I am trying to use Swift Mailer to send an email with an attachment. The email is not sending. I am fairly new to PHP so it may be a simple problem, but I cannot figure it out. Code:
<?php
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465)
->setUsername('my gmail address')
->setPassword('my gmail password')
;
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setSubject('subject')
->setFrom(array('John@doe.com' => 'John Doe'))
->setTo(array('Jane@doe.com' => 'Jane Doe'))
->setBody('body')
->attach(Swift_Attachment::fromPath('image.png'))
;
echo('test 1');
$numSent = $mailer->send($message);
echo('test 2');
printf("Sent %d messages\n", $numSent);
if ($mailer->send($message))
{
echo "Sent\n";
}
else {
echo "Failed\n";
}
?>
swift_required.php is successfully being included. My test 1 echo runs, but test 2 echo never does. This makes me think that the problem exists within the $numSent variable. Of course the problem is still very broad, but hopefully that narrows things a little bit. Also, none of the functions below $numSent work, so it does not tell me whether my email is being sent or not.
Figured it out, turns out you need to use 'tls://smtp.gmail.com'.