1

我正在尝试使用 Mail\Transport\Sendmail() 在 zend 框架 2 中发送电子邮件。它显示无效电子邮件 ID 的运行时异常。

错误消息是“无法发送邮件:邮件():SMTP 服务器响应:550 5.1.1 ... 用户未知”

Zend\Mail\Exception\RuntimeException

$options = new Mail\Transport\SmtpOptions($config_setting);

    // render Email Content
    $this->renderer = $this->getServiceLocator()->get('ViewRenderer');
    $content = $this->renderer->render($config['mail']['templates']. $messageTemplate, $messageParam);

    // make a header as html
    $html = new MimePart($content);
    $html->type = $config['mail']['content_type'];
    $body = new MimeMessage();
    $body->setParts(array($html,));

    // instance mail
    $mail = new Mail\Message();
    $mail->setBody($body); // will generate our code html from template.phtml
    $mail->setFrom($config['mail']['from_email'],$config['mail']['from_name']);
    $mail->setTo($mailTo);
    $mail->setSubject($subject);
    //$transport = new Mail\Transport\Smtp($options);
    $transport = new Mail\Transport\Sendmail();

    try{
        $response = @$transport->send($mail);
        return $response;
    }
    catch(Zend\Mail\Exception\RuntimeException $ex)
    {
        $ex->getMessage();
        $response = array('error' => 1, 'msg' => $ex->getMessage());
        //return $response;
    }

我想忽略此异常消息。

4

1 回答 1

1

您有两种传输方式,一种是 Sendmail,一种是 SMTP。Sendmail 是您电脑上的内部邮件服务器,应该可以正常工作。SMTP 是一种让(可能是外部的)邮件服务器发送电子邮件的协议。您可以使用自己的 SMPT 服务器,或连接到例如 Google 或 Hotmail 以通过 SMTP 发送邮件。

你的代码中有这个:

//$transport = new Mail\Transport\Smtp($options);
$transport = new Mail\Transport\Sendmail();

因此,您在代码中使用了 Sendmail 传输,但来自 SMTP的例外是:

无法发送邮件:mail():SMTP 服务器响应:550 5.1.1 ... 用户未知

所以在我看来,您在代码中的某个地方不小心使用了 SMTP。切换到 Sendmail,它应该可以正常工作,或者使用您发布的代码再次检查您的问题。

于 2013-09-18T12:34:07.143 回答