Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: phpmailer 6.0 success message but no mail received using gmail as relay

Robin Olisa:

I've tried a bunch of alterations to my Code but with no effect. The code itself does not return any errors but instead gives a success message. I am using gmail as my relay.

P.S, I commented out $mail->IsSMTP(); because I saw a similar question here that used it as a fix, I was getting an "smtp failed to connect" error.

I am using Phpmailer 6.0.

Here is my code:



require_once('vendor/autoload.php');

define('GUSER', '[email protected]'); // GMail username
define('GPWD', '*********'); // GMail password

function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer\PHPMailer\PHPMailer(true); // create a new object
//$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}

smtpmailer('[email protected]', '[email protected]', 'yourName', 'test mail message', 'Hello World!');
if (smtpmailer('[email protected]', '[email protected]', 'yourName', 'test mail message', 'Hello World!')) {
// do something
}
if (!empty($error)) echo $error;

?>

If I uncomment $mail->IsSMTP(); I get this error log:

2017-12-27 07:58:54 Connection: opening to smtp.gmail.com:465, timeout=300, options=array() 2017-12-27 07:58:54 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:465 (Network is unreachable) [/srv/disk2/2564570/www/http://ift.tt/2zByAWS line 325] 2017-12-27 07:58:54 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed. http://ift.tt/1IlANVr

Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP connect() failed. http://ift.tt/1IlANVr in /srv/disk2/2564570/www/http://ift.tt/2zByIWm Stack trace: #0 /srv/disk2/2564570/www/http://ift.tt/2BVNL3j: PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Wed, 27 D...', 'Hello World!\r\n') #1 /srv/disk2/2564570/www/http://ift.tt/2zBBYBn: PHPMailer\PHPMailer\PHPMailer->postSend() #2 /srv/disk2/2564570/www/http://ift.tt/2BWtyu7: PHPMailer\PHPMailer\PHPMailer->send() #3 /srv/disk2/2564570/www/http://ift.tt/2zCYg5O: smtpmailer('[email protected]', '[email protected]', 'yourName', 'test mail messa...', 'Hello World!') #4 {main} thrown in /srv/disk2/2564570/www/http://ift.tt/2BY0Usy on line 1726



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: phpmailer 6.0 success message but no mail received using gmail as relay

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×