Agusprast\’s Weblog

September 12, 2007

send mail using SMTP authentication :: phpmailer script

Filed under: Uncategorized — agusprast @ 12:56 pm

Now a day, most of the hosting providers disable nobody user on their server or do not allow to send mail through script without SMTP authentication to stop the spamming from their servers. In such cases, you have to use SMTP authentication to send mail through PHP, ASP, or ASP.Net script. Below is the sample SMTP authentication script to send mail through PHP script:


$mail = new PHPMailer();

$mail->IsSMTP(); // send via SMTP
$mail->Host = “”; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = “”; // SMTP username
$mail->Password = “password”; // SMTP password

$mail->From = “”;
$mail->FromName = “Name”;
$mail->AddReplyTo(“”,”Your Name”);

$mail->WordWrap = 50; // set word wrap

$mail->IsHTML(true); // send as HTML

$mail->Subject = “Here is the subject”;
$mail->Body = “This is the HTML body“;
$mail->AltBody = “This is the text-only body”;

echo “Message was not sent”;
echo “Mailer Error: ” . $mail->ErrorInfo;

echo “Message has been sent”;


Note: To use above script, PHPMailer must be installed on the server. For more information, go to


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: