Hello, I am attempting to use a contact form in a website which the visitors can fill & the responses will be emailed to me. I am using a template temporarily for testing & i know the form works as I used the same template in another paid hosting. In here, I understand SMTP is blocked & I need to use external service. I set up the Google smtp using (https://infinityfree.net/support/how-to-send-email-with-gmail-smtp), named the code file as phpmailer.php. & did the username/pass change. However i dont seem to get an email. Am i missing something? The temporary site is at adoniatech.epizy.com
Procedures given in that link should be enough to send mail using Gmail’s SMTP.
Can you provide the code?
@Joo_Nath said:
Procedures given in that link should be enough to send mail using Gmail’s SMTP.Can you provide the code?
If you mean the contact form php code this it (i changed the siteowneremail to 1 created with infinity):
`<?php
// Replace this with your own email address
$siteOwnersEmail = ‘[email protected]’;
if($_POST) {
$name = trim(stripslashes($_POST[‘contactName’]));
$email = trim(stripslashes($_POST[‘contactEmail’]));
$subject = trim(stripslashes($_POST[‘contactSubject’]));
$contact_message = trim(stripslashes($_POST[‘contactMessage’]));
// Check Name
if (strlen($name) < 2) {
$error[‘name’] = “Please enter your name.”;
}
// Check Email
if (!preg_match(‘/[1]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is’, $email)) {
$error[‘email’] = “Please enter a valid email address.”;
}
// Check Message
if (strlen($contact_message) < 15) {
$error[‘message’] = “Please enter your message. It should have at least 15 characters.”;
}
// Subject
if ($subject == ‘’) { $subject = “Contact Form Submission”; }
// Set Message
$message .= "Email from: " . $name . “
”;
$message .= "Email address: " . $email . “
”;
$message .= “Message:
”;
$message .= $contact_message;
$message .= “
-----
This email was sent from your site’s contact form.
”;
// Set From: header
$from = $name . " <" . $email . “>”;
// Email Headers
$headers = "From: " . $from . "\r
";
$headers .= "Reply-To: ". $email . "\r
";
$headers .= "MIME-Version: 1.0\r
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r
";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \
" : null;
$response .= (isset($error[‘email’])) ? $error[‘email’] . "
" : null;
$response .= (isset($error[‘message’])) ? $error[‘message’] . “
” : null;
echo $response;
} # end if - there was a validation error
}
?>`
if you are talking about the code shown on the link i used it exactly the way it is with a change in username & password & named the file as phpmailer.php
a-z0-9&\'\.\-_\+ ↩︎
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
Even though your code may be similar to the PHPmailer example, you’re not actually using PHPmailer. The code above actually sends the email with PHP mail()
, which does not use SMTP (and is heavily restricted).