Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » form mailer RSS

form mailer

This thread was started by mlhamp and has been viewed 609 times, and contains 2 replies, with the last reply made by Danny[MLWA].
Post Reply
1
View mlhamp's reputation
mlhamp, WDF Noob Private message  
Posted June 4 '09 at 11:30 PM
      Posts: 1
I have a form mailer that is sending me a grocery list by email. I need the items that are checkboxes and the qty to show up side by side in the email. It currently shows up like this in the email:

From : fdgfg

Address : dfgdfg

Delivery Date : dfgdf

Phone : fdgdf

Email : fdgdg

Email Confirm : dfgdf

Comments : dfgdfg

Item Ordered: Active Care-Chicken Brown Rice- 4.4 lb bag Price=$8.99

Item Ordered: Active Care-Chicken Brown Rice- 15 lb bag Price=$22.99

Item Ordered: Active Care-Chicken Brown Rice - 30 lb bag Price=$41.99

QTY: 1 QTY: 2 QTY: 3

I would like to see it show up like this:

Item Ordered: Active Care-Chicken Brown Rice - 30 lb bag Price=$41.99 QTY: 1


Any suggestions or help...Here is the html code for the form:
<FORM NAME="form1" METHOD="post" ACTION="?send=1">
  
  <table width="97%" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td width="97%"><span class="style1"><font size="2">Name&nbsp;</font></span>
          <input type="TEXT" name="NAME" size="30" class="shadeform" VALUE="<?PHP ECHO $_POST[NAME]; ?>">
          &nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1"><font size="2">Address&nbsp;</font></span><input type="TEXT" name="ADDRESS" size="30" class="shadeform" value="<?PHP ECHO $_POST[ADDRESS]; ?>" />
        <span class="style1"><font size="2">&nbsp; Delivery Date</font></span>
        <input type="TEXT" name="DATE" size="30" class="shadeform" VALUE="<?PHP ECHO $_POST[DATE]; ?>">
            
        <br>      </td>
    </tr>
   
    <tr>
      <td><span class="style1"><font size="2">Phone </font><font size="2"> # &nbsp;&nbsp; </font></span>
          <input type="TEXT" name="PHONE" size="30" class="shadeform" VALUE="<?PHP ECHO $_POST[PHONE]; ?>">
        <span class="style1"><font size="2">E-Mail&nbsp;&nbsp;</font></span>
          <input type="TEXT" name="EMAIL" size="30" class="shadeform" VALUE="<?PHP ECHO $_POST[email]; ?>">
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="style1"><font size="2">E-Mail Confirm&nbsp;&nbsp;</font></span>
          <input type="TEXT" name="EMAIL_CONFIRM" size="30" class="shadeform" VALUE="<?PHP ECHO $_POST[EMAIL_CONFIRM]; ?>">
          
      </td>
    </tr>
   <tr>
      <td><span class="style1"> <font size="2">Comments/Questions/Request&nbsp;&nbsp;</font></span><input type="TEXT" name="COMMENTS" size="100%" class="shadeform" VALUE="<?PHP ECHO $_POST[COMMENTS]; ?>">


ï <a name="actived1" id="actived1"></a>Active Care </B><BR>
  <INPUT type=checkbox value="Active Care-Chicken & Brown Rice- 4.4 lb bag  Price=$8.99" name="BOX[]" >
  Chicken &amp; Brown Rice - 4.4 lb bag &nbsp;&nbsp;Price=$8.99&nbsp;&nbsp;
  <input type="text" name="QTY[]" value="<?PHP ECHO $_POST[QTY]; ?>" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Active Care-Chicken & Brown Rice- 15 lb bag  Price=$22.99" name="BOX[]">
  Chicken &amp; Brown Rice - 15 lb bag&nbsp;&nbsp;Price=$22.99&nbsp;&nbsp;
  <input type="text" name="QTY[]" value="<?PHP ECHO $_POST[QTY]; ?>" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Active Care-Chicken & Brown Rice - 30 lb bag  Price=$41.99" name="BOX[]">
  Chicken &amp; Brown Rice - 30 lb bag&nbsp;&nbsp;Price=$41.99&nbsp;&nbsp;
  <input type="text" name="QTY[]" value="<?PHP ECHO $_POST[QTY]; ?>" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Active Care-Lamb & Brown Rice - 4.4 lb bag  Price=$8.99" name="BOX4">
  Lamb &amp; Brown Rice - 4.4 lb bag&nbsp;&nbsp;Price=$8.99&nbsp;&nbsp;
  <input type="text" name="QTY4" value="<?PHP ECHO $_POST[QTY4]; ?>" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Active Care-Lamb & Brown Rice - 15 lb bag  Price=$22.99" name="BOX5">
  Lamb &amp; Brown Rice - 15 lb bag&nbsp;&nbsp;Price=$22.99&nbsp;&nbsp;
  <input type="text" name="QTY5" value="<?PHP ECHO $_POST[QTY5]; ?>" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Active Care-Lamb & Brown Rice - 30 lb bag  Price=$41.99" name="BOX6">
  Lamb &amp; Brown Rice - 30 lb bag&nbsp;&nbsp;Price=$41.99&nbsp;&nbsp;
  <input type="text" name="QTY6" value="<?PHP ECHO $_POST[QTY6]; ?>" maxlength="2" size="4">
  Quantity<BR>
    <br />
  Add more items to my order: <a href="#products">Product Categories</a> or 
  complete my order
  <input name="submit" type="submit" class="button" onMouseOver="this.className='buttonon'" onMouseOut="this.className='button'" value="Submit Order">
  <br />
  <br /> 
  <br />
  <strong>ï <a name="avodermd1" id="avodermd1"></a>Avoderm</strong><BR>
  <INPUT type=checkbox value="Fresh Lime" name=field006>
  Baked Lamb - 4.4 lb bag&nbsp;&nbsp;Price=$11.99&nbsp;&nbsp;
  <input type="text" name="quantity8" value="" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Fresh Lemons" name=field005>
  Baked Lamb - 15 lb bag&nbsp;&nbsp;Price=$27.99&nbsp;&nbsp;
  <input type="text" name="quantity9" value="" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Fresh Melons" name=field007>
  Baked Lamb - 30 lb bag&nbsp;&nbsp;Price=$59.99&nbsp;&nbsp;
  <input type="text" name="quantity10" value="" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Fresh Nectarines" name=field008>
  Baked Original (Beef) - 4.4 lb bag&nbsp;&nbsp;Price=$8.99&nbsp;&nbsp; 
      <input type="text" name="quantity11" value="" maxlength="2" size="4">
  Quantity<BR>
  <INPUT type=checkbox value="Fresh Oranges" name=field009>
  Baked Original (Beef) - 15 lb bag&nbsp;&nbsp;Price=$27.99 &nbsp;&nbsp;
  <input type="text" name="quantity12" value="" maxlength="2" size="4">
  Quantity<BR>

