Hi Eveyone,
This code was working for hotmail, googlemail and SquirrelMail but sometime in the last few weeks the code has stopped working for hotmail.
The mail doesn't even arrive (i've checked junk folders) and I don't get a delivery failure email to my host account's email address.
Do you know what may be wrong with it?
Thanks!
Stu
<?php
###############
//callback function for the regex (if not already called in another module)
if ($function_utf8_entity_decode_used != 'yes')
{
function utf8_entity_decode($entity)
{
$convmap = array(0x0, 0x10000, 0, 0xfffff);
return mb_decode_numericentity($entity, $convmap, 'UTF-8');
}
$function_utf8_entity_decode_used = 'yes';
}
#################
# put in security checks to ensure no spamming / hijack / unreasonable repeat applications
if ( 1 == 1)
{
// we'll begin by assigning the To address and message subject
$to = $_POST['email_to'];
$subject = $_POST['subject'];
// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['email_from']).">";
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// store the file information to variables for easier access
$tmp_name = $_FILES['FILE1']['tmp_name'];
# # TEST
# echo "<br>_FILES['FILE1']['tmp_name'] is {$_FILES[FILE1][tmp_name]}";
# echo "<br>_FILES['FILE1'] is {$_FILES[FILE1]}";
# echo "<br>_FILES['FILE1']['name'] is {$_FILES[FILE1][name]}";
$type = $_FILES['FILE1']['type'];
$name = $_FILES['FILE1']['name'];
####
//decode decimal HTML entities added by web browser
$name = preg_replace('/&#\d{2,5};/ue', "utf8_entity_decode('$0')", $name );
//decode hex HTML entities added by web browser
$name = preg_replace('/&#x([a-fA-F0-7]{2,8});/ue', "utf8_entity_decode('&#'.hexdec('$1').';')", $name );
####
$name_base64 = base64_encode($name);
# insert notation required for header including character set
# backup
# $name_base64 = "=?UTF-8?B?" . $name_base64 . "?=\r\n";
$name_base64 = "=?UTF-8?B?" . $name_base64 . "?=";
# # TEST
# echo "<br>name_base64 is $name_base64<br>";
$size = $_FILES['FILE1']['size'];
// here we'll hard code a text message
// again, in reality, you'll normally get this from the form submission
$message = $_POST['comments'];
# set the email's line length to 70 characters
$message = wordwrap($message, 70);
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name))
{
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
# backup
# "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Type: text/plain; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
###
###
// if the upload succeded, the file will exist
if (file_exists($tmp_name))
{
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: $type\n" .
"Content-Transfer-Encoding: base64\n" .
# backup
# //"Content-Disposition: attachment;\n" .
"Content-Disposition: attachment;\n" .
# backup
# //" filename=\"{$fileatt_name}\"\n" .
# backup2
# " filename=\"$name_base64\"\n" .
" filename=\"$name_base64\"" . "\n\n" .
# backup
# " name=\"{$name_base64}\"\n" .
# not required at all?
# " name=$name_base64\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
####
####
// now we just send the message
if (@mail($to, $subject, $message, $headers))
{
# TEST
# echo "<br>Message Sent<br>";
$email_status = "sent";
}
else
{
# TEST
# echo "<br>Failed to send<br>";
$email_status = "not sent";
}
}
?>