Sending email is not just for some message you want your members/customers know. In some cases, you will need to send to them one or multiple documents such as: quote/sale report/user guide or whatever you want.
Again, PHPMailer is my choice for email transfer class and also with an Authenticated SMTP Server.
In the example below, I’ll send 2 attachments: 1 image and 1 text file. In your real situation, they could be PDF, DOC, XLS, PPT or any compressed files.
PHP send email with multiple attachments with PHPMailer with SMTP Authentication
<?php include "class.smtp.php"; include "class.phpmailer.php"; $Host = "mail.yourdomain.com"; // SMTP servers $Username = "your-smtp-username@yourdomain.com"; // SMTP password $Password = "your-smtp-password"; // SMTP username $From = "from-email@yourdomain.com"; $FromName = "From Name"; $To = "to-email@yourdomain.com"; $ToName = "To Name"; $Subject = "Hello there, you will receive some files"; $Body = "This is a test email which includes attachment"; $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = $Host; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = $Username; $mail->Password = $Password; $mail->From = $From; $mail->FromName = $FromName; $mail->AddAddress($To , $ToName); $mail->WordWrap = 50; // set word wrap $mail->Priority = 1; $mail->IsHTML(true); $mail->Subject = $Subject; $mail->Body = $Body; $mail->AddAttachment("logo.jpg"); // attachment $mail->AddAttachment("text-attachment.txt"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } ?> |
Download source code above with PHPMailer include file and attachments for your testing. That example just send attachments to one recipient, if you want to send them to multiple recipients, let read more on How to send and CC to multiple recipients.