I am unable to send an email with smtp
here is the code I am using
public function hello()
{
require_once(APPPATH."libraries/phpmailer/PHPMailerAutoload.php");
$mail = new phpmailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPSecure = 'tls'; // or ssl
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.zoho.com";
$mail->Port = 25;// 25, 465 for ssl or 587 for tls
$mail->Username = '[email protected]';
$mail->Password = 'my_password';
$mail->setFrom('[email protected]','example.com');
$mail->addReplyTo('[email protected]', 'example.com);
$mail->addAddress('[email protected]',"my_friend name");
$mail->Subject = 'PHPMailer SMTP test from Hello';
$mail->Body = 'Body This is a plain-text message body';
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
and this is what I get
2017-06-14 16:42:36 SERVER -> CLIENT: 220-server.example.com ESMTP Exim 4.86 #2 Wed, 14 Jun 2017 12:42:36 -0400 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2017-06-14 16:42:36 CLIENT -> SERVER: EHLO example.com
2017-06-14 16:42:36 SERVER -> CLIENT: 250-server.example.com Hello example.com [23.92.221.226]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2017-06-14 16:42:36 CLIENT -> SERVER: STARTTLS
2017-06-14 16:42:36 SERVER -> CLIENT: 220 TLS go ahead
2017-06-14 16:42:36 CLIENT -> SERVER: EHLO example.com
2017-06-14 16:42:36 SERVER -> CLIENT: 250-server.example.com Hello example.com [23.92.221.226]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250 HELP
2017-06-14 16:42:36 CLIENT -> SERVER: AUTH LOGIN
2017-06-14 16:42:36 SERVER -> CLIENT: 334 VXNlcm5hbxWUd
2017-06-14 16:42:36 CLIENT -> SERVER: bm9fcmVdbHddc2hvcddtZXJpa2EuY29t
2017-06-14 16:42:36 SERVER -> CLIENT: 334 UGdzc3dvdmQ6
2017-06-14 16:42:36 CLIENT -> SERVER: IXMxsdU1OTss
2017-06-14 16:42:38 SERVER -> CLIENT: 535 Incorrect authentication data
2017-06-14 16:42:38 SMTP ERROR: Password command failed: 535 Incorrect authentication data
SMTP Error: Could not authenticate.
2017-06-14 16:42:38 CLIENT -> SERVER: QUIT
2017-06-14 16:42:38 SERVER -> CLIENT: 221 server.example.com closing connection
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have been looking on stackoverflow for days and nothing worked for me
I made a small Python script to send emails using smtplib and everything worked ok, but I need to use PHP. the error is vague. I also followed the Troubleshooting https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
and everything is set properly in my dns
what can be wrong ? I even contacted zoho mail and they told me that the problem is in my code, which is true since the Python code works just fine .
thank you for your help
Read docs @ https://www.zoho.com/mail/help/zoho-smtp.html
Unable to connect to Outgoing Server/ SMTP Server
Sometimes, the email clients connect to the default port 25 when connecting to the SMTP server. In case of Zoho Mail, you need to connect to smtp.zoho.com in SSL or TLS ports i.e 465 or 587 respectively. Ex: In Outlook, you need to check the 'Advanced Server Settings' section.
If the port details are correct and there are still issues in connecting to the server, you need to get the traceroute details for smtp.zoho.com server and share it to support (at) zohomail (dot) com with the details of your account, your email client, screenshots of the configuration, etc.
I found the problem, it was related to a security feature in WHM/cPanel
Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)
Login to CPanel > Tweak Settings > All> "Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) and switch it from “On” to “Off”.
for my case I used the shell (ssh) to fix this :
/scripts/smtpmailgidonly off
and I posted an answer here
https://stackoverflow.com/questions/14297264/password-not-accepted-from-server-535-incorrect-authentication-data-when-send/44564332#44564332
@nsssim thank you for posting your solution.
@nsssim thanks for solution.
@nsssim Thanks for the Solution Saved Me Hours!
Cheers :+1:
Am getting the same error. Am using Webmin on VPS and trying to send my mails via php mailer.
Most helpful comment
I found the problem, it was related to a security feature in WHM/cPanel
Login to CPanel > Tweak Settings > All> "Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) and switch it from “On” to “Off”.
for my case I used the shell (ssh) to fix this :
/scripts/smtpmailgidonly offand I posted an answer here
https://stackoverflow.com/questions/14297264/password-not-accepted-from-server-535-incorrect-authentication-data-when-send/44564332#44564332