Monday, October 27, 2008

Send mails with PHPMailer

PHPMailer is a PHP class for PHP that provides a package of functions to send email. The two primary features are sending HTML Email and e-mails with attachments. PHPMailer supports nearly all possiblities to send email: mail() , Sendmail, qmail & direct to SMTP server. You can use any feature of SMTP-based e-mail, multiple recepients via to, CC, BCC, etc. In short: PHPMailer is an efficient way to send e-mail within PHP.

As you may know, it is simply to send mails with the PHP mail() function. So why use PHPMailer? Isn't it slower? Yes that's true, but PHPMailer makes it easy to send e-mail, makes it possible to attachm files, send HTML e-mail, etc. With PHPMailer you can even use your own SNTP server and avoid Sendmail routines used by the mail() function on *nix platforms. [Ref. http://phpmailer.codeworxtech.com ]

require ( "class.phpmailer.php" );

$mail  =  new  PHPMailer();

$mail ->IsSMTP();   // telling the class to use SMTP
$mail ->Host     =  "smtp.example.com" ;  // SMTP server

$mail ->From     =  "from@example.com" ;
$mail ->AddAddress( "myfriend@example.net" );

$mail ->Subject  =  "First PHPMailer Message" ;
$mail ->Body     =  "Hi! \n\n This is my first e-mail sent through PHPMailer." ;
$mail ->WordWrap = 50;

if (! $mail ->Send()) {
echo 'Message was not sent.' ;
echo 'Mailer error: '  .  $mail ->ErrorInfo;
}  else  {
echo 'Message has been sent.' ;

2 comments:

  1. class.phpmailer.php is this an inbuilt class in PHP or we have to download it separately.

    ReplyDelete
  2. This is an third party tool hosted in SF. You can download it in - http://sourceforge.net/project/showfiles.php?group_id=26031

    ReplyDelete