How to send mail with attachments using PHPMailer

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->From='sender@gmail.com';
$objMail->FromName='Sender Name';
$objMail->AddEmbeddedImage("logo.jpg", 1, 'logo.jpg');
$objMail->Subject='Mail sent using PHPMailer';
$objMail->AddAddress('receiver@gmail.com', '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

Leave a Reply

Your email address will not be published. Required fields are marked *