联系表单文件附件或textcontent

时间:2014-02-11 11:20:11

标签: 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 -----
<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 11:53:37 +0100
    Subject: blah

    From: 1145
     name: sadad
     Destination:france
     experience: none
     sex: male

所以没关系...

当我附加文件时就像

---------- Forwarded message ----------
From: mainftp52149@hz-w8.hosting90.cz
To: xxx@gmail.com
Cc: 
Date: Tue, 11 Feb 2014 12:01:29 +0100
Subject: blah

在主题下:它显示附件[图片],但没有FROM,NAME,DESTIANTION,EXPERIENCE和SEX的部分...任何想法如何解决这个问题?我需要同时拥有这个名称和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>'; 
        } 
        } 
    ?>

0 个答案:

没有答案