SMTP connect failed - PHPMailer Error on Localhost in phpmailer - php

I am using phpmailer latest version . I am using the following code :
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'sultan.ahmed.sagor#gmail.com'; // SMTP username
$mail->Password = 'simplePass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SMTPDebug=2;
$mail->setFrom('sultan.ahmed.sagor#gmail.com', 'Mailer');
$mail->addAddress('zakir#era.com.bd', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen#example.com'); // Name is optional
//$mail->addReplyTo('info#example.com', 'Information');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
But when I run this code I am giving the following output :
2017-02-09 11:20:34 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP w70sm17914821wrc.47 - gsmtp
2017-02-09 11:20:34 CLIENT -> SERVER: EHLO localhost
2017-02-09 11:20:34 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [50.118.143.87] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHU*KING 250 SMTPUTF8
2017-02-09 11:20:34 CLIENT -> SERVER: STARTTLS
2017-02-09 11:20:37 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-02-09 11:20:38 CLIENT -> SERVER: EHLO localhost
2017-02-09 11:20:39 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [50.118.143.87] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
2017-02-09 11:20:39 CLIENT -> SERVER: AUTH LOGIN
2017-02-09 11:20:39 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2017-02-09 11:20:39 CLIENT -> SERVER: xxx==
2017-02-09 11:20:40 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2017-02-09 11:20:40 CLIENT -> SERVER: xxx==
2017-02-09 11:20:40 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials w70sm17914821wrc.47 - gsmtp
2017-02-09 11:20:40 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials w70sm17914821wrc.47 - gsmtp
2017-02-09 11:20:40 SMTP Error: Could not authenticate.
2017-02-09 11:20:40 CLIENT -> SERVER: QUIT
2017-02-09 11:20:41 SERVER -> CLIENT: 221 2.0.0 closing connection w70sm17914821wrc.47 - gsmtp
2017-02-09 11:20:41 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
And the email is not sent . How can I use phpmailer to send email ?

This should fix your issue:
$mail->AuthType = 'LOGIN';
https://www.emailarchitect.net/easendmail/sdk/html/authtype.htm

Related

SMTP server error: Using PHPMailer while sending outlook mail

Here is my code, The same code is working gmail and yahoo but outlook or hotmail getting this issue
include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.live.com";//tried smtp-mail.outlook.com,smtp.office365.com
$mail->SMTPAuth= true;
$mail->Port = 587;
$mail->Username= $account;
$mail->Password= $password;
$mail->SMTPSecure = 'tls';
$mail->From = $from;
$mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->addAddress($to);
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "E-Mail has been sent";
}
Getting below Error.
SMTP -> FROM SERVER:220 DM5PR0101CA0036.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 7 Mar 2019 07:59:09 +0000
SMTP -> FROM SERVER: 250-DM5PR0101CA0036.outlook.office365.com Hello [146.148.75.233] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:220 2.0.0 SMTP server ready
SMTP -> FROM SERVER: 250-DM5PR0101CA0036.outlook.office365.com Hello [146.148.75.233] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN XOAUTH2 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> ERROR: Password not accepted from server:
SMTP -> FROM SERVER:535 5.7.3 Authentication unsuccessful [DM5PR0101CA0036.prod.exchangelabs.com]
SMTP -> ERROR: RSET failed: 535 5.7.3 Authentication unsuccessful [DM5PR0101CA0036.prod.exchangelabs.com]
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
SMTP server error: 5.7.3 Authentication unsuccessful [DM5PR0101CA0036.prod.exchangelabs.com]

Failed to connect to SMTP using PHPMailer

