简体   繁体   English

Swiftmailer不发送PHP邮件

[英]Swiftmailer not sending mail in php

error_reporting(E_ALL);
require_once 'swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.your_domain.com', 25)
->setUsername('name@your_domain.com')
->setPassword('your_password')
;

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('PHP Message')
->setFrom(array('name@your_domain.com'))
->setTo(array('name@your_domain.com'))
->setBody('PHP Swift Mailer sent with authentication')
;

//Send the message
$result = $mailer->send($message);



if (!$mailer->send($message, $failures)) {
echo "Failures:";
print_r($failures);
}

This is the code I used for sending email. 这是我用于发送电子邮件的代码。 But its not working properly. 但是它不能正常工作。 There is not even any error or fail message. 甚至没有任何错误或失败消息。 What is wrong? 怎么了?

Your code seems to work fine if the SMTP server address is valid and reachable with the credentials provided. 如果SMTP服务器地址有效且可通过提供的凭据访问,则您的代码似乎可以正常工作。 Perhaps your SMTP server address or login credentials are incorrect or the SMTP server is not running? 也许您的SMTP服务器地址或登录凭据不正确,或者SMTP服务器未运行? The code ran correctly with valid settings. 该代码使用有效设置正确运行。

Also, try adding a message upon success as well so you know that the code sent out the email - otherwise you might not notice it's actually working if the emails get spam-filtered at destination: 另外,也请尝试在成功时添加一条消息,以使您知道该代码已发送电子邮件-否则,如果电子邮件在目标位置被垃圾邮件过滤,则您可能不会注意到它实际上是有效的:

if (!$mailer->send($message, $failures)) {
  echo "Failures:";
  print_r($failures);
} else {
    echo 'email sent successfully';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM