Jump to content

making php mail code work for hotmail


stubarny

Recommended Posts

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";
	}

}

?>

Link to comment
Share on other sites

  • 7 months later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.