phpMailer - a PHP class to send emails
Translation of the original in Catalan. Read it in: CatalàCastellano
In PHP, when you have to send an email you often use the mail() function although it is a bit limited as far as the parameters you can pass to the SMTP server. For example, authentication and encryption issues. Via pear there are several solutions but sometimes the solution built into your application needs to be independent of that kind of system requirement. So phpMailer can help us out of more than one muddle.
It supports:
-
Can send emails with multiple TOs, CCs, BCCs and REPLY-TOs
-
Redundant SMTP servers
-
Multipart/alternative emails for mail clients that do not read HTML email
-
Support for 8bit, base64, binary, and quoted-printable encoding
-
Uses the same methods as the very popular AspEmail active server (COM) component
-
SMTP authentication
-
Word wrap
-
Address reset functions
-
HTML email
-
Tested on multiple SMTP servers: Sendmail, qmail, Postfix, Imail, Exchange, etc
-
Works on any platform
-
Flexible debugging
-
Custom mail headers
-
Multiple fs, string, and binary attachments (those from database, string, etc)
-
Embedded image support
A small example of use so you can see how simple it is to use:
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp1.site.com;smtp2.site.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "jswan"; // SMTP username
$mail->Password = "secret"; // SMTP password
$mail->From = "from@email.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@site.com","Josh Adams");
$mail->AddAddress("ellen@site.com"); // optional name
$mail->AddReplyTo("info@site.com","Information");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML body";
$mail->AltBody = "This is the text-only body";
if(!$mail->Send())
{
echo "Message was not sent ";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
I came across this find through the article phpMailer , a great Email transfer class on Moody Bahrain's blog.
2 comments
Comments from the old blog, as they were written. Comments are closed.
—
Sembla prou interessant, nomes dues coses:
1.- Permet enviar el mail en modo pla+html? o nomes l'envia en mode html?
2.- Que es exactament PEAR?
Records!!!
—
[1]
1) jo diria que si que ho pot fer pla+html, no ho he provat. Però crec que no seria difícil.
2) PEAR són un conjunt de paquetes que afegeixen noves funcions i classes al PHP, a l'estíl d'un framework. Seria un equivalent al CPAN de Perl. Aquests nous paquets poden aportar funcions de qualsevol tipus: bbdd, gràfics, matetmàtiques, MVC, etc.