//attachment
$filename = 'test.pdf';
$path = file_get_contents(INC_PATH . 'theme-templates');
$file = $path . "/" . $filename;
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
$eol = "\r\n";
function send_email($email, $emailCopy, $from, $subject, $message, $headers = null)
{
// Unique boundary
$boundary = md5(uniqid());
// If no $headers sent
if (empty($headers)) {
// Add From: header
$headers = "From: " . $from->name . " <" . $from->email . ">\r\n";
// Specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
// Tell e-mail client this e-mail contains alternate versions
$headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"\r\n\r\n";
}
// Plain text version of message
$body = "--$boundary\r\n" .
"Content-Type: text/plain; charset=UTF-8\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode(strip_tags($message)));
// HTML version of message
$body .= "--$boundary\r\n" .
"Content-Type: text/html; charset=UTF-8\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($message));
$body .= "--$boundary--";
// attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";
// end of attechment
// Send Email
if (is_array($email)) {
foreach ($email as $e) {
mail($e, $subject, $body, $headers);
}
} else {
return mail($email, $subject, $body, $headers, $emailCopy);
}
}
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom('from@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'PHPMailer file sender';
$mail->msgHTML("My message body");
// Attach uploaded files
$mail->addAttachment($filename1);
$mail->addAttachment($filename2);
$mail->send();
//$body .= "Content-Disposition: attachment" . $eol;
$body .= "Content-Disposition: attachment" . $eol . $eol;
$body .= $content . $eol;