PHP SwiftMailer Not sending
I am doing some testing prior to working on some production code开发者_如何学JAVA and need to figure out how to do an auto e-mail.
The below script runs fine and the result of the send method returns 1, as if it sends. However, nothing ever makes it to the recipient.
require_once '/home/absolut2/lib/swift_required.php';
//Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.mysite.com', 25)
->setUsername('myuser')
->setPassword('password')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
//Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
//Mail
$transport = Swift_MailTransport::newInstance();
*/
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance('Subject')
->setFrom(array('rp@mysite.com' => 'RP'))
->setTo(array('rp@gmail.com'))
->setBody('Here is the message itself');
//Send the message
$result = $mailer->send($message);
echo "Messages sent: " . $result;
The code itself seems fine, so I guess something else is wrong. Either check the spam queue of the recipient or maybe just the address was rejected.
Find out if addresses were rejected.
You can do that with this code:
if (!$mailer->send($message, $failures)) {
echo "Failures:";
print_r($failures);
}
精彩评论