Hi there,
I am having trouble with a php mail attachment. I have never done this before. I have got to the point where the script sends a blank message with a title... but no attachment and no body of the email is seen. I have opened up the email as a text document and can see the output is all there (so it has sent it). So there must be a syntax error where the mail content-code info stuff is concerned?
Anyway, after hours and hours, I can't figure it out. Is there anyone who could help me out please?
Here is the code I have:
if(isset($_POST['submit_x']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$drawingName = $_POST['drawingName'];
$tempFile = $_FILES['attachment']['tmp_name']; //set name variable
$filename = $_FILES['attachment']['name']; //set name variable
$emailStatus = validate_email($email);
if($name=="" || $email=="" || $drawingName=="" ||$name=="Your Name" || $email=="Your Email" || $drawingName=="Give your Drawing a Name")
{
header("location:competition.php?message=blank");
exit();
}
if($emailStatus==false)
{
header("location:competition.php?message=email");
exit();
}
if($tempFile=="")
{
header("location:competition.php?message=nofile");
exit();
}
if ((($_FILES["attachment"]["type"] == "image/gif")
|| ($_FILES["attachment"]["type"] == "image/png")
|| ($_FILES["attachment"]["type"] == "image/jpeg")
|| ($_FILES["attachment"]["type"] == "image/pjpeg"))
&& ($_FILES["attachment"]["size"] < 20000))
{
header("location:competition.php?message=file");
exit();
}
//move file to intended folder
$fileType = $_FILES["attachment"]["type"];
$fullFileLocation = "tempuploads/".$filename;
$success = move_uploaded_file($tempFile, $fullFileLocation);
$to = "help@lala.co.uk";
$subject = "A tester email";
$random_hash = md5(date('r', time()));
$headers = "From: $email\r\nReply-To: $email";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($fullFileLocation)));
$output = "--PHP-mixed-$random_hash;
Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash'
--PHP-alt-$random_hash
Content-Type: text/plain; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
Hello $name!
This is the simple text version of the email message.
--PHP-alt-$random_hash
Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is the <b>HTML</b> version of the email message.</p>
--PHP-alt-$random_hash--
--PHP-mixed-$random_hash
Content-Type: application/zip; name=$fullFileLocation
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$random_hash--";
if(mail($to, $subject, $output, $headers))
{
//unset file
if (file_exists($fullFileLocation))
{
//unset file
unset($fullFileLocation);
}
//header("location: competition.php?message=success");
exit();
}
}
(Apologies for the long code. I guess in full context it's easier to help.)
Any help would be greatly appreciated.
Cheers
Danny