Php 联系表格文件附件或文本内容

Php 联系表格文件附件或文本内容,php,forms,email,attachment,contact,Php,Forms,Email,Attachment,Contact,我正在尝试制作带有文件附件的联系表。我正在我没有邮件服务的域上测试它,所以每次它都返回到我的域邮件转发。所以在有邮件服务的域上它应该可以工作。它看起来像: The original message was received at Tue, 11 Feb 2014 11:53:37 +0100 from localhost.localdomain [127.0.0.1] ----- The following addresses had permanent fatal errors ---

我正在尝试制作带有文件附件的联系表。我正在我没有邮件服务的域上测试它,所以每次它都返回到我的域邮件转发。所以在有邮件服务的域上它应该可以工作。它看起来像:

The original message was received at Tue, 11 Feb 2014 11:53:37 +0100
from localhost.localdomain [127.0.0.1]

   ----- The following addresses had permanent fatal errors -----
<xxx@gmail.com>
    (reason: 550 No email services for this domain xxx.cz)

   ----- Transcript of session follows -----
... while talking to smtp.hosting90.cz:
>>> MAIL From:<mainftp52149@hz-w8.hosting90.cz> SIZE=622
<<< 550 No email services for this domain xxx.cz
554 5.0.0 Service unavailable

Final-Recipient: RFC822; xxx@gmail.com
Action: failed
Status: 5.0.0
Diagnostic-Code: SMTP; 550 No email services for this domain xxx.cz
Last-Attempt-Date: Tue, 11 Feb 2014 11:53:37 +0100
所以没关系

但是当我附加文件时,它就像

---------- Forwarded message ----------
From: mainftp52149@hz-w8.hosting90.cz
To: xxx@gmail.com
Cc: 
Date: Tue, 11 Feb 2014 12:01:29 +0100
Subject: blah
在主题下:布拉,它显示了附件[图像],但没有一节与来自,姓名,命运,经验和性别。。。有没有办法解决这个问题?我两样都要。。那一节有名字和blahblah,还有附件

这是我的php代码

<?php
        $username = $_POST['username'];
        $name = $_POST['name'];
        $destination = $_POST['destination'];
        $experience = $_POST['experience'];
        $sex = $_POST['sex'];
        $from = 'From:xxx@gmail.com'; 
        $to = 'xxx@gmail.com'; 
        $subject = 'blah';
        $human = $_POST['human'];

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

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

        $headers = "";

        $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";

        /***********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";
        }


        $body = "From: $username\n name: $name\n Destination: $destination\n experience: $experience\n sex: $sex\n";

        {                
            if (mail($to, $subject, $body, $headers )) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        } 
        } 
    ?>

可能是因为您通过应用程序/八位字节流覆盖了内容类型,所以不会显示正文?有任何具体说明如何解决此问题吗?我刚刚尝试了两种方法,但都无效。您是否尝试过使用Content-Type:multipart/alternative?
<?php
        $username = $_POST['username'];
        $name = $_POST['name'];
        $destination = $_POST['destination'];
        $experience = $_POST['experience'];
        $sex = $_POST['sex'];
        $from = 'From:xxx@gmail.com'; 
        $to = 'xxx@gmail.com'; 
        $subject = 'blah';
        $human = $_POST['human'];

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

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

        $headers = "";

        $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";

        /***********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";
        }


        $body = "From: $username\n name: $name\n Destination: $destination\n experience: $experience\n sex: $sex\n";

        {                
            if (mail($to, $subject, $body, $headers )) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        } 
        } 
    ?>