I've got a form with this text field:

<input name="address2" type="text" value="%%ADDRESS2%%">

on submit, it displays all the data in a confirmation page, and then when you submit the confirmation page it emails me the data.

In the email (maybe in belongs in the confirmation page?), I need it to say:

"if data was entered in that field, then include that data in the email"

How to do?

I kind of understand what you want to do..

Is the field a required field? In which, the user MUST enter the data for the email to send?


       // Create a body WITHOUT the data
       $body = "This is what the email will say without the data";
       $data = $_POST['address'];
       $body = "This is what the email will say if there is data.. The data is: $data";

    mail($EMAIL_ADDRESS, 'From: blahblah@blah.com', 'The title', $body);


Something along those lines?

No, it's not a required field. It's the second line of an address such as an apartment number.

Here is the line from the form:

<input name="address2" type="text" value="%%ADDRESS2%%">

And here's a chunk of html from the email template with what I think should happen:

  Postal Address:</td>
  if user entered data in the "address2" field
  print "%%ADDRESS2%%<br>"
  otherwise, print nothing
  %%CITY%%, %%STATE%% %%ZIP%%<br>

What you could do is append to the body of the email if the user filled this field, something like this:

$body = "this is what the mail starts with";
if (!$_POST['address2'] == null){
    $body = $body . $_POST['adress2'];
$body = $body . "this is what the mail ends with";

I don't have the time to boot up my development environment to test it, but using $body += instead of $body = $body .
might also work.

Oh, and i don't know if using and isset() here is a good idea, if i'm not mistaken, a $_POST will always make a field for every form input, even if it's empty (null)