How do I send email using PHP with phpMailer class

Expand / Collapse
 
     

How do I send email using PHP with phpMailer class


Here's a sample for using SMTP. Our server setting REQUIRES all customers to use SMTP authorization in order to send out email. 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->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="My site's mailer";

$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");



Tags:




User Comments

Click to subscribe to comments RSS feed...

No Member Photo
View Members Profile...,Posted By by maturski radovi from http://www.maturskiradovi.net added 10/29/2009 9:21 AM


Thank you so much for this line: <span id="ctl00_ctlContentPlaceHolder_ctl00_ctlViewArticle_ctlPanelBar_lblArticleText"><font face="Arial"><font face="Courier New">$mail->CharSet ="utf-8"; <br />It solved my problems with garbage text in subject.<br /><br /><br />:)))<br /></font></font></span>
Helpful? YesYes NoNo

Add Your Comments


Name: *
Email Address:
Web Address:
Verification Code:
*
 

Details
Last Modified:11/16/2009 5:27 PM
Last Modified By: Mark
Type: How to do this?
Rated 3 stars based on 1 vote.
Article has been viewed 4,958 times.
Options