0

我知道这已经被覆盖了 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);          
4

0 回答 0