I am trying to attach an email directly to another another email.
Here is the source
$mailer = new PHPMailer();
$message = '<p>Some message body text<>';
$mailer->Subject = 'Email subject';
$mailer->addAddress('[email protected]');
$mailer->Body = $message;
$mailer->FromName = $_SERVER['SERVER_NAME'];
$mailer->Sender = $mailer->From = '[email protected]';
$mailer->isHTML(true);
// Also attach the raw email as .eml file for better handling/training purposes
$attachmentMail = new PHPMailer();
$attachmentMail->FromName = $violationFrom;
$attachmentMail->addAddress('[email protected]');
$attachmentMail->Subject = $violationSubject;
$attachmentMail->isHTML(true);
$attachmentMail->Body = $violationBody;
// Prepare and get raw MIME source
if (!$attachmentMail->preSend()) {
echo "preSend failed: " . $attachmentMail->ErrorInfo; die();
}
$rawMime = $attachmentMail->getSentMIMEMessage();
// Attach the raw MIME as an .eml file
$mailer->addStringAttachment($rawMime, 'raw-email.eml', PHPMailer::ENCODING_BASE64, 'message/rfc822');
// Send the alert email
$mailer->send();
I get no error when sending the email. In the email I receive there is an attachment called raw-email.eml which also has the proper size. However, no matter the email client I use I can neither download the attachment, nor open it. Any hint why?