php电子邮件表单回复

时间:2014-02-19 11:59:19

标签: php email mime-mail

尝试创建带附件的邮件表单,其中回复地址与收到的地址不同。他们接收电子邮件的工作正常但如果您决定回复它们,则会在回复电子邮件的末尾添加mime-version。 (例如: email@gmail.commime-version ) 请参阅下面的代码。

<?php

// Email address to which you want to send email
$to = $_POST["gut"];


$subject = $_POST["fieldSubject"];
$message = nl2br($_POST["fieldDescription"]);

/*********Creating Uniqid Session*******/

$txtSid = md5(uniqid(time()));

$headers = "";
$headers .= "From: ".$_POST["fieldFormName"]."<".$_POST["fieldFormus"].">\nReply-To: ".$_POST["fieldFormEmail"]."";

$headers .= "MIME-Version: 1.0" . "\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$txtSid."\"\n\n";
$headers .= "This is a multi-part message in MIME format.\n";

$headers .= "--".$txtSid."\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: 7bit\n\n";
$headers .= $message."\n\n";

/***********Email Attachment************/
if($_FILES["attachment"]["name"] != "")
{
    $txtFilesName = $_FILES["attachment"]["name"];

    $txtContent = chunk_split(base64_encode(file_get_contents($_FILES["attachment"]["tmp_name"]))); 
    $headers .= "--".$txtSid."\n";
    $headers .= "Content-Type: application/octet-stream; name=\"".$txtFilesName."\"\n"; 
    $headers .= "Content-Transfer-Encoding: base64\n";
    $headers .= "Content-Disposition: attachment; filename=\"".$txtFilesName."\"\n\n";
    $headers .= $txtContent."\n\n";
}

// @ is for skiping Errors //
$flgSend = @mail($to,$subject,null,$headers);  

if($flgSend)
{
    echo 'Your email as being sent successFully.';
}
else

{    ?&GT;

1 个答案:

答案 0 :(得分:1)

如果更改会发生什么:

$headers .= "From: ".$_POST["fieldFormName"]."<".$_POST["fieldFormus"].">\nReply-To: ".$_POST["fieldFormEmail"]."";

$headers .= "From: ".$_POST["fieldFormName"]."<".$_POST["fieldFormus"].">\nReply-To: ".$_POST["fieldFormEmail"]."\n";

注意该行末尾的\ n。