I'm trying to send an email and I have 2 scripts:
send.php
<?php
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
$mail = new PHPMailer();
$body = " ";
$mail->IsSMTP();
$mail->SMTPDebug = 4;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "XXXXXXXX#gmail.com";
$mail->Password = "XXXXXXXX";
$mail->Subject = "TEST";
$mail->MsgHTML($body);
$address = "YYYYYYYY#gmail.com";
$mail->AddAddress($address, "");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
script.php
<?php
echo shell_exec("php send.php");
?>
By calling directly send.php in browser, the email is send. Problem is when I'm calling script.php, then the email is not send and Im getting an error. Here are last lines from output:
2016-02-09 19:19:55 Connection: opening to smtp.gmail.com:587, t=300, opt=array (
)
2016-02-09 19:19:55 Connection: opened
2016-02-09 19:19:55 SMTP -> get_lines(): $data was ""
2016-02-09 19:19:55 SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP cc7sm606507lbd.11 - gsmtp
"
2016-02-09 19:19:55 SMTP -> get_lines(): $data is "220 smtp.gmail.com ESMTP cc7sm606507lbd.11 - gsmtp
"
2016-02-09 19:19:55 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP cc7sm606507lbd.11 - gsmtp
2016-02-09 19:19:55 CLIENT -> SERVER: EHLO raspberrypi
....
Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in /var/www/html/class.smtp.php on line 325
2016-02-09 19:19:55 CLIENT -> SERVER: QUIT
2016-02-09 19:19:56 SMTP -> get_lines(): $data was ""
2016-02-09 19:19:56 SMTP -> get_lines(): $str is "�F"
2016-02-09 19:19:56 SMTP -> get_lines(): $data is "�F"
2016-02-09 19:19:56 SERVER -> CLIENT: �F
2016-02-09 19:19:56 SMTP ERROR: QUIT command failed: �F
2016-02-09 19:19:56 Connection: closed
2016-02-09 19:19:56 SMTP connect() failed.
Mailer Error: SMTP connect() failed.
What can be causing this issue? Im using PHP7
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 know there's a lot a similar questions, I've read them all, tried everything in the comments. Still doesn't work.
I've created the gmail account for this project and set the less secure aplication usage configurations from the beginning.
If anyone can give me any ideas I've aprecciate it a lot, I've been trying to solve this for months.
This is the output:
" 2018-06-03 21:03:33 SERVER -> CLIENT:
2018-06-03 21:03:33 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP Error: Could not authenticate.
Message hasnt been sent. Mailer Error: SMTP Error: Could not authenticate.> "
And this is my send.php code:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
require 'vendor/autoload.php';
if(isset($_REQUEST['send']))
{
$name= $_REQUEST['name'];
$tel= $_REQUEST['tel'];
$email= $_REQUEST['email'];
$preference= $_REQUEST['preference'];
$area= $_REQUEST['area'];
$message= $_REQUEST['message'];
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mygmailaccount#gmail.com';
$mail->Password = 'thepassword';
$mail->SMTPSecure = 'TSL';
$mail->Port = 587;
$mail->CharSet= 'UTF-8';
// Port 465 for SSL auth. Also tried 587 for authenticated TLS
$mail->setFrom($email, $name);
$mail->addAddress('mygmail#gmail.com', 'Myname');
$mail->isHTML(true);
$mail->Subject = "Contact from ".$name;
$mail->Body = "Name:". $name. ". </br> Tel:". $tel. ". </br> Email:". $email. ". </br> Preference:". $preference. ". </br> Area:". $area. ". </br> Message:". $message. ". </br> ";
$mail->AltBody = "Name:". $name. ". ::: Tel:". $tel. ". ::: Email:". $email. ". ::: Preference:". $preference. ". ::: Area:". $area. ". ::: Message:". $message. ". ::: ";
$mail->send();
$_SESSION["success"] = "Thanks for the message";
}
catch (Exception $e)
{
echo 'Message hasnt been sent. Mailer Error: ', $mail->ErrorInfo;
}
}
Edit: I've tried what Abdulla and Glass said, deactivated the 2 step verification and changed to tsl with port 587 and debug 3 and get this output:
2018-06-03 22:03:55 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2018-06-03 22:03:55 Connection: opened
2018-06-03 22:03:55 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP u74-v6sm3867212qku.55 - gsmtp
2018-06-03 22:03:55 CLIENT -> SERVER: EHLO localhost
2018-06-03 22:03:55 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [190.2.100.71]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2018-06-03 22:03:55 CLIENT -> SERVER: STARTTLS
2018-06-03 22:03:56 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-06-03 22:03:56 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [H:\xampp\htdocs\mati\PHPMailer\src\SMTP.php line 406]
SMTP Error: Could not connect to SMTP host.
2018-06-03 22:03:56 CLIENT -> SERVER: QUIT
2018-06-03 22:03:56 SERVER -> CLIENT:
2018-06-03 22:03:56 SMTP ERROR: QUIT command failed:
2018-06-03 22:03:56 Connection: closed
SMTP Error: Could not connect to SMTP host.
El mensaje no ha sido enviado. Mailer Error: SMTP Error: Could not connect to SMTP host.
Edit2: It is solved, I've uploaded in a provisional server that use tsl authentication and worked perfectly. I can thank you enough #abdulla-nilam and #mr-glass for your contribution.
It finnaly sent the message so, thank you again. It didn't worked at first from my localhost but in the provissional server works just fine.
I think you should try this:
$mail = new \PHPMailer(true);
$mail->CharSet = 'UTF-8'; $mail->isHTML();
$mail->Host = ...//my config
$mail->Port = ...//my port $mail->isSMTP();
if (version_compare(PHP_VERSION, '5.6.0') >= 0){
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ), );
}
I am having troubles with PHPMailer. on index.php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/PHPMailer/src/Exception.php';
require __DIR__ . '/PHPMailer/src/PHPMailer.php';
require __DIR__ . '/PHPMailer/src/SMTP.php'
$mail = new PHPMailer;
require __DIR__ . '/../controllers/login.php';
And login. php
$app->post('/proyectos/login', function ($request) use($servername, $dbname, $dbuser, $dbpassword, $mail)
{
$objTmp = $request->getBody();
$obj = array();
parse_str($objTmp, $obj);
$response = array();
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'user#gmail.com';
$mail->Password = 'pass';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('oneemail#gmail.com', 'sender');
$mail->addAddress('someemail#gmail.com', 'receiver');
$mail->addReplyTo('anotheremail#gmail.com', 'Information');
$mail->isHTML(true);
$mail->Subject = 'Just a subject';
$mail->Body = "Just a body";
if(!$mail->send()) {
$response['success'] = false;
$response['message'] = "Could not send email.";
echo json_encode($response);
return;
}
$response['success'] = true;
echo json_encode($response);
return;
2017-12-01 19:54:33 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2017-12-01 19:54:34 Connection: opened
2017-12-01 19:54:34 SMTP INBOUND: "220 smtp.gmail.com ESMTP g37sm1362021uah.16 - gsmtp"
2017-12-01 19:54:34 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP g37sm1362021uah.16 - gsmtp
2017-12-01 19:54:34 CLIENT -> SERVER: EHLO localhost
2017-12-01 19:54:34 SMTP INBOUND: "250-smtp.gmail.com at your service, [190.94.198.150]"
2017-12-01 19:54:34 SMTP INBOUND: "250-SIZE 35882577"
2017-12-01 19:54:34 SMTP INBOUND: "250-8BITMIME"
2017-12-01 19:54:34 SMTP INBOUND: "250-STARTTLS"
2017-12-01 19:54:34 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2017-12-01 19:54:34 SMTP INBOUND: "250-PIPELINING"
2017-12-01 19:54:34 SMTP INBOUND: "250-CHUNKING"
2017-12-01 19:54:34 SMTP INBOUND: "250 SMTPUTF8"
2017-12-01 19:54:34 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [190.94.198.150]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2017-12-01 19:54:34 CLIENT -> SERVER: STARTTLS
2017-12-01 19:54:34 SMTP INBOUND: "220 2.0.0 Ready to start TLS"
2017-12-01 19:54:34 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-12-01 19:54:34 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [C:\xampp\htdocs\proyectos\public\PHPMailer\src\SMTP.php line 404]
SMTP Error: Could not connect to SMTP host.
2017-12-01 19:54:34 CLIENT -> SERVER: QUIT
2017-12-01 19:54:34
2017-12-01 19:54:34
2017-12-01 19:54:34
2017-12-01 19:54:34 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
{"success":false,"message":"Could not send email."}
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
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.