PHP has default mail() function for sending mail. We can easily send mail using this function passing few parameters. But there is one nice class named ‘PHPMailer’ extending that function with lots of attractive and useful features. This PHPMailer, PHP email transport class features file attachments, SMTP servers, CCs, BCCs, HTML messages, word wrap, and more. Sends email via sendmail, PHP mail(), QMail, or with SMTP.
Here is an simple example to use PHPMailer.
$objMail = new PHPMailer; $objMail->IsHTML(true); $objMail->Fromemail@example.com'; $objMail->FromName='Sender Name'; $objMail->AddEmbeddedImage("logo.jpg", 1, 'logo.jpg'); $objMail->Subject='Mail sent using PHPMailer'; $objMail->AddAddress('firstname.lastname@example.org', 'Receiver Name'); $objMail->AddAttachment('attachment.docx'); $objMail->Body='This is mail body'; $objMail->Send();
You can find detail documentation here.
2 thoughts on “How to send mail with attachments using PHPMailer”
There are some interesting points in time in this article but I don’t know if I see all of them center to heart. There is some validity but I will take hold opinion until I look into it further. Good article , thanks and we want more!
Marvelous, what a weblog it is! This web site gives
helpful facts to us, keep it up.