带有多个附件的php邮件

时间:2013-07-18 17:53:22

标签: php

我想使用php基础库发送带有两个内容的邮件。

到目前为止我用这个

while($donnee = $reponse->fetch()){
$mime_boundary = md5(uniqid(time()));

$message = "message text";

$to = $donnee["MAIL"]; 
//define the subject of the email 
$subject = "title";; 
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash 
$random_hash = md5(date('r', time())); 

 // from
$header = "From : sender-mail \r\nReply-To: sender-mail \r\n";
$header .= "MIME-Version:1.0\r\n";
$header .= "Content-Type:multipart/mixed; boundary=\"{$mime_boundary}\"\r\n\r\n";

// message
$header .= "--{$mime_boundary}\r\n";
$header .= "Content-Type:text/html; charset=\"ISO-8859-1\"\r\n";
$header .= "Content-Transfer-Encoding:7bit\r\n\r\n";
$header .= "<html><head><style type=\"text/css\">body { font:10pt Arial; }</style></head><body>". str_replace("\r", "", str_replace("\n", "<br />", $message)) ."</body></html>\r\n\r\n";

// attachment
$attachments = array("../fichier/downloadable/cv.docx","../fichier/downloadable/resume.pdf");
$attachmentNames = array("Covering_Letter_Anthony_Pifarré.docx","CV_Anthony_Pifarré.pdf");
for ($i = 0; $i < count($attachments); $i++)
{
    if (!base64_decode($attachments[$i], true))
        $attachments[$i] = base64_encode($attachments[$i]);
    else
        $attachments[$i] = str_replace("\r", "", str_replace("\n", "", str_replace(" ", "+", $attachments[$i])));

    $header .= "--{$mime_boundary}\r\n";
    $header .= "Content-Type:application/octet-stream; name=\"{$attachmentNames[$i]}\"\r\n";
    $header .= "Content-Transfer-Encoding:binary\r\n";
    $header .= "Content-Disposition:attachment; filename=\"{$attachmentNames[$i]}\"\r\n";
    $header .= "{$attachments[$i]}\r\n\r\n";
}

//send the email 
mail( $to, $subject, "", $header );

$requ = 'UPDATE mailing_list SET ALREADY_SENT = 1 WHERE ID = "'.$donnee["ID"].'"';
//$bdd->exec($requ);

echo "<br/>"."Sent To : ".$donnee["MAIL"];
$counter++;}

这会向我发送一封包含正确短信的电子邮件,好的发件人联系NAME就可以了。 但是atachments是空的。我有两个正确名称但权重为0ko的文件。 当我尝试写$ attachements [$ i]时,得到了一些文字,而不是什么。

有什么想法吗?

0 个答案:

没有答案