Hello I am trying to send emails using PHPmailer with the SMTP method it was working fine until it stopped sending emails..
I tried to debug and the error I got was this
2021-01-14 14:46:47 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2021-01-14 14:46:47 Connection: opened
2021-01-14 14:46:48 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP n16sm10096874wrj.26 - gsmtp
2021-01-14 14:46:48 CLIENT -> SERVER: EHLO localhost
2021-01-14 14:46:48 SERVER -> CLIENT: 550 Transaction failed; HELO/EHLO argument not accepted
2021-01-14 14:46:48 SMTP ERROR: EHLO command failed: 550 Transaction failed; HELO/EHLO argument not accepted
2021-01-14 14:46:48 CLIENT -> SERVER: HELO localhost
2021-01-14 14:46:48 SERVER -> CLIENT: 421 Local Error, closing transmission channel
2021-01-14 14:46:48 SMTP ERROR: HELO command failed: 421 Local Error, closing transmission channel
2021-01-14 14:46:48 CLIENT -> SERVER: STARTTLS
2021-01-14 14:46:48 SERVER -> CLIENT:
2021-01-14 14:46:48 SMTP ERROR: STARTTLS command failed:
SMTP Error: Could not connect to SMTP host.
2021-01-14 14:46:48 SMTP NOTICE: EOF caught while checking if connected
2021-01-14 14:46:48 Connection: closed
SMTP Error: Could not connect to SMTP host.
From the error it seemed to me that the EHLO argument sent from the localhost to Gmail wasn't accepted, but I don't have a way or an idea to fix this
Here is my PHPmailer code if it may be of help.
require(ROOT_PATH . 'phpmailer/src/Exception.php');
require(ROOT_PATH . 'phpmailer/src/PHPMailer.php');
require(ROOT_PATH . 'phpmailer/src/SMTP.php');
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = "browynlouis2@gmail.com";
$mail->Password = '081';
//Recipients
$mail->setFrom('browynlouis2@gmail.com', 'Sativa');
$mail->addAddress($email); // Name is optional
$mail->addReplyTo('browynlouis2@gmail.com', 'Sativa Merchandise');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Sativa Merch Newsletter';
$mail->AddEmbeddedImage('admin/assets/img/logo.jpg', 'logo');
$mail->Body = '<div style="background:whitesmoke;padding:10px"><div style="background:white;padding:5px;"><div><img src="cid:logo"><h2 style="text-align:center">Sativa Merchandise</h2></div><div style="padding:10px;padding-top:5px; text-align:center"><p style="color:grey;">You are getting the mail because you just recently subscribed to Sativa Merchandise newsletter. You can continue shopping with us below, thanks for your patronage.</p> <br><br><a href="<?php echo BASE_URL; ?>" style="background-color:black; padding:10px; color:white">Continue Shopping</a><br><br></div></div></div>';
$mail->AltBody = 'You are getting the mail because you just recently subscribed to Sativa Merchandise newsletter. You can continue shopping with us below, thanks for your patronage.';
if (!$mail->send()) {
$subscribe = "Unable to Subscribe you to our newsletter.";
} else {
$subscribe = " You have successfully subscribed to our newsletter. Thank You. ";
}
It's complaining about this:
2021-01-14 14:46:48 CLIENT -> SERVER: EHLO localhost
localhost
is not an externally routable name, so they can't do a lookup on it to determine if it matches the IP the SMTP connection is coming from. PHPMailer attempts to figure out this name automatically, but sometimes it can't. In those circumstances, you can set it manually via the Hostname
property, like this:
$mail->Hostname = 'my.host.example.com';
Set this to whatever your server's real host name is. The next thing is to ensure that your DNS resolvers work both forwards and backwards, so if you do a lookup on your name with:
host my.host.example.com
you'll get an IP address back, and if you then do:
host <ip address>
you should end up with the host name you started with.