Saturday, April 25, 2009

Send email from a PHP script

PHPMailer is a powerful email transport class. Sending email using PHPMailer is simple.

PHPMailer features:-


  • Supports emails digitally signed with S/MIME encryption!
  • Supports emails with multiple TOs, CCs, BCCs and REPLY-TOs
  • Works on any platform.
  • Supports Text & HTML emails.
  • Embedded image support.
  • Multipart/alternative emails for mail clients that do not read HTML email.
  • Flexible debugging.
  • Custom mail headers.
  • Redundant SMTP servers.
  • Support for 8bit, base64, binary, and quoted-printable encoding.
  • Word wrap.
  • Multiple fs, string, and binary attachments (those from database, string, etc).
  • SMTP authentication.
  • Tested on multiple SMTP servers: Sendmail, qmail, Postfix, Gmail, Imail, Exchange, etc.
  • Good documentation, many examples included in download.
  • It's swift, small, and simple.
[http://phpmailer.codeworxtech.com]

How to use

Download PHPMailer from http://sourceforge.net/projects/PHPmailer
Extract it into your web directory.
Turn on SSL support.
Use the following code to send email.

Sample code

include("/lib/phpmailer/class.phpmailer.php");
$mail = new PHPMailer(); // Creating PHPMailer object
$body = "Hai hello, this is my first mail using PHPMailer. ";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "ssl://smtp.gmail.com:465"; // SMTP Server.
/*
Setting gmail as the SMTP Server
*/
$mail->Username = "myphpapp@gmail.com"; // username [Gmail]
$mail->Password = "mypassword
"; // password for myphpapp
$mail->AltBody = "This is the body when user views in plain text format";
$mail->Subject = "Say hello!"; // This is the subject
$mail->From = "myphpapp@gmail.com"; // From email-id
$mail->FromName = "PHP Developer"; // From Name
$mail->MsgHTML($body);
$mail->AddAddress("toaddress@gmail.com","Name"); // To address.
$mail->IsHTML(true);
if(!
$mail->Send()) {
echo
"Mailer Error: " . $mail->ErrorInfo;
}
else {
echo
"Message has been sent";
}
?> 


courtsey: nexabion software cum webdevelopers and webhosting providers kerala

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails