简体   繁体   中英

MIME error- accepting MIME types while sending a email

The following script works (almost) just as I want. This project is so near completion with one small problem. In the email message I get the following: "If you can see this MIME then your client doesn't accept MIME types! --jacquie1003"

This is being sent through Novell GroupWise. I have included the mail script and the resulting email. The email arrives with the attachment and everything seems good except that error message. See the message body below.

The users are completing a form with approximately 95 fields. When they submit a validation is done on mandatory fields. If everthing is complete the completed form is presented to them in the same window, a file is created, and the email is created and sent (with the created file as an attachment) to one of five preset recipient groups.

What am I doing wrong in my mail script. Any help would be greatly appreciated. At this point I am not looking to use PEAR, PHPmailer, Zend, etc... unless I absolutely have to.

I apologize in advance for some of the formatting of my cut-and-paste. Thank you in advance

beginning of mail script

<pre>$head_division = $_POST['head_division'];
$category = $_POST['category'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];

$FilePath = "c:\\temp\\resumes\\";
$FileName = $officer_pr . "_" . $inc_number . ".html";
$ResumeFile = $FilePath . $FileName; 

$to = $fname . "." . $lname . "@tucsonaz.gov";
$from = $fname . "." . $lname;
$subject = $head_division . " Divsional Resume (Test)";

$bound_text = "jacquie1003"; 
$bound = "--".$bound_text."\r\n"; 
$bound_last = "--".$bound_text."--\r\n"; 

$header ="From: " . $from . "@tucsonaz.gov" . "\r\n";  
$header .="MIME-Version: 1.0\r\n";
$header .="Content-Type: multipart/mixed; boundary=\"$bound_text\"";
$message = "If you can see this MIME then your client doesn't accept MIME types!\r\n"
.nl2br($message)
.$bound;

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."Please see the attached resume file.<br /><br />"
."<strong><u>Incident Summary</u></strong><br />"
."<strong>Case Number:</strong> " . $inc_number . "<br />"
."<strong>Category:</strong> " . $category . "<br />"
."<strong>UCR:</strong> " . $ucr . "<br />"
."<strong>Location:</strong> " . $inc_street . "<br />"
."<strong>Date:</strong> " . $inc_date . "<br />"
."<strong>Time:</strong> " . $inc_time . "<br />"
."<strong>Officer:</strong> " . $officer . "&nbsp/&nbsp" . $officer_pr . "<br />"
.nl2br($message)
.$bound;

$file = file_get_contents($ResumeFile);

$message .= "Content-Type: text/html; name=" . $FileName . "\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-disposition: attachment; file=" . $ResumeFile . "\r\n" 
."\r\n" 
.chunk_split(base64_encode($file))
.$bound_last;

mail($to, $subject, $message, $header);
</pre>

end mail script

Email message

Please see the attached resume file.

Incident Summary

Case Number: 0910071139

Category: Matters of Concern COT

UCR: 04.03

Location: 1310 W. Miracle Mile

Date: 10-07-09

Time: 1505

Officer: Smith / 13785

If you can see this MIME then your client doesn't accept MIME types!

--jacquie1003

End of Email

Try taking \\r\\n off your boundary. Not sure if it'll help, but I'm having a similar problem and when I add then it prints part of the attachment.

Looks to me that one problem is that you're messing with your newlines with nl2br on the message. It will insert break tags in the boundaries, content types etc. as well.

Perhaps it will be easier to do something like this to get the newlines right:

$header .= "Content...";
$file = file_get_contents($ResumeFile);

ob_start();  //buffer the output rather than send to client
?>
If you can see this MIME then your client doesn't accept MIME types!
<?php echo $bound;?>

Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Please see the attached resume file.<br>
<br>
Incident Summary<br>
<br>
Case Number: <?php echo $inc_number;?><br>
Category: <?php echo $category;?><br>
UCR: <?php echo $ucr;?><br>
Location: <?php echo $inc_street;?><br>
Date: <?php echo $inc_date;?><br>
Time: <?php echo $inc_time;?><br>
Officer: <?php echo $officer;?> / <?php echo $officer_pr;?><br>
<?php echo $bound;?>

Content-Type: text/html; name=<?php echo $FileName;?>
Content-Transfer-Encoding: base64
Content-disposition: attachment; file=<?php echo $ResumeFile;?>

<?php echo chunk_split(base64_encode($file));?>
<?php echo $bound_last;?>

<?php
$message = ob_get_flush();

You might also have to use both multipart/mixed as well as multipart/alternative as seen in this tutorial: Web Cheat Sheets

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM