By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

Info from form shows in headers but not in body of email

P: 2
I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what I'm doing wrong?

Here is the script:
Expand|Select|Wrap|Line Numbers
  1. <? function send_mail($emailaddress, $fromaddress, $emailsubject, $body)
  2. {
  3.   $eol="\r\n";
  4.   $mime_boundary=md5(time());
  5.  
  6.   # Common Headers
  7.   $headers .= 'From: Sending Love<'.$fromaddress.'>'.$eol;
  8.   $headers .= 'Reply-To: Sending Love<'.$fromaddress.'>'.$eol;
  9.   $headers .= 'Return-Path: Sending Love<'.$fromaddress.'>'.$eol;    // these two to set reply address
  10.   $headers .= "Message-ID: <".$now." TheSystem[color=black]@[/color]".$_SERVER['SERVER_NAME'].">".$eol;
  11.   $headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters
  12.  
  13.   # Boundry for marking the split & Multitype Headers
  14.   $headers .= 'MIME-Version: 1.0'.$eol;
  15.   $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
  16.  
  17.   $msg = "";
  18.  
  19.   # Setup for text OR html
  20.   $msg .= "Content-Type: text".$eol;
  21.  
  22.   # Text Version
  23.   $msg .= "--".$mime_boundary.$eol;
  24.   $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
  25.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  26.   $msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
  27.  
  28.   # HTML Version
  29.   $msg .= "--".$mime_boundary.$eol;
  30.   $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  31.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  32.   $msg .= $body.$eol.$eol;
  33.  
  34.   # Finished
  35.   $msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.
  36.  
  37.   # SEND THE EMAIL
  38.   ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
  39.   mail($emailaddress, $emailsubject, $msg, $headers);
  40.   ini_restore(sendmail_from);
  41.   #echo "mail send";
  42. }
  43.  
  44.  
  45. # To Email Address
  46. $emailaddress="denise@REMOVED.net";
  47.  
  48. # From Email Address
  49. $fromaddress = "orders@REMOVED.ca";
  50.  
  51. # Message Subject
  52. $emailsubject="Web Customer Submission";
  53.  
  54.  
  55. #----------------------------------------------------------------
  56. # Message Body
  57. $body = $body."This is a request for service from a customer <br>";
  58. $body = $body."<b>Customer Name: </b>".$_REQUEST['cust_name']."<br>";
  59. $body = $body."<b>Address: </b>".$_REQUEST['cust_address']."<br>";
  60. $body = $body."<b>City: </b>".$_REQUEST['cust_city']."<br>";
  61. $body = $body."<b>Province/State: </b>".$_REQUEST['cust_provstate']."<br>";
  62. $body = $body."<b>Zip: </b>".$_REQUEST['cust_postzip']."<br>";
  63. $body = $body."<b>Country: </b>".$_REQUEST['cust_country']."<br>";
  64. $body = $body."<b>E-Mail: </b>".$_REQUEST['cust_email']."<br>";
  65. $body = $body."<b>Customer is Intersted in: </b>".$_REQUEST['cust_interest']."<br>";
  66. $body = $body."<b>Other Specification: </b>".$_REQUEST['cust_interest_other']."<br>";
  67. $body = $body."<b>Design Selection: </b>".$_REQUEST['design_select']."<br>";
  68. $body = $body."<b>Color Preferences: </b>".$_REQUEST['color_pref']."<br>";
  69. $body = $body."<b>Customer Pertinent Info: </b>".$_REQUEST['cust_pertinfo']."<br>";
  70. $body = $body."<b>Anything else the customer would like to see: </b>".$_REQUEST['cust_ideas']."<br>";
  71. $body = $body."<b>Things the customer doesn't want on their card: </b>".$_REQUEST['Cust_dont_want']."<br>";
  72. $body = $body."<b>Card Size: </b>".$_REQUEST['card_size']."<br>";
  73. $body = $body."<b>Card Finish: </b>".$_REQUEST['card_finish']."<br>";
  74. $body = $body."<b>Quantity: </b>".$_REQUEST['quantity']."<br>";
  75. $body = $body."<b>Can you use the finished product as a design example? : </b>".$_REQUEST['cust_permission']."<br>";
  76. $body = $body."<b>How did you find us?: </b>".$_REQUEST['found_us']."<br>";
  77.  
  78. #Add all other parts here
  79. #----------------------------------------------------------------
  80.  
  81. send_mail($emailaddress, $fromaddress, $emailsubject, $body);
  82. ?> 
  83.  
TIA for your Help!
Dec 20 '07 #1
Share this Question
Share on Google+
4 Replies


Ranjan kumar Barik
P: 95
I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what I'm doing wrong?

Here is the script:
<? function send_mail($emailaddress, $fromaddress, $emailsubject, $body)
{
$eol="\r\n";
$mime_boundary=md5(time());

# Common Headers------------------headers not declared-------------
$headers .= 'From: Sending Love<'.$fromaddress.'>'.$eol;
$headers .= 'Reply-To: Sending Love<'.$fromaddress.'>'.$eol;
$headers .= 'Return-Path: Sending Love<'.$fromaddress.'>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$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;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;

$msg = "";

# Setup for text OR html
$msg .= "Content-Type: text".$eol;

# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;

# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$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($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
#echo "mail send";
}


