Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

php - PHPMailer and attachments not displaying properly when opened

My apologies, I am very new and had difficulty with the editing process etc. I hope the following is more acceptable. The PHP application attaches to the 'receiving email box' and processes the received emails accordingly. It creates a new email that contains comments, attaches the original email and then sends the newly created email back to the 'from address' extracted from the original email. The original email may have been sent from any number of email programs available to users. It may also have pdf/text attachments. When I send the 'newly' created email to Gmail, it displays the attached original email (and it's attachments if any) correctly but not when it is sent to MS Outlook or Horde.

After execturing a new phpmailer class, I added the following:

$mail->CharSet = 'UTF-8';
$mail->Encoding = 'base64';

Coding to save the original email:

$mime = imap_fetchbody($inbox, $email_number, "");
file_put_contents('./workfolder/OriginalEmail.eml', $mime);

I have also tried this coding when saving the original email:

$headers = imap_fetchheader($inbox,$email_number, FT_PREFETCHTEXT);
$body = imap_body($inbox, $email_number);
$structures = imap_fetchstructure($inbox, $email_number);
file_put_contents('./workfolder/OriginalEmail.eml', $headers . '
' . $body . '
' . $structures);

I have checked the mime type which displays: message/rfc822

Coding used to attach original email:

$mail->AddAttachment('./workfolder/OriginalEmail.eml');

I have also tried this when attaching the original email:

$mailer->AddAttachment('./workfolder/','OriginalEmail.eml','base64','message/rfc822');

Wednesday - I am having such problems with adding comments. Here is what I tried:

$strOrigEmail = file_get_contents('./workfolder/OriginalEmail.eml');
echo '<BR><BR>$strOrigEmail: ' . $strOrigEmail;
$mail->addStringAttachment('$strOrigEmail', 'YourEmail.eml');

And the echo displays everything from the original email- headers, body etc. and the attachments (including their filename) but it is endocded. Below is a snippet below of what it looks like:

   name=junk.txt Content-Disposition: attachment; size=11; filename=junk.txt junk file --=_7-AofrqAv83eu5i63j73DWn-- 

I have also tried this and no better - displays same thing as above:

  $strOrigEmail = file_get_contents('./workfolder/OriginalEmail.eml');
  echo '<BR><BR>$strOrigEmail: ' . $strOrigEmail;
  $mail->addStringAttachment(base64_decode('$strOrigEmail'), 'YourEmail.eml');
question from:https://stackoverflow.com/questions/65886370/phpmailer-and-attachments-not-displaying-properly-when-opened

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...