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.

How to use

Download PHPMailer from
Extract it into your web directory.
Turn on SSL support.
Use the following code to send email.

Sample code

$mail = new PHPMailer(); // Creating PHPMailer object
$body = "Hai hello, this is my first mail using PHPMailer. ";
$mail->SMTPAuth = true;
$mail->Host = "ssl://"; // SMTP Server.
Setting gmail as the SMTP Server
$mail->Username = ""; // 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 = ""; // From email-id
$mail->FromName = "PHP Developer"; // From Name
$mail->AddAddress("","Name"); // To address.
$mail->Send()) {
"Mailer Error: " . $mail->ErrorInfo;
else {
"Message has been sent";

courtsey: nexabion software cum webdevelopers and webhosting providers kerala

No comments:

Post a Comment


Related Posts with Thumbnails