Contact Form

VoltronFutura

New Member
I've tried a lot of different stuff to try and get my contact form to send the name, phone, company, and message in a single email. However, all I can get is it to just send the message. I used smoovo's php code from another thread, and that's what I tried to modify to get it to work.

Here's that code
PHP:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail( "[email protected]", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

Now here's some of the stuff I've done to it to try and make it work for my needs.

PHP:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $subject = $_REQUEST['subject'] ;
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $company = $_REQUEST['company'] ;
  $phone = $_REQUEST['phone'] ;
  $message = $_REQUEST['message'] ;
  $yes = $_REQUEST['yes'] ;
  $no = $_REQUEST['no'] ;
  $body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Company: $company <br>
Phone: $phone <br>
Message: $message <br>
Yes: $yes <br>
No: $no <br>
EOD;

  mail( "[email protected]", $subject, $body );
  
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

What do I need to do to make it work?
 

smoovo

New Member
Try adding some headers, some servers will only send if the header is formatted a certain way.

That's right. I posted the basic script (this script works and also yours), but there is more components to add.

For example:
1. Headers - Email configuration. (in your script you are using HTML, you should add HTML content type)
2. Email check - if the email entered is valid.

So as bcee mentioned, add headers to your mail() function. The shorter header should be "From: $email".

You can read more about "Headers" in the php.net website.

- Enjoy.
 
Last edited:

VoltronFutura

New Member
I've tried all these solutions, but the problem is that it won't send the email at all. If I use the simple form, it sends, but I need all the information to send. At one point, it was sending the body code in the subject line. It's becoming very frustrating.

This is what I've got right now.
PHP:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $subject = $_REQUEST['subject'] ;
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $company = $_REQUEST['company'] ;
  $phone = $_REQUEST['phone'] ;
  $message = $_REQUEST['message'] ;
  $yes = $_REQUEST['yes'] ;
  $no = $_REQUEST['no'] ;

$body = <<<EOD
<br><hr><br>
Name: $name <br>
Company: $company <br>
Phone: $phone <br>
Message: $message <br>
Yes: $yes <br>
No: $no <br>
EOD;

  mail( "[email protected]", $body, "From: $email" );  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>
 
Top