zend-frameworkconnectionzend-mail

Zend_Mail fail to send email, output message : Connection timeout


I try to write codes about sending email using Zend Framework. Here is the code,

$mail = new Zend_Mail('utf-8');
$mailConfig = array(
'auth'=> 'login',
'username'  => 'sample@gmail.com',
'password'  => 'samplepassword',
'ssl'       => 'tls',
'port'      => '587';

$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailConfig);
Zend_Mail::setDefaultTransport($tr);

$mail->setSubject('test email');
$mail->setBodyText('body');

$mail->setFrom('sample@gmail.com', 'Just a sample');

$mail->addTo('anothersample@gmail.com', 'Another sample');

$mail->send();

These codes work perfectly at my local computer, but failed to send email at the server side with return message "Connection time out". I guess there might be some configuration problem on the server side, but I don't know what it is. Anyone with idea what is going wrong?


Solution

  • Contact the admin of the server and ask if they allow outgoing communication on port 587.
    It seems like they are blocking certain traffic.