PHPMailer Hangs on Send
Asked Answered
P

5

9

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.

Plash answered 28/3, 2013 at 21:17 Comment(14)
Can you read the logs of the SMTP server?Sacrilege
i cannot. And because I can connect with telnet, and issue the command it hangs on, and get a response, I don't think that's the issue. Additionally, this used to work before I moved to a different WAMPSERVER version on another computer. I'm not 100% sure, but I think it was 64-bit 2.4.2 apache and now is 32-bit 2.2.22. PHP version should be the same.Plash
Next in line: can you fsockopen() a connection to the smtp server, and what do you get if you manually write the EHLO line there?Sacrilege
i think you might be on to something. i'm not terribly familar with these functions, let me know if i messed it up. i did: $socket=fsockopen('smtp.internal.com',25); echo fgets($socket); fwrite($socket,'EHLO desktophostname'); echo fgets($socket); i got a php error for timeout on the first echo fgets() line.Plash
if i comment that line out it gets to the next fgets and timesout, but seems to be ok on fsockopen and fwrite.Plash
Add an "\r\n" after your EHLO string, what happens then?Sacrilege
still hangs on the fgets (i have the first commented out)Plash
Hm, and from the same machine a telnet connection is possible? I'd say firewall issues...Sacrilege
just disabled, still same. checked firewall log to double check, no blocking or issues listed.Plash
Hmf, final push, and them I'm out of ideas: if fread($socket,1); works, enable auto_detect_line_endings....Sacrilege
same result, but something potentially interesting, i tried this $socket=fsockopen('ssl://smtp.gmail.com',465); echo fgets($socket); and it seems to hang just the same, if not worse because i don't seem to get a timeout error.Plash
Well weird... I'd examine TCP traffic to see if there is a connect & return.Sacrilege
in my testing i switched back to my internal server and it seemed to work, i didn't switch 465 back to 25. i have no idea what's going on, but it works if i leave everything the same and use port 465 instead. Thanks for the help anyway...Plash
Thanks @user2221400, setting $mail->SMTPSecure to ssl instead of the PHPMailer::ENCRYPTION_STARTTLS from the readme docs actually solved my problem :DKrongold
P
2

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.

Plash answered 1/4, 2013 at 17:51 Comment(1)
Ha, this was my problem too. Had it set to 993, but that's for TLS.Ish
C
14

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

Coven answered 14/6, 2015 at 23:14 Comment(2)
setting smtpsecure to ssl fixed it for me as well, I'm using hostgator.Torment
Thank you! Sending from localhost through zoho required this configuration too.Natalee
J
4

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)

Jardena answered 16/8, 2020 at 1:56 Comment(1)
Except he's already setting ssl which is the value of ENCRYPTION_SMTPSKrongold
P
2

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.

Plash answered 1/4, 2013 at 17:51 Comment(1)
Ha, this was my problem too. Had it set to 993, but that's for TLS.Ish
C
1

Eventually found solution for my configuration.
Just add ssl:// to smtp.google.com
$mail->Host = 'ssl://smtp.gmail.com';

Cerf answered 31/7, 2019 at 16:55 Comment(1)
Thanks this worked for SendGrid hanging on me, you rock, thxPlaten
D
1

I had the same issue. Nothing displays after the send method. I realized that the encryption was wrong, I did use SMTPS

$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
// Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted
Dystrophy answered 27/9, 2019 at 14:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.