发送带附件的邮件

时间:2012-09-11 09:56:11

标签: php email attachment

我有代码发送带有多个附件的邮件.. 当我提交邮件时,文件附在邮件中...买我的短信没有出现在邮件中(我的留言: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()) “×”;

     $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“邮件发送成功。”; 其他    echo“邮件错误”;

有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

我建议您使用PHP Mailer - http://sourceforge.net/projects/phpmailer/