Info from form shows in headers but not in body of email | Newbie | | Join Date: Dec 2007
Posts: 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: -
<? function send_mail($emailaddress, $fromaddress, $emailsubject, $body)
-
{
-
$eol="\r\n";
-
$mime_boundary=md5(time());
-
-
# Common Headers
-
$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[color=black]@[/color]".$_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 = $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!
|  | Member | | Join Date: Aug 2007
Posts: 95
| | | re: Info from form shows in headers but not in body of email Quote:
Originally Posted by sadieslc 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; - # 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;
-
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.
| | Newbie | | Join Date: Dec 2007
Posts: 2
| | | re: Info from form shows in headers but not in body of email Quote:
Originally Posted by Ranjan kumar Barik Hi,
The error is occurring here; - # 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;
-
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
|  | Member | | Join Date: Aug 2007
Posts: 95
| | | re: Info from form shows in headers but not in body of email Quote:
Originally Posted by sadieslc 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; -
function send_mail($emailaddress, $fromaddress, $emailsubject, $text_body = "", $html_body ="")//Just To make them optional.
-
{
-
# Text Version
-
$text_msg = "";
-
$text_msg .= "--".$mime_boundary.$eol;
-
$text_msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
-
$text_msg .= "Content-Transfer-Encoding: 8bit".$eol;
-
$text_msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
-
$text_msg .= $text_body.$eol.$eol;
-
-
# HTML Version
-
$html_msg = "";
-
$html_msg .= "--".$mime_boundary.$eol;
-
$html_msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
-
$html_msg .= "Content-Transfer-Encoding: 8bit".$eol;
-
$html_msg .= $html_body.$eol.$eol;
-
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!
:)
|  | Moderator | | Join Date: Jan 2007 Location: Colombo
Posts: 1,439
| | | re: Info from form shows in headers but not in body of email
Please do not post any email address with the code snippets. Thanks.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|