下面的PHP将附加服务器上的文件,但不允许我编辑电子邮件正文的消息输入。
<?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_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");
?>
如果我通过替换以下内容为电子邮件正文输入消息:
$email_message . "\n\n";
附件没有通过,但是消息将......以及一些乱码
--==Multipart_Boundary_xd05fe3fbc7afe814087a952a9c31f1fax Content-Type: application/octet-sdiveam; name="061711_080900_dwr.fdf" Content-Transfer-Encoding: base64 JUZERi0xLjIKJe+/ve+/ve+/ve+/vQoxIDAgb2JqCjw8IAovRkRGIDw8IC9GaWVsZHMgWyA8PC9U KFdvcmtfRGF0ZSkvVihramgpPj48PC9UKE1haW50ZW5hbmNlX0FyZWEpL1YoKT4+PDwvVChSb3V0 ZV9OdW1iZXIpL1YoKT4+PDwvVChEdWVfRGF0ZSkvVigyMDExLTA2LTE2IDIyOjI2OjAxKT4+PDwv VChSb2FkX1NlZ21lbnRfSUQpL1YoKT4+PDwvVChDcm9zc19TZWN0aW9uX1Bvc2l0aW9uKS9WKCk+ Pjw8L1QoTG9jYWxfTmFtZSkvVigpPj48PC9UKEZhY2lsaXR5X05hbWUpL1YoKT4+PDwvVChGYWNp bGl0eV9BZGRyZXNzKS9WKCk+Pl0gCi9GIChodHRwOi8vY2FnZWRuYXRpb24uY29tL2pjcy9waHAv ZHdyX2Zvcm0ucGRmKSAvSUQgWyA8ZjIxODgyZTJmOGQxOGJjYjY5OGRhYzlmNTllNzIwYWM+Cl0g Pj4gCj4+IAplbmRvYmoKdHJhaWxlcgo8PAovUm9vdCAxIDAgUiAKCj4+CiUlRU9GCg==
我想在电子邮件中加入一个评论和备注的正文。
答案 0 :(得分:1)
为什么不使用邮件程序库?其中有很多,例如Swiftmailer,PHPMailer或Zend_Mail。你可以省去处理电子邮件细节的麻烦。
答案 1 :(得分:0)
您是否尝试使用\ r \ n?
结束标题