Send email using gmail smtp in zend? [duplicate]
Possible Duplicate:
email zend framwork smtp
I have following configuration:
smtp.type = Zend_Mail_Transport_Smtp
smtp.smtpServer = "smtp.gmail.com"
smtp.username = "ddd@gmail.com"
smtp.password = "dddd"
smtp.email = "ddd@gmail.com"
smtp.port = "587"
smtp.ssl = "tls"
smtp.auth = "login"
I am getting following error:
5.7.0 Must issue a STARTTLS command first. 74sm813723wem.41
My COde:
public function sendEmail( $mailData, $bootstrap = null ) {
// Get SMTP server configurations
if ( $bootstrap == null ) {
$front = Zend_Controller_Front::getInstance();
$bootstrap = $front->getParam('bootstrap');
}
$smtpSettings = $bootstrap->getOption('smtp');
print_r($smtpSettings);
// Only pass username password settings if the authentication is required.
if ( $smtpSettings['auth'] == 'login' ) {
$config = array('ssl' => $smtpSettings['ssl'],
'username' => $smtpSettings['username'],
'password' => $smtpSettings['password']);
$transport = new Zend_Mail_Transport_Smtp( $smtpSettings['smtpServer'], $config );
} else {
$transport = new Zend_Mail_Transport_Smtp( $smtpSettings['smtpServer'] );
}
$mail = new Zend_Mail( 'utf-8' );
try {
if ( $mailData['user'] == true ) {
$mail->setFrom( $mailData['from'], $mailData['fromName'] );
} else {
$mail->setFrom( $smtpSettings['email'], "eCHDP" );
}
// Do we have a single reciepent or multiple receipents?
if ( !is_array($mailData['to']) ) {
$mail->addTo( $mailData['to'] , $mailData['toName'] );
} else {
// We have multiple receipents. Add all of them.
foreach ( $mailData['to']开发者_运维知识库 as $id => $value ) {
$mail->addTo( $value , $mailData['toName'][$id] );
}
}
$mail->setSubject( $mailData['subject'] );
$mail->setBodyHtml( $mailData['body'] );
// If attachment found then attach
if ( $mailData['attachment'] ) {
$attach = new Zend_Mime_Part( file_get_contents( $mailData['attachment'] ) );
$attach->type = 'application/pdf';
$attach->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attach->filename = 'Invoice.pdf';
$mail->addAttachment( $attach );
}
$mail->send( $transport );
return true;
} catch ( Exception $e ) {
echo "Error sending Email : ";
$logger = Zend_Registry::get('Logger');
$logger->err($e->getMessage());
echo $e->getMessage() . "\n\n\n";
return false;
}
}
Can someone guess that what is the error ? I can post code as well if required.
Thanks
This is from our application.ini
resources.mail.transport.type = Zend_Mail_Transport_Smtp
resources.mail.transport.host = "smtp.gmail.com"
resources.mail.transport.port = 587
resources.mail.transport.auth = "login"
resources.mail.transport.username = "email@address.com"
resources.mail.transport.password = "password"
resources.mail.transport.ssl = "tls"
And it "Just works (tm)"!
You can try with: ssl = tls
or port = 587
精彩评论