1

我有发送带有多个附件的邮件的代码。当我提交邮件时,文件附在邮件中...购买我的短信不会出现在邮件中(我的邮件:xxxxxxx)

$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
$phone =  $_POST["phone"];
$address =  $_POST["address"];
$freetext = $_POST["freetext"];
    /////

$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

     $headers = "From: '".$email."'\r\n" .
     "MIME-Version: 1.0\r\n" .
        "Content-Type: multipart/mixed; charset=utf-8 ; boundary=$sep\n" .
        " boundary=\"{$mime_boundary}\"";

     $message = "xxxxxx" .
        "--{$mime_boundary}\n" .
        "Content-Type: text/html; charset=utf-8\n\n" .
        "Content-Transfer-Encoding: 7bit\n\n" .
         "\n\n";

     foreach($_FILES as $userfile)
     {
        $tmp_name = $userfile['tmp_name'];
        $type = $userfile['type'];
        $name = $userfile['name'];
        $size = $userfile['size'];

        if (file_exists($tmp_name))
        {
           if(is_uploaded_file($tmp_name))
           {
              $file = fopen($tmp_name,'rb');

              $data = fread($file,filesize($tmp_name));

              fclose($file);

              $data = chunk_split(base64_encode($data));
           }

           $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$type};\n" .
              " name=\"{$name}\"\n" .
              "Content-Disposition: attachment;\n" .
              " filename=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
           $data . "\n\n";
        }
     }

     $message .="--{$mime_boundary}--\n";

if (mail($support, $txt_new_member, $message, $headers)) echo "邮件发送成功。"; 否则回显“邮件错误”;

请问有什么帮助吗?

4

1 回答 1

1

我推荐你使用 PHP Mailer - http://sourceforge.net/projects/phpmailer/

于 2012-09-11T09:59:17.440 回答