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
Related
I am unable to send an email on my local server.
I used following phpmailer code to test mail sending:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.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";
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 587; // SMTP port
$mail->Username = ""; // username
$mail->Password = ""; // password
$mail->SetFrom('', 'Test');
$mail->Subject = "I hope this works!";
$mail->MsgHTML('Blah');
$address = "";
$mail->AddAddress($address, "Test");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
But I get the following error:
2020-07-06 09:20:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y7sm6517117pjy.54 - gsmtp
2020-07-06 09:20:08 CLIENT -> SERVER: EHLO localhost
2020-07-06 09:20:08 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [157.49.67.14]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2020-07-06 09:20:08 CLIENT -> SERVER: STARTTLS
2020-07-06 09:20:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2020-07-06 09:20:09 CLIENT -> SERVER: QUIT
2020-07-06 09:20:09
2020-07-06 09:20:09
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Please suggest possible solutions.
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
I'm trying to send email using PHPMailer. When I tried sending the email from gmail account, it works perfectly fine. However, I would like to send the email from my own SMTP, but there seems to be an error. What could be the problem? Please help me. Thank you.
Using smtp.gmail.com :
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail#gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
Using mail.distech.com.my :
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'mail.distech.com.my';
$mail->SMTPAuth = true;
$mail->Username = 'myemail#distech.com.my';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = 'myemail#distech.com.my';
$mail->addAddress('amalina#distech.com.my');
$mail->Subject = 'Test';
$mail->Body = 'Test message';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Error using mail.distech.com.my
2015-06-23 06:58:45 Connection: opening to mail.distech.com.my:587, timeout=300, options=array ( )
2015-06-23 06:58:45 Connection: opened
2015-06-23 06:58:45 SERVER -> CLIENT: 220-server.firstonline-server16.com ESMTP Exim 4.85 #2 Tue, 23 Jun 2015 14:58:45 +0800 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2015-06-23 06:58:45 CLIENT -> SERVER: EHLO 192.168.1.20
2015-06-23 06:58:46 SERVER -> CLIENT: 250-server.firstonline-server16.com Hello 192.168.1.20 [115.135.120.220] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
2015-06-23 06:58:46 CLIENT -> SERVER: STARTTLS
2015-06-23 06:58:46 SERVER -> CLIENT: 220 TLS go ahead
Warning: stream_socket_enable_crypto() [function.stream-socket-enable-crypto]: SSL: The operation completed successfully. in C:\xampp\htdocs\ehars\phpmailer\class.smtp.php on line 344
2015-06-23 06:58:46 SMTP Error: Could not connect to SMTP host.
2015-06-23 06:58:46 CLIENT -> SERVER: QUIT
Notice: fwrite() [function.fwrite]: send of 6 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\ehars\phpmailer\class.smtp.php on line 937
2015-06-23 06:58:46 SERVER -> CLIENT:
2015-06-23 06:58:46 SMTP ERROR: QUIT command failed:
2015-06-23 06:58:46 Connection: closed 2015-06-23 06:58:46 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
UPDATE :
Checked my phpinfo () and the ssl has been enabled.
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.
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.