PhpMailer fails with 500 error, can't reach smtp server

August 8, 2015 3.1k views
PHP DigitalOcean Networking


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 fails..:
root@root:~# telnet 587
Trying 2a00:1450:400c:c01::6c...



require 'phpm/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP

//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 = '';

//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 = "";

//Password to use for SMTP authentication
$mail->Password = "pass...";

//Set who the message is to be sent from
$mail->setFrom('', 'Example');

//Set an alternative reply-to address
$mail->addReplyTo('', 'Example');

//Set who the message is to be sent to
$mail->addAddress('', 'Test1');
$mail->addAddress('', '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

//send the message, check for errors
if (!$mail->send()) {
    echo "Failed: " . $mail->ErrorInfo;
} else {
    echo "";

2 Answers

I got it working for port 25 (wasn't blocked when checked the telnet). Still, strange that others doesn't work.

DigitalOcean blocks SMTP ports on new accounts to cub spam and abuse:

So you have to create a ticket to get it unblocked.

Have another answer? Share your knowledge.