Php Swiftmailer不通过smtp发送邮件

Php Swiftmailer不通过smtp发送邮件,php,email,symfony,smtp,swiftmailer,Php,Email,Symfony,Smtp,Swiftmailer,首先,我尝试使用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-smtp1

首先,我尝试使用
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.
和创建用于发送电子邮件的命令:

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而不是假脱机:

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 mailer实例然后发送时,我遇到了相同的错误

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

斯威夫特恢复正常,所以它工作正常。您必须检查邮件服务器日志,以查看swift完成电子邮件交付后发生的情况。e、 g.yandex或使用套接字的目标服务器.smtp将其作为垃圾邮件转储。就像我理解所有的邮件都被推到后台一样。我将spool处理程序设置为files,但不设置邮件sendno。swiftmailer使用您告诉它的任何传输方式。本地MTA、与SMTP服务器的直接TCP连接等。因此我选择SMTP,因此电子邮件应通过SMTP发送。这可能会有所帮助,但很难说,因为您的问题并没有真正表明您正在进行故障排除:
$mailer = new \Swift_Mailer($transport);
$mailer->send($message);