Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer Hangs on Send

I had successfully setup a web app using WAMPSERVER on a desktop used by a few people internally, this used PHPMailer to an internal SMTP server without encryption or authentication and it worked.

That desktop crashed and I've migrated to a "new" desktop. I had an SVN setup so I was even using most of the same files and config. One difference which might matter is that the old desktop was 64-bit and the new is 32-bit. This means I'm using different versions of WAMPSERVER.

The mailer just hangs. I don't get a PHP error or a PHP timeout. I just never reach the end of my script. The crazy part about this is that it works with authentication, ssl, and gmail. It just won't work with the extra simple case I need.

This works:

<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.gmail.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "[email protected]";  // GMAIL username
$mail->Password   = "mypassword";            // GMAIL password
$mail->AddAddress('[email protected]', 'John Doe');
$mail->SetFrom('[email protected]', 'First Last');
$mail->Send();
?>

this used to, but now does not:

<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.internal.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
$mail->Port       = 25;                   // set the SMTP port for the GMAIL server
$mail->AddAddress('[email protected]', 'John Doe');
$mail->SetFrom('[email protected]', 'First Last');
$mail->Send();
?>

The only thing I get from debug is

CLIENT -> SMTP: EHLO thedesktophostname

No errors display on the page and nothing in the apache log, where I normally get PHP errors, if they don't display.

I can telnet to the host from the desktop on port 25 and even type in the EHLO command and get a good response from the server.

I don't remember having this issue before, although it's possibly I've already solved it once. I couldn't find anything that helped here or on The Google.

Please help. Thanks.

like image 359
user2221400 Avatar asked Mar 28 '13 21:03

user2221400


3 Answers

Hijacking the post to say i had the same issue but had set the port to 465 without setting SMTPSecure to 'ssl' in the example its set TLS by default

like image 116
Louise McMahon Avatar answered Oct 19 '22 23:10

Louise McMahon


sadly this probably won't ever help anyone else who has this same problem, but I was able to get everything working by just changing the port to 465.

like image 2
user2221400 Avatar answered Oct 19 '22 23:10

user2221400


If you have a server hosted in Hostgator (shared hosting), this is what solved for me:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
(even though the official example in PHPMailer suggests using ENCRYPTION_STARTTLS)

like image 2
ofri cofri Avatar answered Oct 19 '22 23:10

ofri cofri