Sending emails via phpmailer

Here we configure SMTP authentication Using phpmailer. You can acquire a copy of phpmailer class from http://sourceforge.net/project/showfiles.php?group_id=26031. You should upload the file "class.phpmailer.php" to same folder for your script

IMPORTANT:  From email address and your authorization email address MUST be same.

<?php
require("class.phpmailer.php");
$mail = new PHPMailer();$mail = new PHPMailer();
$mail->CharSet ="utf-8"; // You can adjust the Charset according to your language
$mail->IsSMTP();
$mail->Host = "mail.Yourdomain.com";
$mail->From="
youremail@yourdomain.com"; //REMEMBER, this MUST be same as your authorization email address above.
$mail->FromName="PHPmailer Testing";
$mail->SMTPAuth = true;
$mail->Username = "
youremail@yourdomain.com";
$mail->Password = "yourpassword";

$mail->AddAddress("sendTOemail");
$mail->Subject = "Test 1";
$mail->Body = "Test 1 of PHPMailer.";

if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
   echo "Letter is sent";
}?>

To add information about sender, use following functions:

$mail->Sender="mailer@example.com"; // indicates ReturnPath header
$mail->AddReplyTo("
replies@example.com", "Replies for my site"); // indicates ReplyTo headers

For specifying various types of recepients use these:

$mail->AddAddress("mail1@domain.com", "Recepient 1");
$mail->AddCC("
mail1@domain.com", "Recepient 1");
$mail->AddBCC("
mail1@domain.com", "Recepient 1");

 

Share

- has written 121 posts.


Leave a Reply

You must be logged in to post a comment.