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?

<?php

    if(!isset($_POST['address']))
    {
       // Create a body WITHOUT the data
       $body = "This is what the email will say without the data";
    }else{
       $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:

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

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

<?php
$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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.