Swiftmailer不会发送邮件,但是mail()将会发送 [英] Swiftmailer won't send mail, but mail() will
问题描述
这样做:
mail('user@example.com','test'.date('H:i:s'),'');
但这不是:
$ transport = Swift_MailTransport :: newInstance('');
$ mailer = Swift_Mailer :: newInstance($ transport);
$ message = Swift_Message :: newInstance('test'.date('H:i:s'))
- > setFrom('user@example.com')
- > ; setTo('user@example.com')
- > setBody('Testing one two three');
$ result = $ mailer-> send($ message);
( user@example.com
在我的测试代码中被一个有效的电子邮件地址替换。)
两种事件的邮件日志在这两种情况下看起来都非常相似,似乎邮件正在发送
是否有一些关于Swiftmailer构建的消息导致垃圾邮件过滤器阻止的信息?
(p)(顺便说一句,我尝试使用SMTP传输,没有运气;我认为,由于mail()正常工作,切换到Swiftmail的邮件传输将是微不足道的。)
您正在使用哪个邮件服务器(如您的Web服务器或gmail,yahoo ..)
这是用于gmail SMTP,
$ transport = Swift_SmtpTransport :: newInstance('smtp.gmail.com',465,ssl)
- > ; setUsername($ login_id)
- > setPassword($ password)
;
$ mailer = Swift_Mailer :: newInstance($ transport);
$ message = Swift_Message :: newInstance('test'.date('H:i:s'))
- > setFrom('user@example.com')
- > ; setTo('user@example.com')
- > setBody('Testing one two three');
$ result = $ mailer-> send($ message);
如果mail()函数有效,那么SwiftMailer也应该可以工作。
希望它为你工作,并帮助你。
PHP's mail() function sends mail fine, but Swiftmailer's Swift_MailTransport doesn't work!
This works:
mail('user@example.com', 'test '.date('H:i:s'), '');
But this does not:
$transport = Swift_MailTransport::newInstance('');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('test '.date('H:i:s'))
->setFrom('user@example.com')
->setTo('user@example.com')
->setBody('Testing one two three');
$result = $mailer->send($message);
(The user@example.com
is replaced by a valid email address in my test code.)
The mail logs for both events look very similar in both cases, and it appears that mail is being sent in the latter.
Could there be something about the message constructed by Swiftmailer that is causing it to be blocked by a spam filter?
(By the way, I have tried using the SMTP transport, with no luck; I figured that since mail() works correctly, it would be trivial to switch to Swiftmail's Mail transport...)
Which mail server are you using(like your web server or gmail,yahoo..) this is for gmail SMTP,
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername($login_id)
->setPassword($password)
;
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('test '.date('H:i:s'))
->setFrom('user@example.com')
->setTo('user@example.com')
->setBody('Testing one two three');
$result = $mailer->send($message);
if mail() function works, then SwiftMailer should also work. Hope it worked for you, and helped you.
这篇关于Swiftmailer不会发送邮件,但是mail()将会发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!