stubarny Posted April 27, 2007 Share Posted April 27, 2007 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"; } } ?> Quote Link to comment Share on other sites More sharing options...
infusionstudios Posted December 9, 2007 Share Posted December 9, 2007 did you find an answer to this? Quote Link to comment Share on other sites More sharing options...
Dragen Posted December 9, 2007 Share Posted December 9, 2007 It could be a problem on microsoft's end as so many people seem to be having the same problem. Just a thought, but has anyone tried contacting them about it? It may be that they've put a filter of some sort in place. Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 9, 2007 Share Posted December 9, 2007 what advantages are there to using all that code as stated at start of topic compared to the simple validation and mailto job ? most of its forign to me like what the freak is a mimboundary and why do you send headers for this i want to know Quote Link to comment Share on other sites More sharing options...
Dragen Posted December 9, 2007 Share Posted December 9, 2007 mime boundaries are set to allow attachements, and headers are one of the fundamental parts of a mail script. They send info such as whether the email is plain text, or html. Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted December 10, 2007 Share Posted December 10, 2007 Sometimes hotmail is a little funny. Make sure its not being directed to your Junk inbox Quote Link to comment Share on other sites More sharing options...
anthrt Posted December 10, 2007 Share Posted December 10, 2007 if ( 1 == 1) { what's the point in having that in there? Quote Link to comment Share on other sites More sharing options...
Dragen Posted December 10, 2007 Share Posted December 10, 2007 if ( 1 == 1) { what's the point in having that in there? perhaps it's a safety check, just to make sure that the computer can add up We'll be checking it's 5 times tables in a minute Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 10, 2007 Share Posted December 10, 2007 Does anyone have any links to tutorials on headers. Is there anyway to stop a php script from the mail being directed to the junk box ? Quote Link to comment Share on other sites More sharing options...
Dragen Posted December 11, 2007 Share Posted December 11, 2007 Does anyone have any links to tutorials on headers. Is there anyway to stop a php script from the mail being directed to the junk box ? It's not determined by the sender whether or not the email goes into the junk box. It's up to the recipients settings. then again, on hotmail, just about everything goes into junk unless the senders email address is in their address book. I'd suggest asking the recipient to add your email address to the contacts. Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 11, 2007 Share Posted December 11, 2007 Does anyone have any links to tutorials on headers. Is there anyway to stop a php script from the mail being directed to the junk box ? It's not determined by the sender whether or not the email goes into the junk box. It's up to the recipients settings. then again, on hotmail, just about everything goes into junk unless the senders email address is in their address book. I'd suggest asking the recipient to add your email address to the contacts. Do sites like facebook use a different method of seding email as it doesn't go into my junk mail ,yet is not added to my add book Quote Link to comment Share on other sites More sharing options...
Dragen Posted December 12, 2007 Share Posted December 12, 2007 probably not. To be honest I'm not at all sure how hotmail filters what is junk and what isn't. It's probably based on several things, such as subject, content, sender, and if they're in your contacts list. Facebook and other such sites are probably not sent to junk, because they are well known as not being junk. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.