8

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   = "myemail@gmail.com";  // GMAIL username
$mail->Password   = "mypassword";            // GMAIL password
$mail->AddAddress('toemail@supersecret.com', 'John Doe');
$mail->SetFrom('something@gmail.com', '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('myaddress@somewhere.com', 'John Doe');
$mail->SetFrom('someaddress@mightbereal.com', '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.

user2221400
  • 101
  • 1
  • 1
  • 4
  • Can you read the logs of the SMTP server? – Wrikken Mar 28 '13 at 21:21
  • 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. – user2221400 Mar 28 '13 at 21:24
  • 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? – Wrikken Mar 28 '13 at 21:25
  • 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. – user2221400 Mar 28 '13 at 21:30
  • if i comment that line out it gets to the next fgets and timesout, but seems to be ok on fsockopen and fwrite. – user2221400 Mar 28 '13 at 21:32
  • Add an `"\r\n"` after your `EHLO` string, what happens then? – Wrikken Mar 28 '13 at 21:35
  • still hangs on the fgets (i have the first commented out) – user2221400 Mar 28 '13 at 21:40
  • Hm, and from the same machine a telnet connection is possible? I'd say firewall issues... – Wrikken Mar 28 '13 at 21:41
  • just disabled, still same. checked firewall log to double check, no blocking or issues listed. – user2221400 Mar 28 '13 at 21:44
  • Hmf, final push, and them I'm out of ideas: if `fread($socket,1);` works, enable `auto_detect_line_endings`.... – Wrikken Mar 28 '13 at 21:48
  • 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. – user2221400 Mar 28 '13 at 21:56
  • Well weird... I'd examine TCP traffic to see if there _is_ a connect & return. – Wrikken Mar 28 '13 at 22:04
  • 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... – user2221400 Mar 28 '13 at 22:10
  • Thanks @user2221400, setting `$mail->SMTPSecure` to `ssl` instead of the `PHPMailer::ENCRYPTION_STARTTLS` from the readme docs actually solved my problem :D – jave.web Nov 18 '20 at 09:43

5 Answers5

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

Louise McMahon
  • 1,655
  • 3
  • 15
  • 21
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)

ofri cofri
  • 886
  • 10
  • 13
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.

user2221400
  • 101
  • 1
  • 1
  • 4
1

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

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
Nathan Lo Sabe
  • 197
  • 1
  • 13