Tuesday, 4 May 2010

php code for sending email with godaddy using phpmailer

require dirname(__FILE__).'/phpmailer/class.phpmailer.php';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body = $content;
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
//$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->Host = "relay-hosting.secureserver.net"; // sets GMAIL as the SMTP server


$mail->SetFrom('postman@website.com', 'Postman');

$mail->Subject = $subject;

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($content);

$address = $to;
$mail->AddAddress($address);
if($attachment) {
$mail->AddAttachment($attachment); // attachment
}
$mail->Send();

return true;
} catch (phpmailerException $e) {
//echo $e->errorMessage();
}

No comments:

Post a Comment

Please share your thought about this