PHP警告:mail():在additional_header中找到多个或格式错误的换行符

时间:2015-09-16 23:20:53

标签: php malformed

直到几天联系表单工作正常,但现在它给了我这个错误:PHP警告:mail():在additional_header中找到多个或格式错误的换行符

我正在尽力找到解决方案,但我迷失了方向。感谢任何帮助。

以下是代码:

    <?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_phone = $_POST['phone'];
$strMessage = nl2br($_POST["message"]);

$mail_to = 'info@websiteurl';
$subject = 'websiteurl.es - '.$field_name;



$srMessage=" --- Nombre: {$field_name}
 --- Telefono: {$field_phone}
 --- Email: {$field_email} ---";

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

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$headers .= 'Telefono: '.$field_phone."\r\n";

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

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

//*** Attachment ***//
    if($_FILES["fileAttach"]["name"] != "")
    {
        $strFilesName = $_FILES["fileAttach"]["name"];
        $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
        $headers .= "--".$strSid."\n";
        $headers .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
        $headers .= "Content-Transfer-Encoding: base64\n";
        $headers .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
        $headers .= $strContent."\n\n";
    }

$mail_status = mail($mail_to, $subject, $sMessage, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Gracias por contactar con nosotros. Le responderemos con la mayor brevedad posible!');
        window.location = 'index.htm';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Error! Envio de mensaje fallido, por favor envie un email a info@websiteurl.es');
        window.location = 'index.htm';
    </script>
<?php
}
?>

0 个答案:

没有答案