我把放在一起的一个HTML表单a发送到自己的输入,然后继续发送一个带有表单内容和附加文件的电子邮件。我从this帖子中接受了答案,并尝试将其整合到我的表单中。然而,我的代码完成没有错误,但我没有收到电子邮件。这里是它的一部分:用附件发邮件的PHP脚本问题(没有库)
<?php
if(isset($_POST['submit2']))
{
//The form has been submitted, prep a nice thank you message
$output = '<h1>Thanks for your file and message!</h1>';
//Set the form flag to no display (cheap way!)
$flags = 'style="display:none;"';
//Deal with the email
$to = '[email protected]';
$subject = 'Article Submission';
$message = $_POST['name'].'\n'.$_POST['email'].'\n\n'.$_POST['title'].'\n'.$_POST['remarks'];
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From: [email protected]\r\nReply-To: [email protected]";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
mail($to, $subject, $message, $headers);
}
?>
<h2> Article Submission </h2>
(*) Required Fields<br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<table>
<tr>
<td> Name </td>
<td> <input type="text" name="name" size="30"> * </td>
</tr>
<tr>
<td> Email </td>
<td> <input type="text" name="email" size="30"> * </td>
</tr>
<tr> <td> </td><td> </td> </tr>
<tr>
<td> Title of Article </td>
<td> <input type="text" name="title" size="40"> * </td>
</tr>
<tr>
<td> Program </td>
<td></td>
</tr>
<tr>
<td> Course </td>
<td> </td>
</tr>
<tr>
<td> File </td>
<td> <input type="file" name="file" id="file"> </td>
</tr>
<tr> <td> </td><td> </td> </tr>
<tr>
<td valign="top"> Remarks </td>
<td> <textarea rows="6" cols="40" name="remarks"> </textarea>
</tr>
<tr>
<td> <input type="submit" name="submit2" value="Submit" id="submit"> </td>
</tr>
</table>
</form>
</div>
<?php include('include/main_footer.php'); ?>
如果你想知道缺少的输入,表格不是100%完整的。
您根本没有收到邮件,或者收到邮件,但附件不正确?因为这是两个截然不同的问题。 – Ariel
我什么都没有得到。甚至没有电子邮件。 – n0pe
在这种情况下,简化 - 摆脱所有的MIME的东西,只是发送一个简单的电子邮件,并让第一次工作。虽然列出了没有错误或日志文件,但我无法帮助。 – Ariel