Jump to content

[SOLVED] Php email form help


artweb

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.