artweb Posted June 3, 2009 Share Posted June 3, 2009 I have a email form that lets people order products from a company. When the email come in it has every product that's on the form in the email. I want to have just the product the customer orders show in the email. How do I control this with the $subject. I hope this make sense. Quote Link to comment Share on other sites More sharing options...
SuperBlue Posted June 3, 2009 Share Posted June 3, 2009 You just pass on the product Id in the form. Its hard to say more without knowing your site structure. Quote Link to comment Share on other sites More sharing options...
artweb Posted June 3, 2009 Author Share Posted June 3, 2009 You just pass on the product Id in the form.? What do you mean? Quote Link to comment Share on other sites More sharing options...
artweb Posted June 3, 2009 Author Share Posted June 3, 2009 The customer come to my form, and lets say they only fill out the city and state. Then when I get the email it says the following:  Company Name: Address: City:somewhere State:nowhere Zip: Contact Person: Phone: Fax: Email: Question:  I want the email to only have this: Not all the other category that they left blank.  City:somewhere State:nowhere   This is what my code looks like.  <?php  $subject ="order form"; } $message=" Company Name: $companyname,         Address: $address, City: $city, State: $state, Zip: $zip, Contact Person: $contact_person, Phone: $phone, Fax: $fax, Email: $email, Question: $question,;  $mail_from="$email"; $header="from: $companyname <$email>"; $to =''; $done=mail($to,$subject,$message,$header); ?> Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 3, 2009 Share Posted June 3, 2009 The body of your message is being defined by the $message tag  $message=" Company Name: $companyname,         Address: $address, City: $city, State: $state, Zip: $zip, Contact Person: $contact_person, Phone: $phone, Fax: $fax, Email: $email, Question: $question,;  If you did not want to include particulars you'd have to do some testing, for example if zip is blank then message is bla bla which doesn't include zip. This would result in quite a few if statements though. Quote Link to comment Share on other sites More sharing options...
artweb Posted June 3, 2009 Author Share Posted June 3, 2009 Can you show me a if statement that might work? Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 3, 2009 Share Posted June 3, 2009 replace the $message aspect in your code with this.. Â if ($companyname) $message = $message . 'Company Name:' . $companyname . '<br>'; if ($address) $message = $message . 'Address:' . $address . '<br>'; if ($city) $message = $message . 'City:' . $city . '<br>'; if ($state) $message = $message . 'State:' . $state . '<br>'; if ($zip) $message = $message . 'Zip:' . $zip . '<br>'; if ($contact_person) $message = $message . 'Contact Person:' . $contact_person . '<br>'; if ($phone) $message = $message . 'Phone:' . $phone . '<br>'; if ($fax) $message = $message . 'Fax:' . $fax . '<br>'; if ($email) $message = $message . 'Email:' . $email . '<br>'; if ($question) $message = $message . 'Question:' . $question . '<br>'; Â That will build the $message variable depending on if the individual variables are set. Quote Link to comment Share on other sites More sharing options...
artweb Posted June 3, 2009 Author Share Posted June 3, 2009 I try replacing the code and I got the same email with all the category. Not just the ones I filled in. Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 3, 2009 Share Posted June 3, 2009 Let me see the full code you have in place now. Quote Link to comment Share on other sites More sharing options...
artweb Posted June 4, 2009 Author Share Posted June 4, 2009 There my php code now. <?php  $subject ="order form";  $message=" if ($companyname) $message = $message . 'Company Name:' . $companyname . '<br>'; if ($address) $message = $message . 'Address:' . $address . '<br>'; if ($city) $message = $message . 'City:' . $city . '<br>'; if ($state) $message = $message . 'State:' . $state . '<br>'; if ($zip) $message = $message . 'Zip:' . $zip . '<br>'; if ($contact_person) $message = $message . 'Contact Person:' . $contact_person . '<br>'; if ($phone) $message = $message . 'Phone:' . $phone . '<br>'; if ($fax) $message = $message . 'Fax:' . $fax . '<br>'; if ($email) $message = $message . 'Email:' . $email . '<br>'; if ($question) $message = $message . 'Question:' . $question . '<br>'; ";      $mail_from="$email"; $header="from: $companyname <$email>"; $to =''; $done=mail($to,$subject,$message,$header);  ?>    This is what the email looks like. You can see that the Zip and The Email have been left blank but they still show in the email. I want them to be left out of the email when they have not been filled in.  if (new) = . 'Company Name:' . new . '<br>'; if (dsf) = . 'Address:' . dsf . '<br>'; if (adsf) = . 'City:' . adsf . '<br>'; if (adsf) = . 'State:' . adsf . '<br>'; if () = . 'Zip:' . . '<br>'; if (fds) = . 'Contact Person:' . fds . '<br>'; if (sdfa) = . 'Phone:' . sdfa . '<br>'; if (sdf) = . 'Fax:' . sdf . '<br>'; if () = . 'Email:' . . '<br>'; if (asdf) = . 'Question:' . asdf . '<br>';  Quote Link to comment Share on other sites More sharing options...
artweb Posted June 4, 2009 Author Share Posted June 4, 2009 I keep trying but nothing is working here. Does anyone know if this can be done? Quote Link to comment Share on other sites More sharing options...
laPistola Posted June 4, 2009 Share Posted June 4, 2009 $message= ""; if (!empty($companyname)) { Â $message .= "Company Name: $companyname\n"; } if (!empty($address)) { Â $message .= "Address: $address\n"; } Â Do that for all and it will only include info for fields thats not empty Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 5, 2009 Share Posted June 5, 2009 Ahh you misunderstood  You have it set so that $message is everything I sent to you where as $message is each individual line, not all of them together..  replace  $message=" if ($companyname) $message = $message . 'Company Name:' . $companyname . '<br>'; if ($address) $message = $message . 'Address:' . $address . '<br>'; if ($city) $message = $message . 'City:' . $city . '<br>'; if ($state) $message = $message . 'State:' . $state . '<br>'; if ($zip) $message = $message . 'Zip:' . $zip . '<br>'; if ($contact_person) $message = $message . 'Contact Person:' . $contact_person . '<br>'; if ($phone) $message = $message . 'Phone:' . $phone . '<br>'; if ($fax) $message = $message . 'Fax:' . $fax . '<br>'; if ($email) $message = $message . 'Email:' . $email . '<br>'; if ($question) $message = $message . 'Question:' . $question . '<br>'; ";  with  if ($companyname) $message = $message . 'Company Name:' . $companyname . '<br>'; if ($address) $message = $message . 'Address:' . $address . '<br>'; if ($city) $message = $message . 'City:' . $city . '<br>'; if ($state) $message = $message . 'State:' . $state . '<br>'; if ($zip) $message = $message . 'Zip:' . $zip . '<br>'; if ($contact_person) $message = $message . 'Contact Person:' . $contact_person . '<br>'; if ($phone) $message = $message . 'Phone:' . $phone . '<br>'; if ($fax) $message = $message . 'Fax:' . $fax . '<br>'; if ($email) $message = $message . 'Email:' . $email . '<br>'; if ($question) $message = $message . 'Question:' . $question . '<br>'; Quote Link to comment Share on other sites More sharing options...
artweb Posted June 5, 2009 Author Share Posted June 5, 2009 That's it. Thank you so much! Sorry to be such a newbie. Quote Link to comment Share on other sites More sharing options...
artweb Posted June 5, 2009 Author Share Posted June 5, 2009 Topic Solved Quote Link to comment 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.