SMTP Mail problem with Google

Hi,

I am using PHP code similar to this to try and send e-mail:


$config = array('auth' => 'login',
'username' => 'myaccount [at] gmail.com',
'password' => 'mypassword',
'ssl' => 'tls',
'port' => 587);

$userNotification = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

$mail = new Zend_Mail();
$mail->setFrom('another [at] email.com','Another Email');
$mail->addHeader('another [at] email.com');
$mail->setReturnPath('another [at] email.com');
$mail->addTo($userEmail);
$mail->setSubject($usernotificationsubject);
$mail->setBodyText($usernotificationmessage);
$mail->send($userNotification);

When I try to send the e-mail I get an error about TLS. I have enabled SSL for PHP by typing the following:

a2enmod php5_ssl

I am not sure if I need to get Apache to load this up as a module… Any ideas?

The mode you need is SSL, that is to say always encrypted, no TLS negotiation needed.

Hi Ken_yap,

Thanks for your reply… So basically I just have to change:

'ssl' => 'tls'

to

'ssl' => 'ssl'

Is that what you’re saying? This is after doing:

a2enmod php_ssl

and I don’t have to load php_ssl as an Apache module like say mod_php, mod_ssl?

/jlar

I don’t know if it’s as simple as that.

Gmail offers two ports for SMTP connection, 465 and 587. 587 is called submission and is intended as a alternative for 25. 465 is for SMTP over SSL and is always crypted. I think with 587 you are meant to go SSL with the STARTTLS command at some point in the session whereas with 465 it’s always assumed that you are using SSL. My Thunderbird setup uses 465. I don’t know exactly what options affect what with the PHP module as I haven’t used gmail via PHP, only via Thunderbird.

You might want to watch a Thunderbird session and a session with your client to see where the protocol breaks down.

Hi Ken_yap,

I tried your suggestion and it worked! Thanks very much… :slight_smile:

I used the following code, the changes are in bold:

$config = array('auth' => 'login',
'username' => 'myaccount [at] gmail.com',
'password' => 'mypassword',
'ssl' => '**ssl**',
'port' => **465**);

$userNotification = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

$mail = new Zend_Mail();
$mail->setFrom('another [at] email.com','Another Email');
$mail->addHeader('another [at] email.com');
$mail->setReturnPath('another [at] email.com');
$mail->addTo($userEmail);
$mail->setSubject($usernotificationsubject);
$mail->setBodyText($usernotificationmessage);
$mail->send($userNotification);

I also made sure the php_ssl module was installed.

/jlar