PHP,电子邮件附件与表单元素不起作用

时间:2013-03-05 20:01:04

标签: forms php

我知道这已被覆盖了100次,但我似乎仍无法找到正确的方法来实现这一目标。有时这段代码会起作用并发送带附件的电子邮件,有时附件会通过,有时它根本不会发送。我已经尝试了PHPMailer(),当我附加一些身体不会发送的东西时,附件也不会通过。尝试swiftmailer和附件将无法正常工作。也许这是我的服务器IPage?不确定我是否需要在php.ini文件中更改某些内容。但这就是我所拥有的,也许我错过了一些东西

    if($category == 'music' || $category == 'sports'){
  $to[1] = 'post@tweetymail.com';
  $to[2] = '1234567890@tumblr.com';
  $to[3] = 'website.1234567890@blogger.com';
}

  $soc_post = substr($post,0,139);



  $subject[1] = $title;
  $subject[2] = 'Website - ' . $title;
  $subject[3] = 'Site - ' . $title;

       $message[1] = '';
  $message[2] = $url_field . ' ' . str_replace("rnrn"," ",$soc_post);
  $message[3] = '<a href="'.$url_field.'">'.$new_url. '</a> ' . str_replace("rnrn"," ",$soc_post);



for($i=1; $i<=3; $i++){

    $fileatt = $_FILES['blog_pic']['tmp_name'];
    $fileatt_type = $$_FILES['blog_pic']['type'];
    $fileatt_name = $_FILES['blog_pic']['name'];

         $email_message = $message[$i];
         $headers = "From: Website Blog <blog@website.com>";

         $file=fopen($fileatt,'rb');
         $data=fread($file,filesize($fileatt));
         fclose($file);

         $semi_rand=md5(time());
         $mime_boundary ="==Multipart_Boundary_x{$semi_rand}x";

         $headers .= "\nMIME-Version: 1.0\n" .
         "Content-Type: multipart/mixed;\n" .
         " boundary=\"{$mime_boundary}\"";

         $email_message="This is a multi-part message in MIME format.\n\n" .
              "--{$mime_boundary}\n" .
              "Content-Type:text/html; chartset=\"iso-8859-1\"\n" .
              "Content-Transfer-Encoding: 7bit\n\n" .
        $email_message .= "\n\n";

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

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

    mail($to[$i], $subject[$i], $email_message, $headers);          

0 个答案:

没有答案