I have tried to connect using SMTP, but failed. Here is my code.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 20;
$mail->isSMTP();
$mail->Host = 'smtp.mail.yahoo.com';
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
$mail->Username = 'david_thedragonzzz#yahoo.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('david_thedragonzzz#yahoo.com', 'Mailer');
$mail->addAddress('david_thedragonzzz#yahoo.com', 'User');
$mail->addReplyTo('test#yahoo.com', 'Information');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
The result
2018-02-07 10:45:43 Connection: opening to ssl://smtp.mail.yahoo.com:465, timeout=300, options=array()
2018-02-07 10:45:43 Connection: opened
2018-02-07 10:45:43 SMTP INBOUND: "220 smtp.mail.yahoo.com ESMTP ready"
2018-02-07 10:45:43 SERVER -> CLIENT: 220 smtp.mail.yahoo.com ESMTP ready
2018-02-07 10:45:43 CLIENT -> SERVER: EHLO localhost
2018-02-07 10:45:43 SMTP INBOUND: "250-smtp.mail.yahoo.com"
2018-02-07 10:45:43 SMTP INBOUND: "250-PIPELINING"
2018-02-07 10:45:43 SMTP INBOUND: "250-SIZE 41697280"
2018-02-07 10:45:43 SMTP INBOUND: "250-8 BITMIME"
2018-02-07 10:45:43 SMTP INBOUND: "250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE OAUTHBEARER"
2018-02-07 10:45:43 SERVER -> CLIENT: 250-smtp.mail.yahoo.com250-PIPELINING250-SIZE 41697280250-8 BITMIME250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE OAUTHBEARER
2018-02-07 10:45:43 Auth method requested: LOGIN
2018-02-07 10:45:43 Auth methods available on the server: PLAIN,LOGIN,XOAUTH2,XYMCOOKIE,OAUTHBEARER
2018-02-07 10:45:43 CLIENT -> SERVER: AUTH LOGIN
2018-02-07 10:45:43 SMTP INBOUND: "334 VXNlcm5hbWU6"
2018-02-07 10:45:43 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-02-07 10:45:43 CLIENT -> SERVER: xxx==
2018-02-07 10:45:43 SMTP INBOUND: "334 UGFzc3dvcmQ6"
2018-02-07 10:45:43 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2018-02-07 10:45:43 CLIENT -> SERVER: xxx==
2018-02-07 10:45:46 SMTP INBOUND: "535 5.7.0 (#MBR1212) Incorrect username or password."
2018-02-07 10:45:46 SERVER -> CLIENT: 535 5.7.0 (#MBR1212) Incorrect username or password.
2018-02-07 10:45:46 SMTP ERROR: Password command failed: 535 5.7.0 (#MBR1212) Incorrect username or password.
SMTP Error: Could not authenticate.
2018-02-07 10:45:46 CLIENT -> SERVER: QUIT
2018-02-07 10:45:46 SMTP INBOUND: "221 2.0.0 Bye"
2018-02-07 10:45:46 SERVER -> CLIENT: 221 2.0.0 Bye
2018-02-07 10:45:46 Connection: closed
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.
I can't understand how come this code gives me "incorrect username or password" error. I have configured smtp using Mozilla Thunderbird. Username and Password is right, but still gives me this kind of error.

PHPMailer connection Failed

I'm using digital ocean.
I've been digging to fix this error.
2016-10-26 04:35:35 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP ht5sm340860pad.16 - gsmtp
2016-10-26 04:35:35 CLIENT -> SERVER: EHLO example.com 2016-10-26 04:35:35 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [128.199.201.169] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
2016-10-26 04:35:35 CLIENT -> SERVER: STARTTLS
2016-10-26 04:35:35 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2016-10-26 04:35:35 SMTP Error: Could not connect to SMTP host.
2016-10-26 04:35:35 CLIENT -> SERVER: QUIT
2016-10-26 04:35:36 SERVER -> CLIENT:
2016-10-26 04:35:36 SMTP ERROR: QUIT command failed:
2016-10-26 04:35:36 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
There was an error! Try again
Here is my setting:
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->isSMTP();
// Specify main and backup SMTP servers
$mail->Host = gethostbyname('smtp.gmail.com');
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail#gmail.com'; // SMTP username
$mail->Password = 'psw'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('d#gmail.com', 'd');
$mail->addAddress('test#gmail.com', ''); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = " Account Confirmation";
$mail->Body = "Hello. test Thank you for you using our service! To activate your account, please access this link:\n <a href='http://w2heaven.com/index.php?confirmcode=$confirmcode'>Click here</a> \n";
if(!$mail->send()) {
echo "There was an error! Try again";
} else {
echo "Please confirm your email at: blablah";
}
More info: It works without gethostbyname(); but extremely slow because DigitalOcean blocks IPv6

PHPMailer server Message

I'm using php plugin for PHPMailer. Its version is PHPMailer_5.2.4. I have tested the sample code of PhpMailer site.
<?php
require_once('PHPMailer_5.2.4/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
//$body = file_get_contents('contents.html');
//$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.google.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "myuser#gmail.com"; // GMAIL username
$mail->Password = "mypass"; // GMAIL password
$mail->SetFrom('myuser#gmail.com', 'First Last');
$mail->Subject = "FeedBack";
$mail->MsgHTML("helo hru ");
$address = "whomto#domainname.com";
$mail->AddAddress($address, "MYName");
$mail->Send();
//if(!$mail->Send()) {
////echo "Mailer Error: " . $mail->ErrorInfo;
//}
//else {
//echo "Message sent!";
//}
?>
After Executing this code, I'm getting the below output. But the mail has received successfully at my receiver mail Address. But I don't want the below output message. How can I rectify it ?
SMTP -> FROM SERVER:220 mx.google.com ESMTP b3sm40861402pbu.38 - gsmtp
SMTP -> FROM SERVER: 250-mx.google.com at your service, [ipAddress]
250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES
250 CHUNKING
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
SMTP -> FROM SERVER: 250-mx.google.com at your service, [ipAddress]
250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2
PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250 CHUNKING
SMTP -> FROM SERVER:250 2.1.0 OK b3sm40861402pbu.38 - gsmtp
SMTP -> FROM SERVER:250 2.1.5 OK b3sm40861402pbu.38 - gsmtp
SMTP -> FROM SERVER:354 Go ahead b3sm40861402pbu.38 - gsmtp
SMTP -> FROM SERVER:250 2.0.0 OK 1383737961 b3sm40861402pbu.38 - gsmtp
SMTP -> FROM SERVER:221 2.0.0 closing connection b3sm40861402pbu.38 -
gsmtp
Just remove this line of code:
$mail->SMTPDebug = 2;
It will disable debugging output.
This is just the debug output. Set $mail->SMTPDebug to 0
Your problem is the $mail->SMTPDebug line.
Setting that value tells PHPMailer to output debug data, which is what you're seeing.
Remove that line, and you won't get the output any more.

phpmailer tls error,when i try to send mail via tls,error like belowe

when i try to send mail by phpmailer,there is some error.
Like this:
SMTP -> FROM SERVER: 250-m1.mydomain.com
250-PIPELINING
250-SIZE 15728640
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
CLIENT -> SMTP: STARTTLS
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
CLIENT -> SMTP: EHLO localhost.localdomain
250-PIPELINING
250-SIZE 15728640
250-VRFY
250-ETRN
250-AUTH PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
SMTP -> ERROR: AUTH not accepted from server: 535 5.7.8 Error: authentication failed: Invalid authentication mechanism
CLIENT -> SMTP: RSET
SMTP -> FROM SERVER:250 2.0.0 Ok
CLIENT -> SMTP: MAIL FROM:
SMTP -> FROM SERVER:250 2.1.0 Ok
CLIENT -> SMTP: RCPT TO:
SMTP -> FROM SERVER:554 5.7.1 : Relay access denied
SMTP -> ERROR: RCPT not accepted from server: 554 5.7.1 : Relay access denied
CLIENT -> SMTP: quit
SMTP -> FROM SERVER:221 2.0.0 Bye
And my php code like this:
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 3;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Host = "m1.mydomain.com";
$mail->Port = 25;
$mail->Username = "service#mydomain.com";
$mail->Password = "password";
$mail->SetFrom('service#mydomain.com', 'service');
$mail->Subject = "Fine Design - Avise me";
$mail->Body = "This is very interest email for you";
$mail->AddAddress("to#domain.com","name");
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
echo "We're sorry, however, an error has occurred. You may manually e-mail us .";
return false;
} else {
echo "Thanks! Your message was successfully sent.";
return true;
}
?>
but i could send mail by foxmail and other client,
Did anybody could give me some suggestion?
You are using tls on port 25.
That normally should not work as port 25 is normally used for smtp without ssl/tls.
Try to test it with port 25, and with port 587.
Add:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
I used it and works fine without SSL.

Categories