0

I have VERY little experience with PHP.

I am testing out a contact form for this website. I am only getting the "subject, message, and header" fields in the email.

I need the telephone and name fields to show in my email message as well.

What am I doing wrong?

Any help is appreciated -- thanks!

<?php

    $name;$email;$message;$captcha;$telephone;
    if(isset($_POST['name'])){
      $name=$_POST['name'];
    }if(isset($_POST['email'])){
      $email=$_POST['email'];
      }if(isset($_POST['telephone'])){
      $telephone=$_POST['telephone'];
    }if(isset($_POST['message'])){
      $message=$_POST['message'];
    }if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
    }
    if(!$captcha){
      echo '<h2>Please check the the captcha form. <a href=http://www.website.com#contact/>Back to Form</a></h2>';
      exit;
    }
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcYjgcT****q9vhur7iH_O4dZPl4xUAVwW8=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    if($response.success==false)
    {
      echo '<h2>You are spammer ! Get the @$%K out</h2>';
    }else
    {
    // Checking For Blank Fields..
if ($_POST["name"] == "" || $_POST["email"] == "" || $_POST["telephone"] == "" || $_POST["message"] == "") {
    echo "Fill All Fields..";
} else {
    // Check if the "Sender's Email" input field is filled out
    $email = $_POST['email'];
    // Sanitize E-mail Address
    $email = filter_var($email, FILTER_SANITIZE_EMAIL);
    // Validate E-mail Address
    $email = filter_var($email, FILTER_VALIDATE_EMAIL);
    if (!$email) {
        echo "Invalid Sender's Email";
    } else {
        $to = 'email@gmail.com';
        $subject = 'Contact Form';
        $message = $_POST['message']; 
        $name = $_POST['name'];
        $headers = 'From:' . $email . "\r\n";
        // Sender's Email
        // Message lines should not exceed 70 characters (PHP rule), so wrap it
        $message .= "\r\n Name: " . $name;
        $message .= "\r\n Email: " . $email;
        $message .= "\r\n Telephone: " . $telephone;
        $message .= "\r\n Message: " . $message;
        // Send Mail By PHP Mail Function
        if (mail($to, $subject, $message, $headers)) {
            echo "Your mail has been sent successfully!<a href=http://wwwwebsite.com>Back</a>";
        } else {
            echo "Failed to send email, try again.";
            exit ;
        }
    }
}

} ?>

  • you need to append your `name` and `telephone` field value to `message` section. you never used those variable anywhere in your `mail` so how you will get them. – Alive to die - Anant Jun 01 '15 at 13:58
  • [Send email with PHP from html form][1] Visit this link hope so it will help you. Regards [link]: (http://stackoverflow.com/questions/18379238/send-email-with-php-from-html-form-on-submit-with-the-same-script) – Umar Akram Jun 01 '15 at 14:05
  • Thank you your link got me pointed in the right direction. – Kion Lofton Jun 01 '15 at 14:48

1 Answers1

0

The $message variable is the content of the mail that will be sent to your adress, add the values you want to get in your mail to that variable.

like so : (since you're not using HTML mail I think)

$message .= "\r\n Name : " . $name;
$message .= "\r\n Email : " . $email;

etc..

Before you call the mail function.

ALSO :

You're adding Phone number, Email, and message in your $email variable. you should give these their own variable.

Gerton
  • 676
  • 3
  • 14
  • Thank you, That helped. Now I am getting a double copy of everything now. Any idea why? I updated the code above. Thank you – Kion Lofton Jun 01 '15 at 14:47