I've put together an HTML form a which sends its input to itself and proceeds to send an email with the form contents and an attached file. I took the accepted answer from this post and tried to integrate it into my form. However, my code is completing without errors but I don't get an email. Here is part of it:
<?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 = 'testing@example.com';
$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: webmaster@example.com\r\nReply-To: webmaster@example.com";
$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'); ?>
The form isn't 100% complete, if you're wondering about the missing inputs.