2010-08-24 70 views
4

PHP的mail()函数发送邮件很好,但Swiftmailer的Swift_MailTransport不起作用!Swiftmailer不会发送邮件,但邮件()将

这工作:

mail('[email protected]', 'test '.date('H:i:s'), ''); 

但这并不:

$transport = Swift_MailTransport::newInstance(''); 
$mailer = Swift_Mailer::newInstance($transport); 
$message = Swift_Message::newInstance('test '.date('H:i:s')) 
    ->setFrom('[email protected]') 
    ->setTo('[email protected]') 
    ->setBody('Testing one two three'); 
$result = $mailer->send($message); 

(该[email protected]是在我的测试代码的一个有效的电子邮件地址替换)

邮件日志这两个事件在两种情况下看起来都非常相似,并且看起来后者正在发送邮件。

是否有关于Swiftmailer构建的消息导致其被垃圾邮件过滤器阻止的内容?

(顺便说一句,我一直在使用SMTP传输试过,没有运气,我计算过,因为邮件()正常工作,这将是微不足道的切换到Swiftmail的邮件运输...)

+0

这里同样的问题。我激活了[logger Plugin](http://swiftmailer.org/docs/plugins.html),但它没有打印任何内容。 – PiTheNumber 2012-05-16 10:05:40

+2

我再次问这个问题:http://stackoverflow.com/q/10617552/956397 – PiTheNumber 2012-05-16 13:03:55

+0

可能重复的[SwiftMailer不发送邮件,为什么?](https://stackoverflow.com/questions/10617552/swiftmailer-does - 不是,发送邮件,为什么) – fracz 2017-06-17 08:12:54

回答

-3

哪邮件服务器是您使用(如Web服务器或Gmail,雅虎..) 这是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('[email protected]') 
      ->setTo('[email protected]') 
      ->setBody('Testing one two three'); 
$result = $mailer->send($message); 

如果邮件()函数的工作,然后SwiftMailer也应该工作。 希望它为你工作,并帮助你。