我想寄出兩附件,但只寄出第一附件
第一附件是text
第二附件是pdf
希望可幫忙解決
<?php
$mail_to = "xx";
$from_mail = "a@a.com";
$from_name = "a";
$reply_to = "a@a.com";
$subject = "xx";
$message = "None";
/* Attachment File */
// Attachment location
$file_name1 = "textFile.txt";
// Read the file content
$file1 = $file_name1;
$file_size1 = filesize($file1);
$handle1 = fopen($file1, "r");
$content1 = fread($handle1, $file_size1);
fclose($handle1);
$content1 = chunk_split(base64_encode($content1));
// Attachment location
$file_name2 = "textFile.pdf";
// Read the file content
$file2 = $file_name2;
$file_size2 = filesize($file2);
$handle2 = fopen($file2, "r");
$content2 = fread($handle2, $file_size2);
fclose($handle2);
$content2 = chunk_split(base64_encode($content2));
/* Set the email header */
// Generate a boundary
$boundary = md5(uniqid(time()));
// Email header
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$reply_to."\r\n";
$header .= "MIME-Version: 1.0\r\n";
// Multipart wraps the Email Content and Attachment
$header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$boundary."\r\n";
// Email content
// Content-type can be text/plain or text/html
$header .= "Content-type:text/plain; charset=big5\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= "$message\r\n";
$header .= "--".$boundary."\r\n";
// Attachment
$header .= "Content-Type: text/plain; name=\"".$file_name1."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name1."\"\r\n\r\n";
$header .= $content1."\r\n";
$header .= "--".$boundary."--";
$header .= "Content-Type: application/pdf; name=\"".$file_name2."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name2."\"\r\n\r\n";
$header .= $content2."\r\n";
$header .= "--".$boundary."--";
// Send email
if (mail($mail_to, $subject, "", $header)) {
echo "Sent";
} else {
echo "Error";
}
?>