【问题标题】:swiftmailer sending email rejected in Silexswiftmailer 发送电子邮件在 Silex 中被拒绝
【发布时间】:2015-11-12 16:47:01
【问题描述】:

我一直在尝试将 swiftmailer 与 Silex 一起使用,在阅读了完整的文档、查看了此处的主题并进行了一些测试之后,我完全不知道为什么不想发送电子邮件。 为了寻找答案,我一直在使用 ArrayLogger 插件,它给了我一个提示:<< 521 Mail rejected - not allowed to receive mail from this sender

这是我的 app.php 中的服务声明:

$app->register(new Silex\Provider\SwiftmailerServiceProvider());

这是我的控制器:

/**
     * Contact page controller.
     *
     * @param Application $app Silex application
     */
    public function contactAction(Request $request, Application $app) {
        $contact = new Contact();
        $contactForm = $app['form.factory']->create(new ContactType(), $contact);
        $contactForm->handleRequest($request);
        if ($contactForm->isSubmitted() && $contactForm->isValid()) {
            $contact->notify($app);
            $app['session']->getFlashBag()->add('success', 'Your message was successfully sent.');
        }
        return $app['twig']->render('contact.html.twig', array(
            'contactForm' => $contactForm->createView()));
    }

这是来自 Contact 类的方法 notify:

/**
     * Sends an email to the administrator using this object's parameters
     * 
     * @param Application $app
     */
    public function notify($app) {
        $transport = \Swift_SmtpTransport::newInstance('smtp.numericable.fr', 25);

        $mailer = \Swift_Mailer::newInstance($transport);

        // To use the ArrayLogger
        $logger = new \Swift_Plugins_Loggers_ArrayLogger();
        $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));

        $message = \Swift_Message::newInstance($this->getEmitter().' wants to help')
        ->setFrom(array($this->getEmail()))
        ->setTo(array('example@rabbit.com'))
        ->setBody($this->getMessage());

        $app['swiftmailer.use_spool'] = false;
        if (!$mailer->send($message, $failures)) {
            var_dump($logger->dump());
        }
    }

配置(电子邮件和端口)是我在文件 php.ini 中找到的信息,但由于我对这一切了解不多,所以我可能在那里弄​​错了。

【问题讨论】:

标签: php symfony email swiftmailer silex


【解决方案1】:

您的问题似乎是邮件中继服务器问题,而不是 SwiftMailer 问题。检查您是否被允许使用该服务器使用 telnet 发送电子邮件。如果您不知道该怎么做,请看这里: http://ubuntuwiki.net/index.php/SMTP,_testing_via_Telnet

【讨论】:

  • Connection to localhost... Impossible to open a connexion for the host, on the port 25: Failure on connection ,我也尝试使用端口 587 和 8080 但我得到了同样的错误。跨度>
  • @Cachwir 你不必远程登录本地主机,本地主机是你自己的机器。在执行此 PHP 的服务器上,您必须远程登录 SMTP 服务器(在您的情况下为 smtp.numericable.fr),因此您的命令必须是 telnet smtp.numericable.fr 25,然后按照链接说明进行操作。我再说一遍,您必须在执行 PHP 代码的服务器上执行此操作,而不是从您自己的开发计算机上执行此操作。
  • @mTorres 它不起作用。这是日志: 220 smtp2.josinet.cz 准备好 HELO justtesting250 欢迎 10.63.2.20 发件人:me@telnettingin.com250 我发件人好的 RCPT 收件人:postmaster@mail.getsdeliveredhere.net521 邮件被拒绝 - 不允许接收来自该发件人的邮件
  • 错误消息意味着postmaster@mail.getsdeliveredhere.net 不允许来自me@telnettingin.com 的消息。听起来像是配置错误。
  • @Cachwir,您可能只需要一些 SMTP 身份验证。请注意,一旦您指示要发送邮件(rcpt 到)的服务器,服务器就会拒绝该命令。你有用户名和密码吗?如果是这样,try to use them when creating the new instance
猜你喜欢
  • 1970-01-01
  • 2015-04-16
  • 1970-01-01
  • 2014-09-20
  • 2012-12-25
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多