Attaching an email as an attachement to another email in PHPMailer
07:37 13 Nov 2025

I am trying to attach an email directly to another another email.

Here is the source

        $mailer = new PHPMailer();
        $message = '

Some message body text<>'; $mailer->Subject = 'Email subject'; $mailer->addAddress('test@test.com'); $mailer->Body = $message; $mailer->FromName = $_SERVER['SERVER_NAME']; $mailer->Sender = $mailer->From = 'sender@test.com'; $mailer->isHTML(true); // Also attach the raw email as .eml file for better handling/training purposes $attachmentMail = new PHPMailer(); $attachmentMail->FromName = $violationFrom; $attachmentMail->addAddress('test@test.org'); $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?

email phpmailer email-attachments