SwiftMailer不发邮件,为什么? [英] SwiftMailer does not send mail, why?
问题描述
SwiftMail不发送我的电子邮件,而 mail()
可以正常工作。与此处相同。
SwiftMail does not send my email, while mail()
does work. Same as here.
我添加了EchoLogger,但它不打印任何东西。
I added the EchoLogger but it does not print anything.
$message = Swift_Message::newInstance();
$message->setSubject('Test');
$message->setTo( $email );
$message->setFrom(ABSENDER);
$message->setBody($nl_text);
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$logger = new Swift_Plugins_Loggers_EchoLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
$result = $mailer->send($message, $failures);
var_dump($failures);
电子邮件在 $ failures
中返回,为什么?
The email is returned in $failures
but why?
更新
在 Swift_Transport_SimpleMailInvoker ::邮件
我抛出了这个参数,并得到这个:
In Swift_Transport_SimpleMailInvoker::mail
I dumped out the parameters and got this:
$headers =>
string(208) "Message-ID: <1337173064.4fb3a4480b8dd@domain.de>
Date: Wed, 16 May 2012 14:57:44 +0200
From: news@domain.de
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
"
$extraParams =>
string(15) "-fnews@domain.de"
$ to,$ subject,$ body
与我在 mail()
中使用的相同。仍然不知道问题是什么。
$to, $subject, $body
is same as I used in mail()
. Still no idea what the problem is.
更新#2
对我而言:
mail($email, 'Test', $nl_text, "From: " . ABSENDER);
免责声明:这不是一个解决方案,而是我使用的解决方法,因为我没有时间调试框架并找到一个真正的解决方案。随意使用上面提供的信息调试自己,并在此处发布您的解决方案。
Disclaimer: This is not a solution but the workaround I used, because I did not have the time to debugger the framework and find a real solution. Feel free to use the information given above to debug yourself and post your solution here. I will gladly accept and upvote it.
推荐答案
我也有同样的问题。
根据 swiftmailer.org 的文档,默认情况下Swift_MailTransport :: newInstance()使用参数 -f%s
这就是为什么你得到 - fnews@domain.de
来解决那个地方空白 -f%s
之间的空格。
According to the documentation swiftmailer.org by default Swift_MailTransport::newInstance() uses parameters -f%s
and that is why you got "-fnews@domain.de"
, to solve that place blank space between -f %s
.
您的代码现在可以看起来像:
$ message = Swift_Message :: newInstance(' - f%s')
;
Your code now can be looks like that:
$message = Swift_Message::newInstance('-f %s')
;
我解决了这个问题,只是通过 null
to __construct()。所以我的工作代码如下所示:
I solved that problem simply passing null
to __construct(). So my working code looks like that:
$ message = Swift_Message :: newInstance(null)
;
我希望它会帮助某人。
PS我使用Postfix发送电子邮件。
P.S. I use Postfix to send emails.
这篇关于SwiftMailer不发邮件,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!