Results 1 to 5 of 5

Thread: SMTP Mail problem with Google

  1. #1
    Join Date
    Jun 2008
    Location
    Dublin, Ireland
    Posts
    298

    Default SMTP Mail problem with Google

    Hi,

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

    Code:
    $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:

    Code:
    a2enmod php5_ssl
    I am not sure if I need to get Apache to load this up as a module.. Any ideas?

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: SMTP Mail problem with Google

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

  3. #3
    Join Date
    Jun 2008
    Location
    Dublin, Ireland
    Posts
    298

    Default Re: SMTP Mail problem with Google

    Hi Ken_yap,

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

    Code:
    'ssl' => 'tls'
    to

    Code:
    'ssl' => 'ssl'
    Is that what you're saying? This is after doing:

    Code:
    a2enmod php_ssl
    and I don't have to load php_ssl as an Apache module like say mod_php, mod_ssl?

    /jlar

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: SMTP Mail problem with Google

    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.

  5. #5
    Join Date
    Jun 2008
    Location
    Dublin, Ireland
    Posts
    298

    Default Re: SMTP Mail problem with Google

    Hi Ken_yap,

    I tried your suggestion and it worked! Thanks very much..

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

    Code:
    $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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •