尝试仅使用 PHP 来完成此操作,我遇到了一个障碍,电子邮件中的 HTML 很好,但这些boundary
部分显示为普通文本,附件不会附加。
$to = 'myemail@email.com';
$subject = 'Contact Submission';
$name = strip_tags($_POST['name']);
$emailto = strip_tags($_POST['emailto']);
$comments = strip_tags($_POST['comments']);
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: noreply@emailcom' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$comments="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/html; charset=ISO-8859-1\"
Content-Transfer-Encoding: 7bit
<table width=\"600px\" cellpadding=\"0\" cellspacing=\"0\"style=\"\">
<tr valign=\"top\">
<th align=\"left\" style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:14px; padding-left:10px; line-height:32px\">Contact Submission</th>
</tr>
</table>
<br />
<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\"style=\"border: 1px solid #000;\">
<tr valign=\"top\">
<td colspan=\"4\" style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; border-bottom: 1px solid #000;background:#ececec; line-height:32px;\" align=\"left\"><strong>Contact Information</strong></td>
</tr>
<tr valign=\"top\">
<td style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px; font-weight:bold\" align=\"right\" width=\"120\">Name</td>
<td style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px;padding-left:40px;\">$name</td>
</tr>
<tr valign=\"top\">
<td style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px; font-weight:bold; background:#e6edf2;\" align=\"right\" width=\"120\">Email</td>
<td style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px;background:#e6edf2;padding-left:40px;\">$emailto</td>
</tr>
<tr valign=\"top\">
<td style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px; font-weight:bold\" align=\"right\">Comments</td>
<td style=\" font-family:Verdana, Geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px;padding-left:40px;\" colspan=\"3\">$comments</td>
</tr>
</table>
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
mail($to, $subject, $comments, $headers);
对于需要更改/添加/删除什么来获取这封电子邮件以保留我的 HTML 表格并附加文件,任何人都可以提供任何帮助