lisawebs Posted September 4, 2007 Share Posted September 4, 2007 Particularly Hotmail seems to dislike messages sent through mail() Is there any other procedure to sent emails through php? What kind of info we could place in the headers for msgs to be accepted. Can we remove the x-PHP info placed on msg headers (in case this is the main reason for servers discard the msg) Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/ Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 try these headers: <?php $headers = 'From: ' . $from . "\n"; $headers .= 'To: ' . $to . "\n"; $headers .= 'Return-Path: ' . $from . "\n"; $headers .= 'MIME-Version: 1.0' ."\n"; $headers .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '"' . "\n\n"; $headers .= $body_simple . "\n"; $headers .= '--' . $boundary . "\n"; $headers .= 'Content-Type: text/plain; charset=ISO-8859-1' ."\n"; $headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n"; $headers .= $body_plain . "\n"; $headers .= '--' . $boundary . "\n"; $headers .= 'Content-Type: text/HTML; charset=ISO-8859-1' ."\n"; $headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n"; $headers .= $body_html . "\n"; $headers .= '--' . $boundary . "--\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341628 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 <?php $boundary = md5(uniqid(time())); $mailOk=mail('', $subject,'', $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341644 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 <?php // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n"; $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n"; $headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n"; ?> Can we remove the x-PHP info placed on msg headers ? Yes you can remove it. Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341649 Share on other sites More sharing options...
brent123456 Posted September 5, 2007 Share Posted September 5, 2007 What goes into $body_simple, $body_plain and $body_html? Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341707 Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 im not sure im just going to leave it alone and hopefully she gets her problem fixed Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341710 Share on other sites More sharing options...
brent123456 Posted September 5, 2007 Share Posted September 5, 2007 Does anyone else know what goes in those variables above? That would be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341723 Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 Heres a better version of SMTP Mail: <?php function send_mail($to, $body, $subject, $fromaddress, $fromname, $attachments=false) { $eol="\r\n"; $mime_boundary=md5(time()); # Common Headers $headers .= "From: ".$fromname."<".$fromaddress.">".$eol; $headers .= "Reply-To: ".$fromname."<".$fromaddress.">".$eol; $headers .= "Return-Path: ".$fromname."<".$fromaddress.">".$eol; // these two to set reply address $headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol; $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters # Boundry for marking the split & Multitype Headers $headers .= 'MIME-Version: 1.0'.$eol.$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol; # Open the first part of the mail $msg = "--".$mime_boundary.$eol; $htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME boundary for this section # Setup for text OR html - $msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol; # Text Version $msg .= "--".$htmlalt_mime_boundary.$eol; $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= strip_tags(str_replace("<br>", "\n", substr($body, (strpos($body, "<body>")+6)))).$eol.$eol; # HTML Version $msg .= "--".$htmlalt_mime_boundary.$eol; $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= $body.$eol.$eol; //close the html/plain text alternate portion $msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol; if ($attachments !== false) { for($i=0; $i < count($attachments); $i++) { if (is_file($attachments[$i]["file"])) { # File for Attachment $file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1)); $handle=fopen($attachments[$i]["file"], 'rb'); $f_contents=fread($handle, filesize($attachments[$i]["file"])); $f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode(); $f_type=filetype($attachments[$i]["file"]); fclose($handle); # Attachment $msg .= "--".$mime_boundary.$eol; $msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol; // sometimes i have to send MS Word, use 'msword' instead of 'pdf' $msg .= "Content-Transfer-Encoding: base64".$eol; $msg .= "Content-Description: ".$file_name.$eol; $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !! $msg .= $f_contents.$eol.$eol; } } } # Finished $msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection. # SEND THE EMAIL ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used ! $mail_sent = mail($to, $subject, $msg, $headers); ini_restore(sendmail_from); return $mail_sent; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341729 Share on other sites More sharing options...
Yesideez Posted September 5, 2007 Share Posted September 5, 2007 At a guess I think $body in general contains the body of the email - the extention refers to the email in different forms like sending one email as plain, text and HTML but this is a guess. I've noticed that using very basic headers with mail() can result in mail being sent to the junk box whereas using some better header definitions prevents this. Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341731 Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 the $eol /r/n tags and the X-PHP: help prevent it from being passed into the junk filters in yahoo or hotmail. Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-341734 Share on other sites More sharing options...
brent123456 Posted September 5, 2007 Share Posted September 5, 2007 You both have been very helpful I am going to use this script. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/67966-problem-with-mail-acceptance-by-mail-servers/#findComment-342106 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.