Here is the php formmailer:
<?PHP



$YOUREMAIL = "mike@?????.com";


?>




<link href="stylesheet.css" rel="stylesheet" type="text/css">


<?PHP if ($_GET[send] < 1) { ?>
<?php include "delivery_form.php"; ?>
<?PHP } ?>
<?PHP
if ($_GET[send] == 1) {
        if ($_POST[NAME] == $nil || $_POST[ADDRESS] == $nil || $_POST[DATE] == $nil || $_POST[PHONE] == $nil || $_POST[email] == $nil || $_POST[EMAIL_CONFIRM] == $nil)
                $_GET[send] = 2;
}
if ($_GET[send] == 1) {
$comment = preg_replace("/\n/","\n<BR>",$_POST[COMMENT]);
$to="$YOUREMAIL";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\r\n";
$headers.= "From: $_POST[email]";
$subject = "Bark City Delivery Contact";
foreach($_POST['BOX']  as  $value)  {

$check_msg .= "Item Ordered: $value\n <br />
<br />";

} 

foreach($_POST['QTY']  as  $value)  {

$check_msg2 .= "QTY: $value\n";

} 

$body = "<HTML><BODY>
<b>From : $_POST[NAME]</b><BR><BR>
<b>Address : $_POST[ADDRESS]</b><BR><BR>
<b>Delivery Date : $_POST[DATE]</b><BR><BR>
<b>Phone : $_POST[PHONE]</b><BR><BR>
<b>Email : $_POST[email]</b><BR><BR>
<b>Email Confirm : $_POST[EMAIL_CONFIRM]</b><BR><BR>
<b>Comments : $_POST[COMMENTS]</b><BR><BR>
<b>$check_msg $check_msg2</b>


</BODY></HTML>
";


mail($to,$subject,$body,$headers);

?>

Advertisement Register for free to hide these ads and participate in discussions!

2
1,251 points at 99% Moderator Repute
mlseim, WDF Moderator Private message  
Posted June 5 '09 at 08:59 AM
      Posts: 3,100
I'm not trying to flame your question, but if you're starting this out at the beginning,
it would be good if someone pointed out some things that would help you succeed.

With that said ...

I think you're doing it the wrong way, beginning with the form you have.

First of all, I'm assuming you're experimenting with something on the form,
as you have BOX[] and BOX4 ... they are the same item?

And further down the form is a bunch of other groceries that are formatted
totally different than the "Active Care" items.

Which part of the form is the real part?

==============

For things like this, you should be using a database to organize the items.
Each one has an ID, description, price, etc.

A PHP script generates the form from your database, automatically.
That does two things for you:
1) You don't have to edit your form, PHP makes it for you.
2) It makes the handling of quantities very easy. As the script only needs to
know the quantity for each ID. Once the form is submitted, the script opens
the database and generates the invoice using the ID and quantities.

If you end-up having 2000 items in inventory, see where a database will be good?
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
Last edited June 5 '09 at 09:07 AM by mlseim. Reply

3
32 points at 100%
Posted June 10 '09 at 03:58 AM
      Posts: 76
Make sure if you're using this method:

<?PHP ECHO $_POST[QTY]; ?>

to create a function to ensure that it is set before telling it to echo, else you get some nice little warnings (if warnings are configured) in the header...

example:

<input something something value="<?PHP echo(get_info('QTY')); ?>">
<?PHP
function get_info($fieldname) {
   if(isset($_GET[$fieldname])) {
   return $_GET[$fieldname];
   } else {
   return null;
   }
}
?>

This will make sure that if the super-global $_GET['QTY'] is set and has a value it will echo it, else it will not do anything avoiding errors and warnings =)

Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP form not working Ella ASP and .NET 16 January 14 '08 11:27 PM
inserting data from another page into a form mailer timgrigg HTML and CSS Help 2 February 14 '06 08:04 AM
Help! Form POST to another page PLUS js control. MEGAginge Javascript, AJAX, and JSON 0 September 21 '05 06:43 PM
Form mailer Urban Web Design Discussion 1 August 26 '05 05:09 AM
SMTP Error when running CGI form mailer lmarshall Java and JSP 1 June 18 '03 09:35 AM