【问题标题】:Swiftmailer not send mail by smtpSwiftmailer 不通过 smtp 发送邮件
【发布时间】:2013-10-18 17:13:27
【问题描述】:

首先我尝试使用telnet发送它:

$ telnet smtp.yandex.ru 25
Trying 77.88.21.38...
Connected to smtp.yandex.ru.
Escape character is '^]'.
220 smtp12.mail.yandex.net ESMTP (Want to use Yandex.Mail for your domain? Visit http://pdd.yandex.ru)
EHLO yandex.ru
250-smtp12.mail.yandex.net
250-8BITMIME
250-PIPELINING
250-SIZE 42991616
250-STARTTLS
250-AUTH LOGIN PLAIN
250-DSN
250 ENHANCEDSTATUSCODES
AUTH LOGIN
334 VXNlcm5hbWU6
bWFpbEBua3QubWU=
334 UGFzc3dvcmQ6
*******
235 2.7.0 Authentication successful.
MAIL FROM:mail@nkt.me  
250 2.1.0 <mail@nkt.me> ok
RCPT TO:dev@nkt.me
250 2.1.5 <dev@nkt.me> recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: Q^BP5Q^AQ^B
To: dev@nkt.me
.
250 2.0.0 Ok: queued on smtp12.mail.yandex.net as 6VPPHaRoyW-LYnSwHm7
QUIT
221 2.0.0 Closing connection.
Connection closed by foreign host.

一切正常,我收到了邮件 然后我设置了 swiftmailer 参数:

mailer_transport: smtp
mailer_host:      smtp.yandex.ru
mailer_user:      mail@nkt.me
mailer_password:  *****
mailer_auth_mode:  login
mailer_encryption: ~
mailer_port:       25

并创建发送电子邮件的命令:

class SendMailCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('mail:send')
            ->setDescription('Send email')
            ->addOption('to', null, InputOption::VALUE_REQUIRED, 'Destination email address')
            ->addOption('body', 'b', InputOption::VALUE_REQUIRED, 'Mail body')
            ->addOption('subject', 'sub', InputOption::VALUE_OPTIONAL, 'Mail title');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $mailer = $this->getContainer()->get('mailer');
        $to = $input->getOption('to');
        $subject = $input->getOption('subject');
        $body = $input->getOption('body');
        $message = \Swift_Message::newInstance()
            ->setTo($to)
            ->setSubject($subject)
            ->setBody($body);
        $output->writeln('To: ' . $to);
        $output->writeln('Subject: ' . $subject);
        $output->writeln('Body: ' . $body);
        $output->writeln('Result: ' . $mailer->send($message));
    }
}

然后运行它:

$ app/console mail:send --to="dev@nkt.me" --body="Test body" --subject="Test"
To: dev@nkt.me
Subject: Test
Body: Test body
Result: 1

嗯,实际上不是,否则我不会发布这个问题。 我尝试使用 ssl,但仍然无法正常工作,可能是什么问题?

PS 现在我得到的是 smtp 而不是 spool:

protected function execute(InputInterface $input, OutputInterface $output)
{
    $mailer = $this->getContainer()->get('swiftmailer.transport.real');
    $message = \Swift_Message::newInstance()
        ->setFrom(['mail@nkt.me' => 'Admin'])
        ->setTo($input->getOption('to'))
        ->setSubject($input->getOption('subject'))
        ->setBody($input->getOption('body'));
    $output->writeln(sprintf('Sent %s emails', $mailer->send($message)));
}

但也会报错:

[Swift_TransportException]                                   
Expected response code 250 but got code "", with message "" 

【问题讨论】:

  • swift 返回 true,所以它工作正常。您必须检查邮件服务器日志,以了解在 swift 完成电子邮件移交后发生了什么。例如它被 yandex 或目标服务器作为垃圾邮件转储。
  • smtp 使用套接字。就像我了解所有电子邮件推送到假脱机。我将 spool-handler 设置为文件,但邮件不发送
  • 没有。 swiftmailer 使用您告诉它的任何传输方法。本地 MTA、与 SMTP 服务器的直接 TCP 连接等......
  • 所以我选择smtp,所以邮件应该smtp发送
  • 这可能会有所帮助,但很难说,因为您的问题并没有真正表明您正在解决问题:Got issue with Swift Mailer Not sending messages

标签: php email symfony smtp swiftmailer


【解决方案1】:

当我直接使用传输而不是将传输传递给 swift mailer 实例然后发送时,我遇到了同样的错误。

$mailer = new \Swift_Mailer($transport);
$mailer->send($message);

【讨论】:

    猜你喜欢
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多