PDA

View Full Version : Swiftmailer - PHP Mail



ewilki01
03-30-2011, 09:02 PM
Hi,

I was trying to use swiftmailer to send emails and I'm not getting any errors with the script below, however it is not sending an email. Does anyone use swiftmailer to send emails through bluehost? I've tried using different smtp addresses and ports. Thanks for your help.


require("Swift/Swift.php");
require("Swift/Swift/Connection/SMTP.php");
$smtpaddress = "localhost";
$emailuser = "validusername";
$emailpassword = "validpassword";
$emailfrom = "xxx@xxx.com";
$emailto = "yyy@yyy.com";
$emailport = 25;

try{
$smtp = new Swift_Connection_SMTP($smtpaddress);
//$smtp->setUsername($emailuser);
//$smtp->setPassword($emailpassword);

$swift = new Swift($smtp);


$message = new Swift_Message($subj, $body, "text/html");
//Start a new list
$recipients = new Swift_RecipientList();
$recipients->addTo($emailto); //or we can just add the address
$result = $swift->send($message, $recipients, new Swift_Address($emailfrom, $emailfrom));
}
catch (Swift_ConnectionException $e) {
echo "There was a problem communicating with SMTP: " . $e->getMessage();
}
catch (Swift_Message_MimeException $e) {
echo "There was an unexpected problem building the email:" . $e->getMessage();
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}


if (!$result)
{
echo "error: ";
//this is where the script is getting to
}
else {
$swift->disconnect();
}