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. Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/ 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. Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848623 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? Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848626 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); ?> Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848643 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. Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848658 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? Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848659 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. Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848675 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. Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848686 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. Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-848711 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>'; Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-849233 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? Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-849365 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 Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-849387 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>'; Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-849651 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. Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-849971 Share on other sites More sharing options...
artweb Posted June 5, 2009 Author Share Posted June 5, 2009 Topic Solved Link to comment https://forums.phpfreaks.com/topic/160798-solved-php-email-form-help/#findComment-849973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.