CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 problem with email from app

Print topic Send  topic

Author Message
mike
Posted: 07/30/2009, 12:15 AM

I'm using the folloing code to send a email when a user registers on our
site.

But some email clients won't display properly - google mail is OK but
hotmail (and others) won't show the link properly

$to_email= $users->email->GetValue();
$from_name="admin@mydomain.com";
$from_email="admin@mydomain.com";
$headers = "From: ".$from_name."<".$from_email.">;\r\n";
$headers .= "Content-Type: text/html";
$subject = "New User Registeration Email";
$message = "Registeration information.";
$message .= "<br><br>Thank-you for registering at MyDomain.";
$message .= "<br>You must go to the following link to complete the
registeration process.";
$message .=
"<br><br>http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["SCRIPT_NAME"])."/verify.php?id=".session_id();
$message .= "<br><br>Once you have clicked on the above link your account
will be verified and you may log in.<br>";
$message .= "<br>";
mail ($to_email,$subject,$message,$headers);

Script otherwise works ok.


Gena

Posts: 591
Posted: 07/30/2009, 2:37 AM

you try to send HTML type email. Some email clients understands this kind of email some other doesn't. To be correct in anyway you need to use boundary separator..

try following function:

  
function send_email($to, $fromaddr, $fromname, $subject, $message_text, $message_html = "")   
{   
  $subject = preg_replace("/\nfrom\:.*?\n/i", "", $subject);   
  $subject = preg_replace("/\nbcc\:.*?\n/i", "", $subject);   
  $subject = preg_replace("/\ncc\:.*?\n/i", "", $subject);   
  $message_text = preg_replace("/\nfrom\:.*?\n/i", "", $message_text);   
  $message_text = preg_replace("/\nbcc\:.*?\n/i", "", $message_text);   
  $message_text = preg_replace("/\ncc\:.*?\n/i", "", $message_text);   
  $message_html = preg_replace("/\nfrom\:.*?\n/i", "", $message_html);   
  $message_html = preg_replace("/\nbcc\:.*?\n/i", "", $message_html);   
  $message_html = preg_replace("/\ncc\:.*?\n/i", "", $message_html);   
  
  // create additional_parameters - this ensures that the RETURN-PATH will be properly set   
  // saving the mail from being rejected by the destination mail server as spam   
  // known servers that reject if RETURN-PATH domain does not match the from domain include   
  // gmail, hotmail, aol, excite, yahoo, btinternet   
  // most spam killers will also regard emails with   
  $additional_parameters = "-f $fromaddr";   
  
  // create additional_headers   
  $headers = "From: $fromname <$fromaddr>\r\n";   
  
  // specify MIME version 1.0   
  $headers .= "MIME-Version: 1.0\r\n";   
  
  // deal with html messages   
  if($message_html != "")   
  {   
   // unique boundary   
   $boundary =  md5(uniqid(time()));  //uniqid("sometext");   
  
   // tell e-mail client this e-mail contains alternate versions   
   $headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n\r\n";   
  
   // plain text version of message   
   $body  = "--$boundary\r\n";   
   $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";   
   $body .= "Content-Transfer-Encoding: 7 bit\r\n\r\n";   
   $body .= $message_text."\r\n\r\n";   
  
   // HTML version of message   
   $body .= "--$boundary\r\n";   
   $body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";   
   $body .= "Content-Transfer-Encoding: 7 bit\r\n\r\n";   
   $body .= $message_html."\r\n\r\n";   
  }   
  
  // deal with plain text only messages   
  if($message_html == "")   
  {   
   // tell e-mail client the content type   
     $headers .= "Content-type: text/plain; charset=iso-8859-1\n";   
  
   // the plain text message   
   $body = $message_text;   
  }   
  
  // send message   
  return mail($to, $subject, $body, $headers, $additional_parameters);   
}   

then you set all variable and send you email like

send_email($to, $from, $fromname, $subject, $message_text, $message_html);
_________________
Gena
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.