views:

2293

answers:

4

Hello,

I'm trying to send out mail using Google's SMTP in combination with PHPMailer, but I can't get it to work. This is my code:

$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "[email protected]";
$mail->Password = "**********";
$mail->Port = "465";

First I do not fully understand what should be filled in as 'SMTPSecure', some say 'ssl', other say 'tls'. Next for 'Port' I could enter '465' or '587'. But none of the combinations work... Note that I'm using a regular Gmail account and not Google Apps. In my Gmail account I've enabled 'POP access'.

The error I get is: "Must issue a STARTTLS command first". Which means SSL failed, but don't know why...

+2  A: 

I had similar problems with GMail when using it through CodeIgniter

For me, changing the host option worked:

$mail->Host = "ssl://smtp.googlemail.com";
Jon Winstanley
Didn't work :( Error: 'Failed to connect to server'
bart
+2  A: 

Ok, the problem was the version of PHPMailer. I updated to PHPMailer version 5 and everything worked great. I was using phpMailer version 1.02.

bart
Same problem, updated to version 5.0.0 and it worked fine.
ARemesal
+1  A: 

Set $mail->SMTPDebug = 1; It will give you more info about this error. Most likely you will get "Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP". To fix this remove ";" from ;extension=php_openssl.dll line in php.ini.

PS I also like XAMPP :)))

kami
A: 

$host = "ssl://smtp.gmail.com"; $port = "465"

I changed from SSL to ssl. It works.

ohyeahfanfan