Reputation: 27
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?
Upvotes: 0
Views: 3944
Reputation: 376
Your code seems to work fine if the SMTP server address is valid and reachable with the credentials provided. Perhaps your SMTP server address or login credentials are incorrect or the SMTP server is not running? 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';
}
Upvotes: 1