I'm new here, but after surfing through many pages, I've came up with a form that actually works and sends an attachment to my email. However, when an attachment is not attached at the time the form is filled out, I get this instead of the Thank You Page.
Warning: file_get_contents(): Filename cannot be empty in /home/advem/public_html/careers.php on line 21
Warning: Cannot modify header information - headers already sent by (output started at /home/advem/public_html/careers.php:21) in /home/advem/public_html/careers.php on line 61
However, the email still gets sent to me when an attachment is not used.
Any help is greatly appreciated.
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
//Deal with the email
$to = 'email@example.com';
$subject = 'New Proof Request';
$visitor_email = $_POST['email'];
$message = strip_tags($_POST['message']);
$sku = $_POST['sku'];
$phone = $_POST['phone'];
$name = $_POST['name'];
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
echo "Name and email are mandatory!";
$headers = "From: firstname.lastname@example.org\r\nReply-To: $visitor_email";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
Content-Type: text/plain; charset=\"iso-8859-1\"