【问题标题】:Swiftmailer Caught exception: Expected response code 250 but got code "", with message ""Swiftmailer 捕获异常:预期响应代码 250 但得到代码“”,带有消息“”
【发布时间】:2014-10-10 12:35:59
【问题描述】:

我在 symfony 1.4 swiftmailer 中遇到问题。 当我尝试使用 sendmail 功能() 我得到错误代码:

Caught exception: Expected response code 250 but got code "", with message ""

而且 symfony 不发送消息。

下面是我的发送邮件功能

static function sendmail($mail, $textmessage, $subject) {
    try {
        $message = Swift_Message::newInstance()
                ->setFrom(sfConfig::get('app_mail_address_from'))
                ->setTo($mail)
                ->setSubject($subject)
                ->setBody($textmessage)
                ->setContentType("text/html");
      //  sfContext::getInstance()->getMailer()->send($message);
      sfContext::getInstance()->getMailer()->send($message);
    //   mail("mymailcom", "A subject", "A message", "FROM: noreply@mail.com");

    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";
    }


}

我想做什么:

  1. 我尝试测试 mail() 函数。效果很好。

  2. 我尝试将 smtp 设置更改为 gmail 帐户 - 不起作用

我的服务器是:godaddy.co.uk 服务器上的 CentOs6

有人可以帮我解决这个错误吗?

【问题讨论】:

标签: php symfony-1.4 swiftmailer


【解决方案1】:

好的,来自评论的帖子有帮助,也许有人会使用它: 我认为问题出在 swiftmailer 上:

 try {

        $transport = Swift_MailTransport::newInstance();
        $mailer = Swift_Mailer::newInstance($transport);
        $message = Swift_Message::newInstance('Subject')
            ->setFrom(sfConfig::get('app_mail_address_from'))
            ->setTo($mail)
            ->setSubject($subject)
            ->setBody($textmessage)
            ->setContentType("text/html");
        $mailer->send($message);
    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";die;
    }

这是工作代码

【讨论】:

  • 检查您的代码,noreply@gmail.com 行有问题");
猜你喜欢
  • 2015-09-16
  • 2018-05-03
  • 2017-02-12
  • 2019-05-07
  • 2016-05-28
  • 1970-01-01
  • 1970-01-01
  • 2016-08-14
  • 2020-11-15
相关资源
最近更新 更多