I am using SMTP to send an email. for that, I used the WP Mail SMTP plugin ( https://wordpress.org/plugins/wp-mail-smtp/ ) I tested the mail with the WP Mail SMTP plugin and it works. Now I want to send a mail with the SMTP function which I created in the WordPress template
Here is my template file code
<?PHP
/* Template Name: smt */
get_header();
require '/PHPMailer/class.PHPMailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "******";
$mail->Username = "******";
$mail->Password = "***********";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->From = "no-reply@*****.com";
$mail->FromName = "zaata";
$mail->AddAddress('[email protected]');
$mail->IsHTML(true);
$mail->Subject = "zaata Varification code";
$mail->Body = "testmail";
$mail->IsHTML(true);
if(!$mail->Send())
{
echo 'false';
}
echo 'send';
}
?>
It show me itsugestion.com/:1 GET *******.com/dev/smt/ 500 (Internal Server Error) in console
Please help me how can I set up the SMTP in WordPress template
Any help is appreciated.
2
Answers
As I mentioned in the comment to your question its best to just use
wp_mail()
as the plugin makes it use smtp, as for the error 500 your missing a the else part of the if statementFunction.php
JQuery
This is what worked to me. but my problem is the wp_mail() is still return true. even the SMTP got an error or did not really send. What I want is wp_mail() should not proceed if the SMTP got an error.
if you add that
That produces the Ajax error on the console.
Now this is my config in wp-config.
They work all fine except handling the SMTP Error before wp_mail() is to send.