PHP邮件多次附加 [英] PHP mail multiple attach

查看:173
本文介绍了PHP邮件多次附加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这个代码发送多个附件:

I writte this code to send multiple attachments:

    $tablica_plikow=$_FILES["file"]; //array of files
if(!empty($tablica_plikow['name'])){///if attachment 
          $uid = md5(uniqid(time()));

    $header =  "From: od\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";

    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/html; charset=iso-8859-2\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .=win2iso( $_POST['tresc'])."\r\n\r\n\r\n\r\n\r\n\r\n";///message
    $header .= "--".$uid."\r\n";

    for($i=0; $i<count($tablica_plikow['name']); $i++){

    if ($tablica_plikow["error"][$i] > 0)
    { $komunikat = "<img src=\"img_panel/bttn_error.gif\">"."Return Code: " . $tablica_plikow["error"][$i] ;


    }
    if (file_exists("zalacznik/" . $tablica_plikow["name"][$i]))
      {

      $komunikat = "<img src=\"img_panel/bttn_error.gif\">"."Return Code: " . $tablica_plikow["name"][$i]. " already exists. " ;

      }
    else
      {
        if(is_uploaded_file($tablica_plikow["tmp_name"][$i])) { 
    move_uploaded_file($tablica_plikow["tmp_name"][$i],
    "zalacznik/" . $tablica_plikow["name"][$i]);
    $komunikat = "<img src=\"img_panel/bttn_info.gif\">" . "zalacznik/" . $tablica_plikow["name"][$i];

    $target_path="zalacznik/" . $tablica_plikow["name"][$i];
    $file = "zalacznik/".$tablica_plikow["name"][$i];
    $file_size = filesize($file);
    $handle = fopen($file, "rb");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $name = basename($file);
    $header .= "Content-Type: ".$tablica_plikow["type"][$i]." name=\"".$tablica_plikow["name"][$i]."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\n\r".$content."\r\n\r\n";;
    $header .= "Content-Disposition: attachment; filename=\"".$tablica_plikow["name"][$i]."\"\r\n\r\n";
   // $header .= $content."\r\n\r\n";
    $header .= "--".$uid."-- \r\n";

            }
        }
    }
     if (mail("mail@moj.com", $_POST['tytul'], "", $header)) {

         $komunikat = "<img src=\"img_panel/bttn_info.gif\">mail send";


    } else {
      $komunikat = "<img src=\"img_panel/bttn_error.gif\">error";

      }

但是当我发送一封包含两个或更多附件的电子邮件时,只收到一个文件。该文件是所有附件的连接。但是文件的第一部分是第一个附件,其他部分只是hashmap其他文件。

But when I send an email with two or more attachments, receive only one file.This file is a concatenation of all attachments. But the first part of the file is the first attachment, and other parts are just hashmap other files.

推荐答案

我建议你使用标准和测试的邮件库,如phpMail

I advice you use standard and tested mailing lib such as phpMail

以前已经讨论过,请参阅关于电子邮件附件在php

It has been discussed here before Please see regarding email with attachment in php

谢谢

:)

这篇关于PHP邮件多次附加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