I've tried searching the forums, I have found that some other people have been having the same issue as me, but haven't found a solution that works yet.
I am creating a portal where the customer enters their information in the form and uploads an image, which is then sent as an attachment to the email.
I am finding that when I use the PHP mail() function, it is sending duplicate emails, one with the POST data, and one without. I am only calling the function once, and as far as I can tell I am only loading the page once.
Here is my code:
//recipient address (made up but you get the idea)
$to = 'sales@skycommunications.net';
//subject of email
$subject = 'Phone Order from Online Portal';
//create body of message
$message = "An order has been placed using the Portal.
";
$message .= "The order details are as follows:
";
$message .= "
";
$message .= "First Name: ".$_POST["firstname"]."
";
$message .= "Last Name: ".$_POST["lastname"]."
";
$message .= "Phone Number: ".$_POST["phonenumber"]."
";
$message .= "Email Address: ".$_POST["emailaddress"]."
";
$message .= "
";
$message .= "Phone: " . $_POST["phone"] . "
";
$message .= "Color: " . $_POST["color"] . "
";
$message .= "Voice Plan: " . $_POST["voiceplan"] . "
";
$message .= "Data Plan: " . $_POST["dataplan"] . "
";
//get file details from previous form
$file_tmp_name = $_FILES['uploaded_file']['tmp_name'];
$file_name = $_FILES['uploaded_file']['name'];
$file_size = $_FILES['uploaded_file']['size'];
$file_type = $_FILES['uploaded_file']['type'];
//read from the uploaded file & base64_encode content for the mail
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
//random number for headers
$boundary = md5("sanwebe");
//create the headers
$headers = "MIME-Version: 1.0
";
$headers .= "From: noreply@skycommunications.net
";
$headers .= "Reply-To: noreply@skycommunications.net
";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary
";
//plain text info
$body = "--$boundary
";
$body .= "Content-Type: text/plain; charset=ISO-8859-1
";
$body .= "Content-Transfer-Encoding: base64
";
$body .= chunk_split(base64_encode($message));
//attachment info
$body .= "--$boundary
";
$body .="Content-Type: $file_type; name='$file_name'
";
$body .="Content-Disposition: attachment; filename='$file_name'
";
$body .="Content-Transfer-Encoding: base64
";
$body .="X-Attachment-Id: ".rand(1000,99999)."
";
$body .= $encoded_content;
//send the email
mail($to, $subject, $body, $headers);
Everything works beautifully except for the fact that it sends one email complete with the information and attachment, another with no information from POST and a 0kb attachment. Any ideas? Is it a problem with the server possibly?