Send email using gmail smtp in zend?
10,694
Solution 1
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 protected]"
resources.mail.transport.password = "password"
resources.mail.transport.ssl = "tls"
And it "Just works (tm)"!
Solution 2
You can try with: ssl = tls
or port = 587
Comments
-
Awan almost 2 years
Possible Duplicate:
email zend framwork smtpI have following configuration:
smtp.type = Zend_Mail_Transport_Smtp smtp.smtpServer = "smtp.gmail.com" smtp.username = "[email protected]" smtp.password = "dddd" smtp.email = "[email protected]" 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
-
Piskvor left the building almost 13 yearsI'm guessing that you must issue a STARTTLS command first ;) No, seriously: you are using
ssl = ssl
, you should tryssl = tls
- those are two different methods of securing the connection to the server.
-
-
Awan almost 13 yearsOK. Let me try this but where are you using this
resources.mail.transport.type
?? -
Phliplip almost 13 yearsEhh.. in application.in :) Do you use ONLY Zend_Mail or is it a fullblown ZF site? framework.zend.com/manual/en/learning.quickstart.html Anyways, you should be able to use our config values in your specifications.
-
Jon Skarpeteig almost 13 yearsThe mail resource simply autoregister to Zend_Mail when used with Zend MVC as a mail transport
-
Awan almost 13 yearsI tried this setting and error is changed:
5.5.1 Authentication Required. Learn more at 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 h43sm824480wes.35
-
Awan almost 13 years@Phliplip: I am running it in Zend environment but I dont have
"resources.mail.transport.type = Zend_Mail_Transport_Smtp "
in my application.ini -
Phliplip almost 13 yearsThis means wrong username/password combination.
-
Awan almost 13 yearsI am using correct username/password combination. I am successfully login to gmail using my username and password.
-
Awan almost 13 yearsIf you paste your mail sending code. May be it will help me..
-
Phliplip almost 13 years@Awan: What if you paste your code, then we can help you :)
-
Awan almost 13 yearsOK review my question again...
-
Phliplip almost 13 years@Awan: You need to add port and auth to your
$config
array. auth is the authentificationType used. In this case 'login', it could be 'digest' in other cases.