Question

I have this form on my contact page:

    <?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $phone = $_REQUEST['phone'] ;
  $message = $_REQUEST['message'] ;
  mail("contact@*****.com", $name, 
  $message, "From:" . $email);
  echo "Thank you for using our mail form. <br><br>We will get back to you within 48 hours.";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<br><form method='post' action='enquiry.php' align='center'>
  <strong>Name: </strong><input class='textbox' name='name' type='text'><br><br>
  <strong>Email: </strong><input class='textbox' name='email' type='text'><br><br>
  <strong>Phone: </strong><input class='textbox' name='phone' type='text'><br><br>
  <strong>Message: </strong><br>
  <textarea class='textbox' name='message' rows='15' cols='40'>
  </textarea><br>
  <input type='submit'><br><br>
  </form>";
  }
?>

which sends me an email when someone submits the form.

but when I try to add $phone to my email code. it fails to send the mail to me.

please can someone advise me on where I can add this? thank you.

Was it helpful?

Solution

Do this:

$message = $_REQUEST['message'].$phone;

This will appened the mobile number with your message.

OTHER TIPS

So what's the problem, append the number to $message before sending it.

$message .= $phone;

try it

<?php
if (isset($_REQUEST['email'])) //if "email" is filled out, send email
{
      //send email
      $name = $_REQUEST['name'] ;
      $email = $_REQUEST['email'] ;
      $phone = $_REQUEST['phone'] ;
      $message = $_REQUEST['message'] ;

      $message_text = $message." Phone no:".$phone; // combine here $message and $phone to $message_text

      mail("contact@*****.com", $name, $message_text, "From:" . $email); // now use $message_text here to send mail
      echo "Thank you for using our mail form. <br><br>We will get back to you within 48 hours.";
}
else //if "email" is not filled out, display the form
{
      echo "<br><form method='post' action='enquiry.php' align='center'>
      <strong>Name: </strong><input class='textbox' name='name' type='text'><br><br>
      <strong>Email: </strong><input class='textbox' name='email' type='text'><br><br>
      <strong>Phone: </strong><input class='textbox' name='phone' type='text'><br><br>
      <strong>Message: </strong><br>
      <textarea class='textbox' name='message' rows='15' cols='40'>
      </textarea><br>
      <input type='submit'><br><br>
      </form>";
 }
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top