我正在研究symfony 1.4。 对于电子邮件,我使用了swiftmailer。
$this->toAddress = $arrParams['toEmail'];
$this->bccAddress = $arrParams['bccEmail'];
$this->subject = $objSiteEmails->getSubject();
$this->body = $objSiteEmails->getMessageBody();
if (sfConfig::get('app_smtp_flag') == 'On') {
$transport = Swift_SmtpTransport::newInstance(sfConfig::get('app_smtp_host'), sfConfig::get('app_smtp_port'), sfConfig::get('app_smtp_security'))
->setUsername(sfConfig::get('app_smtp_username'))
->setPassword(sfConfig::get('app_smtp_password'));
} else {
$transport = Swift_MailTransport::newInstance();
}
$mailer = Swift_Mailer::newInstance($transport);
// COMMENT : Replace Common Variable
$SITE_URL = clsCommon::getSystemConfigVars('SITE_URL');
$supportEmail = clsCommon::getSystemConfigVars('SUPPORT_EMAIL');
$SITE_NAME = clsCommon::getSystemConfigVars('SITE_NAME');
$this->fromEmail = clsCommon::getSystemConfigVars('SITE_EMAIL_FROM');
$this->fromLabel = clsCommon::getSystemConfigVars('SITE_EMAIL_FROM_LABEL');
$this->body = preg_replace('/##SITE_URL##/', $SITE_URL, $this->body);
$this->body = preg_replace('/##SUPPORT_EMAIL##/', $supportEmail, $this->body);
$this->body = preg_replace('/##SITE_NAME##/', $SITE_NAME, $this->body);
//Create a message
$message = Swift_Message::newInstance($this->subject)
->setFrom(array($this->fromEmail => $this->fromLabel))
->setTo($this->toAddress)
->setBcc($this->bccAddress)
->addPart($this->body, $this->contentType);
$mailer->send($message);
我使用上面的代码进行电子邮件发送, 我收到如下错误,
500 |内部服务器错误| Swift_TransportException
Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/?p=WantAuthError y20sm15170767pfj.26 - gsmtp