My website URL is: www.realestateTalk.online
I am trying to send email from my index.php webpage using PHP. I want the SMTP setting to be changed to my mail server settings. How can I do that from control panel?
My website URL is: www.realestateTalk.online
I am trying to send email from my index.php webpage using PHP. I want the SMTP setting to be changed to my mail server settings. How can I do that from control panel?
You need to edit your code that posts the messages from your contact form (for example, process.php) to include this PHP code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require "/path/to/your/PHPMailer/src/PHPMailer.php"; // Overwrite /path/to/your/PHPMailer with the path of your PHPMailer
require "/path/to/your/PHPMailer/src/Exception.php"; // Overwrite /path/to/your/PHPMailer with the path of your PHPMailer
require "/path/to/your/PHPMailer/src/SMTP.php"; // Overwrite /path/to/your/PHPMailer with the path of your PHPMailer
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$email = $_POST["email"];
$message = $_POST["message"];
/* If you use reCAPTCHA v2, uncomment the lines that have gRecaptcha things,
and also the if-else statements of those */
//$gRecaptchaResponse = $_POST["g-recaptcha-response"];
/*$postRecaptcha = http_build_query(
array(
"secret" => "your_recaptcha_secret_token", // Replace your_recaptcha_secret_token with the secret token of your website available on Google reCAPTCHA's Admin Settings page for your domain
"response" => $gRecaptchaResponse
)
);*/
/*$reCaptchaPostOpts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postRecaptcha
)
);*/
//$reCaptchaContext = stream_context_create($reCaptchaPostOpts);
//$reCaptchaResult = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify", false, $reCaptchaContext));
//if ($reCaptchaResult->success == "true") {
$mail = new PHPMailer(true);
/* $mail->setLanguage("it");*/ //Uncomment this and change the language to your own if you want to show errors in your language
try {
$mail->isSMTP();
$mail->Host = "yoursmtpserver"; // Overwrite yoursmtpserver to your SMTP server hostname
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl"; // Change ssl with your SMTP server's protocol
$mail->Port = 465; // Change 465 with your SMTP server's port (note: if you choose 587 and TLS encryption method it might not work)
$mail->Username = "yourusername"; // Change yourusername with your SMTP server's authorized username (if you're using Gmail's or Yandex.Connect's one the username will be your email)
$mail->Password = "********"; // Change those asterisks with your account's password
$mail->setFrom("youremail", "test"); // Change youremail and test with your email and the name you want to be called
$mail->addAddress("youremail"); // Change youremail with your email
$mail->addReplyTo($email);
$mail->isHTML(true);
$mail->Subject = "Your website name | New message"; // Change Your website name with your website name
$mail->Body = "Username: ".$username."<br />Email: ".$email."<br />Message:<br /><br />".$message."<br /><div style=\"text-align:right\">Sent from the contact form on your website name</div>"; // Change your website name with your website name
$mail->AltBody = "Your email client does not support HTML emails. Please update your email client before you can see the message.";
$mail->send();
echo "Your message was sent successfully!";
} catch (Exception $err) {
echo "Your message can't be sent because of a Mailer Error: {$mail->ErrorInfo}";
}
//} else {
// echo "Please compile the reCAPTCHA again, and then send the message!";
//}
} else {
echo "This file only supports POST requests. Please send a valid POST request, then try again!";
}
?>
by following the comments present on it, and knowing that you already have PHPMailer installed on your htdocs folder. If you don’t have it, download it from here, extract it on your computer, rename PHPMailer-master
folder to PHPMailer
and upload the entire folder to your htdocs folder with your FTP client. Then include the name of the file you used to post the contact form’s data on your HTML form
tag’s action
attribute.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.