# To Email Address
$emailaddress="denise@REMOVED.net";

# From Email Address
$fromaddress = "orders@REMOVED.ca";

# Message Subject
$emailsubject="Web Customer Submission";


#----------------------------------------------------------------
# Message Body-----------------------body not declared----------------------
$body = $body."This is a request for service from a customer <br>";
$body = $body."<b>Customer Name: </b>".$_REQUEST['cust_name']."<br>";
$body = $body."<b>Address: </b>".$_REQUEST['cust_address']."<br>";
$body = $body."<b>City: </b>".$_REQUEST['cust_city']."<br>";
$body = $body."<b>Province/State: </b>".$_REQUEST['cust_provstate']."<br>";
$body = $body."<b>Zip: </b>".$_REQUEST['cust_postzip']."<br>";
$body = $body."<b>Country: </b>".$_REQUEST['cust_country']."<br>";
$body = $body."<b>E-Mail: </b>".$_REQUEST['cust_email']."<br>";
$body = $body."<b>Customer is Intersted in: </b>".$_REQUEST['cust_interest']."<br>";
$body = $body."<b>Other Specification: </b>".$_REQUEST['cust_interest_other']."<br>";
$body = $body."<b>Design Selection: </b>".$_REQUEST['design_select']."<br>";
$body = $body."<b>Color Preferences: </b>".$_REQUEST['color_pref']."<br>";
$body = $body."<b>Customer Pertinent Info: </b>".$_REQUEST['cust_pertinfo']."<br>";
$body = $body."<b>Anything else the customer would like to see: </b>".$_REQUEST['cust_ideas']."<br>";
$body = $body."<b>Things the customer doesn't want on their card: </b>".$_REQUEST['Cust_dont_want']."<br>";
$body = $body."<b>Card Size: </b>".$_REQUEST['card_size']."<br>";
$body = $body."<b>Card Finish: </b>".$_REQUEST['card_finish']."<br>";
$body = $body."<b>Quantity: </b>".$_REQUEST['quantity']."<br>";
$body = $body."<b>Can you use the finished product as a design example? : </b>".$_REQUEST['cust_permission']."<br>";
$body = $body."<b>How did you find us?: </b>".$_REQUEST['found_us']."<br>";

#Add all other parts here
#----------------------------------------------------------------

send_mail($emailaddress, $fromaddress, $emailsubject, $body);
?>

TIA for your Help!
Hi,
The error is occurring here;
Expand|Select|Wrap|Line Numbers
  1. # Text Version
  2.   $msg .= "--".$mime_boundary.$eol;
  3.   $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
  4.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  5.   $msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
  6.  
  7.   # HTML Version
  8.   $msg .= "--".$mime_boundary.$eol;
  9.   $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  10.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  11.   $msg .= $body.$eol.$eol;
  12.  
The problem is, I think, you are making the same body into text version and again making it to html version. Use of html body for html versioning and plain body for text versioning will do a fever.

Two more errors in the coding.
Just check it in your original post, I have marked those.
Dec 21 '07 #2

P: 2
Hi,
The error is occurring here;
Expand|Select|Wrap|Line Numbers
  1. # Text Version
  2.   $msg .= "--".$mime_boundary.$eol;
  3.   $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
  4.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  5.   $msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
  6.  
  7.   # HTML Version
  8.   $msg .= "--".$mime_boundary.$eol;
  9.   $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  10.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  11.   $msg .= $body.$eol.$eol;
  12.  
The problem is, I think, you are making the same body into text version and again making it to html version. Use of html body for html versioning and plain body for text versioning will do a fever.

Two more errors in the coding.
Just check it in your original post, I have marked those.
Ranjan,

Should I take out one or the other of the versions? Also, how do I declare the body and the headers?

Thanks,

Denise
Dec 21 '07 #3

Ranjan kumar Barik
P: 95
Ranjan,

Should I take out one or the other of the versions? Also, how do I declare the body and the headers?

Thanks,

Denise
By removing the Html version, the mail function works well but,
you don't have to take out any one. You can declare two mail bodies like $text_body and $html_body and just pass two of them as parameters and make changes like this;
Expand|Select|Wrap|Line Numbers
  1. function send_mail($emailaddress, $fromaddress, $emailsubject, $text_body = "", $html_body ="")//Just To make them optional.
  2. {
  3. # Text Version
  4. $text_msg = "";
  5. $text_msg .= "--".$mime_boundary.$eol;
  6. $text_msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
  7. $text_msg .= "Content-Transfer-Encoding: 8bit".$eol;
  8. $text_msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
  9. $text_msg .= $text_body.$eol.$eol;
  10.  
  11. # HTML Version
  12. $html_msg = "";
  13. $html_msg  .= "--".$mime_boundary.$eol;
  14. $html_msg  .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  15. $html_msg  .= "Content-Transfer-Encoding: 8bit".$eol;
  16. $html_msg .= $html_body.$eol.$eol;
  17.  
When calling the function you can pass any one "text" or "html", because they are optional. If you don't pass any of the two then a blank message will be sent.

I think it will work, just try.

Merry Christ mass!
:)
Dec 22 '07 #4

ak1dnar
Expert 100+
P: 1,584
Please do not post any email address with the code snippets. Thanks.
Dec 22 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.