2
首先,我試圖把它用telnet
:Swiftmailer不是由SMTP發送郵件
$ 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:[email protected]
250 2.1.0 <[email protected]> ok
RCPT TO:[email protected]
250 2.1.5 <[email protected]> recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: Q^BP5Q^AQ^B
To: [email protected]
.
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 PARAMS:
mailer_transport: smtp
mailer_host: smtp.yandex.ru
mailer_user: [email protected]
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="[email protected]" --body="Test body" --subject="Test"
To: [email protected]
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(['[email protected]' => '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,所以它工作正常。您必須檢查郵件服務器日誌,以查看在完成交付電子郵件後發生了什麼。例如它被yandex或目標服務器轉儲爲垃圾郵件。 –
smtp使用套接字。就像我瞭解所有電子郵件推到後臺。我將spool-handler設置爲文件,但郵件不會發送 – nkt
no。 swiftmailer使用你告訴它的任何傳輸方法。無論是本地MTA,直接TCP連接到SMTP服務器等... –