Possible Duplicate:
email zend framwork smtp在zend中使用gmail smtp發送電子郵件?
我有以下配置:
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"
我收到以下錯誤:
5.7.0 Must issue a STARTTLS command first. 74sm813723wem.41
我的代碼:
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;
}
}
有人能猜到是什麼錯誤?如果需要,我也可以發佈代碼。
感謝
我猜你必須首先發出一個STARTTLS命令;)不,認真:你正在使用'ssl = ssl',你應該嘗試'ssl = tls' - 這是兩種不同的方法來保證連接到服務器。 – Piskvor