开发者

Can't add message body to PHP without loosing attachment

开发者 https://www.devze.com 2023-03-13 13:03 出处:网络
I have finally pieced together a code that would allow me to send an FDF file from my server to e-mail that didn\'t reduce my file to a 0kb attachment. Problem is, that I had to get rid of the body of

I have finally pieced together a code that would allow me to send an FDF file from my server to e-mail that didn't reduce my file to a 0kb attachment. Problem is, that I had to get rid of the body of the e-mail to do it.

I want to be able to add an HTML (or plain text) body to the e-mail being sent. Kind of like:

<h2>DWR Submittal</h2>
<p>Process the attachment in the system.</p>

STEP 1. Download file
STEP 2. Open with Adobe Acrobat
STEP 3. Verify form data
STEP 4. etc...
STEP 5. etc...

Where or how could this be done without compromising the attachment

<?php
  $fileatt = './dwrdocuments/dwr.fdf'; // Path to the file
  $fileatt_type = "application/octet-sdiveam"; // File Type
  $fileatt_name = date(mdy_his).'_dwr.fdf'; 
  $email_from = $_POST['From']; // Who the email is from
  $email_subject = 'DWR Submittal'; // The Subject of the email
  $email_txt = $_POST['Comments']; // Message that the email has in it

  $email_to = 'admin@example.com'; // Who the email is to

  $headers = "From: ".$email_from;

  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);

  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

  $headers .= "\nMIME-Version: 1.0\n" .
  "Content-Type: multipart/mixed;\n" .
  " boundary=\"{$mime_boundary}\"";

  $email_message .= "This is a multi-part message in MIME format.\n\n" .
  "--{$mime_boundary}\n" .
  "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
  "Content-divansfer-Encoding: 7bit\n\n" .
  $email_message . "\n\n";

  $data = chunk_split(base64_encode($data));

  $email_message .= "--{$mime开发者_C百科_boundary}\n" .
  "Content-Type: {$fileatt_type};\n" .
  " name=\"{$fileatt_name}\"\n" .
  //"Content-Disposition: attachment;\n" .
  //" filename=\"{$fileatt_name}\"\n" .
  "Content-Transfer-Encoding: base64\n\n" .
  $data . "\n\n" .
  "--{$mime_boundary}--\n";

  $ok = @mail($email_to, $email_subject, $email_message, $headers);
  header ("Location: ../confirm.html");  
?>


Try adding:

$email_message .= '<h2>DWR Submittal</h2>
<p>Process the attachment in the system.</p>

STEP 1. Download file
STEP 2. Open with Adobe Acrobat
STEP 3. Verify form data
STEP 4. etc...
STEP 5. etc...';

Right before:

$data = chunk_split(base64_encode($data));
0

精彩评论

暂无评论...
验证码 换一张
取 消