我有以下代码来发送带有附件的邮件,并且我在调整它以发送2个附件而不是1个附件时遇到了问题。我需要发送一个.docx和一个.pdf
你知道我应该修改什么吗?
function mail_attachment($filename1, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "Content-Type: application/msword; name=\"".$filename."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
mail($mailto, $subject, "", $header);
}
我是这么称呼它的..。
mail_attachment("attachment.docx", "","recipient@mail.com","admin@mail.com","Admin","admin@mail.com","Subject","Mail body");
发布于 2012-10-23 23:09:55
我推荐你使用PHPMailer -一个稳定的库,它很容易使用,可以做你所有的工作!http://code.google.com/a/apache-extras.org/p/phpmailer/
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddAddress("email@example.com");
$mail->Subject = "Test 1";
$mail->Body = "Test 1 of PHPMailer.";
您将能够在一个字符串中添加附件:
$mail->AddAttachment('/home/mywebsite/public_html/file1.zip', 'file1.zip');
$mail->AddAttachment('/home/mywebsite/public_html/file2.zip', 'file2.zip');
它更容易,也更灵活。不要做猴子的工作。已经为您完成了!
程序员一定很懒!键入较少的代码)
https://stackoverflow.com/questions/13033515
复制相似问题