Contact Form only sending message

I am extremely stuck on this issue. I have the PHP form working and it sends an email, however its only sending what I type in the message. The Name, Email, Phone and URL are all not being sent only the message. If someone could please assist and tell me what I am missing. :slight_smile:

[php]<?php

// define variables and set to empty values
$name_error = $email_error = $phone_error = $url_error = “”;
$name = $email = $phone = $message = $url = $success = “”;

//form is submitted with POST method
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
if (empty($_POST[“name”])) {
$name_error = “Name is required”;
} else {
$name = test_input($_POST[“name”]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$name_error = “Only letters and white space allowed”;
}
}

if (empty($_POST[“email”])) {
$email_error = “Email is required”;
} else {
$email = test_input($_POST[“email”]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email_error = “Invalid email format”;
}
}

if (empty($_POST[“phone”])) {
$phone_error = “Phone is required”;
} else {
$phone = test_input($_POST[“phone”]);
// check if e-mail address is well-formed
if (!preg_match("/^(\d[\s-]?)?[([\s-]{0,2}?\d{3}[)]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$phone)) {
$phone_error = “Invalid phone number”;
}
}

if (empty($POST[“url”])) {
$url_error = “”;
} else {
$url = test_input($POST[“url”]);
// check if URL address syntax is valid (this regular expression also allows dashes in the URL)
if (!preg_match("/\b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~
|!:,.;]*[-a-z0-9+&@#/%=~
|]/i",$url)) {
$url_error = “Invalid URL”;
}
}

if (empty($_POST[“message”])) {
$message = “”;
} else {
$message = test_input($_POST[“message”]);
}

if ($name_error == ‘’ and $email_error == ‘’ and $phone_error == ‘’ and $url_error == ‘’ ){
$message_body = ‘’;
unset($_POST[‘submit’]);
foreach ($_POST as $key => $value){
$message_body .= “$key: $value\n”;
}

  $to = 'myemail[member=6131]Shaw[/member].ca';
  $subject = 'Contact Form Submit';
  if (mail($to, $subject, $message)){
      $success = "Someone will be with you shortly";
      $name = $email = $phone = $message = $url = '';
  }

}

}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}[/php]

Where are you adding the name, email, phone and url to the email?

[php] if ($name_error == ‘’ and $email_error == ‘’ and $phone_error == ‘’ and $url_error == ‘’ ){
$message_body = ‘’;
unset($_POST[‘submit’]);
foreach ($_POST as $key => $value){
$message_body .= “$key: $value\n”;
}

   $to = 'myemail[member=6131]Shaw[/member].ca';
   $subject = 'Contact Form Submit';
   if (mail($to, $subject, $message)){[/php]

Do you want $message or $message_body?

Hello,

It seems you are using the same contact form I am. Your message now reads this:

 $to = 'myemail[member=6131]Shaw[/member].ca';
       $subject = 'Contact Form Submit';
       if (mail($to, $subject, $message)){
           $success = "Someone will be with you shortly";
           $name = $email = $phone = $message = $url = '';
       }

And it should look like this:

$to = '[email protected]';
      $subject = 'Contact Form Submit';
      $mailheader = "From: ".$_POST["email"] . "\n";
      $mailheader .= "Reply-To: ".$_POST["email"]."\n";
      $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
      $message_body = "<span style='font-size: 12pt;'>Name: ".$_POST["name"] . "</span><br>" ;
      $message_body .= "<span style='font-size: 12pt;'>URL: " . $_POST["url"] . "</span><br><br>";
      $message_body .= "<span style='font-size: 12pt;'>" . nl2br($_POST["message"]) . "</span>";
      if (mail($to, $subject, $message_body, $mailheader)){
          $success = "Message sent, thank's for contacting us!";
          $name = $email = $captchaResult = $message = $url = '';
      }

This will send the name of your messager and his url, but the url won’t come through as a link. Good luck.

Sponsor our Newsletter | Privacy Policy | Terms of Service