我使用以下PHP通过电子邮件发送表单。除Microsoft Outlook之外的所有电子邮件客户端都会看到提交的图像附件根据我的阅读,似乎Microsoft Outlook要求在此代码中的某处使用\ r \ n或PHP_EOL。或者它可能需要在ob_start部分中回车。如果这实际上是问题,我不知道我应该在哪里对此代码进行更改。在回答这个问题时,如果可以请使用此代码来解释您的答案 - 我将非常感激。非常感谢你。
$strSid = md5(uniqid(time()));
/* Set e-mail recipient */
$Receiver = "someone@something.com";
$Subject = 'Form Name';
/* Check all form inputs using check_input function */
$Name = check_input($_POST['Name'], "Please enter your name.");
$EmailAddress = check_input($_POST['EmailAddress'], "Please enter your email address.");
$PhoneNumber = check_input($_POST['PhoneNumber'], "Please enter your phone number.");
$Age = check_input($_POST['Age'], "Please enter your age.");
$Comments = check_input($_POST['Comments'], "Please enter your comments.");
$Experience = check_input($_POST['Experience'], "Please enter your experience.");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $EmailAddress))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
/* put priority here using Headers */
$Headers .= "From: someone@something.com\r\n";
$Headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$strSid."\"\r\n";
$filename = $_FILES["uploaded_file"]["name"];
$filesize = filesize($_FILES["uploaded_file"]["tmp_name"]);
$data = chunk_split(base64_encode(file_get_contents($_FILES["uploaded_file"]["tmp_name"])));
/* Picture Data and File Size is retrieved from tmp_name */
ob_start();
echo "
--PHP-mixed-$strSid
Content-Type: multipart/alternative; boundary=\"PHP-alt-$strSid\"
--PHP-alt-$strSid
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit
Name: $Name
E-mail: $EmailAddress
Phone Number: $PhoneNumber
Age: $Age
Comments: $Comments
Experience: $Experience
--PHP-alt-$strSid
--PHP-mixed-$strSid
Content-Type: application/octet-stream; name=$filename
Content-Description: $filename
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=$filename size=$filesize
$data
--PHP-mixed-$strSid--
";
/* Do not remove space before $data required */
$Message = ob_get_clean();
/* Send the message using mail() function */
mail($Receiver, $Subject, $Message, $Headers);
答案 0 :(得分:1)
我发现问题的答案是稍微修改$ Headers,如下所示:
$Headers = "From: someone@something.com\r\n";
$Headers .= "MIME-Version: 1.0\r\n";
$Headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-" . $strSid . "\"\r\n";
我还必须在第二个--PHP-alt- $ strSid中添加两个破折号,如下所示:
--PHP-alt-$strSid--
我还必须更改Content-Disposition:attachment; filename = $ filename size = $ filesize to:
Content-Disposition: attachment; filename=$filename
现在,Outlook和所有其他电子邮件客户端都使用HTML和附件正确地解释了电子邮件。