Question
PhpMailer fails with 500 error, can't reach smtp server
Hi,
I have faced with problem. I use the following code to send mail on development server, but it fails when I try to do the same from Digitalocean server (Ubuntu 12.04.5 x64).
Bascially it shows that script loading but ends up with 500 error.
The connection to smtp.gmail.com fails..:
root@root:~# telnet smtp.gmail.com 587
Trying 2a00:1450:400c:c01::6c…
Trying 74.125.195.108…
Trying 74.125.195.109…
Code:
<?php
error_reporting(-1);
date_default_timezone_set('Etc/UTC');
require 'phpm/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 3;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
$mail->CharSet = 'UTF-8';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "...@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "pass...";
//Set who the message is to be sent from
$mail->setFrom('....@gmail.com', 'Example');
//Set an alternative reply-to address
$mail->addReplyTo('...@gmail.com', 'Example');
//Set who the message is to be sent to
$mail->addAddress('example@example.com', 'Test1');
$mail->addAddress('example2@example.com', 'Test2');
//Set the subject line
$mail->Subject = 'Hi!';
$mail->Body = "Hi!";
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'Hi!';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Failed: " . $mail->ErrorInfo;
} else {
echo "";
}
?>
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×