D. Roberts
D. Roberts

Reputation: 1

PHP email script not sending all form fields

IF (I Started Receiving Spam Bot Forms)

THEN (I Implemented New PHP Email script using a basic Honey Pot Method)

$ERROR (New PHP is not sending ALL the forms fields. Upon sending the form, my email is only receiving the, textarea id="message", field)

$LOG_FILE (My previous PHP script implemented a dynamic catch-all solution for form fields)

$FAILED_SOLUTION (Conversely I attempted to add the individual, $phone & $address fields manually on lines #6 7 & 14 of the PHP but am still only receiving the, textarea id="message", field)

$NOTES (I am self taught & typically only deal with PHP on a need to know basis. Please try to keep it simple and include a step-by-step explanation. Feel free to suggest any "best practices" i may have overlooked unrelated to my problem!)

$QUESTION = "Can someone show me how to call the other form fields in the PHP script to send to my email?"

$SUCCESS = "Thanks in Advance For Any Help That Maybe Given!";

PHP:

<?php
if($_POST){
$to = '[email protected]';
$subject = 'Contact Form Submission';
$name = $_POST['name'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$email = $_POST['email'];
$message = $_POST['message'];
$robotest = $_POST['robotest'];
if($robotest)
  $error = "Spam Protection Enabled";
else{
  if($name && $phone && $address && $email && $message){
    $header = "From: $name <$email>";
    if(mail($to, $subject, $message,$header))
      $success = "Your message was sent!";
    else
      $error = "Error_36 there was a problem sending the e-mail.";
  }else
    $error = "Error_09 All fields are required.";
}
if($error)
  echo '<div class="msg error">'.$error.'</div>';
elseif($success)
  echo '<div class="msg success">'.$success.'</div>';
}
?>

HTML FORM:

<form method="post" action="Form_Email.php">
    <input type="text" id="name" name="name" placeholder="name" required>
    <input type="text" id="phone" name="phone" placeholder="phone" required>
    <input type="text" id="address" name="address" placeholder="address" required>
    <input type="text" id="email" name="email" placeholder="email" required>                            
    <textarea id="message" name="message" placeholder="message" required> </textarea>
<p class="robotic">
    <input name="robotest" type="text" id="robotest" class="robotest" autocomplete="off"/>
</p>
    <input type="submit" id="SEND" value="Submit">
</form> 

Upvotes: 0

Views: 69

Answers (1)

btlm
btlm

Reputation: 350

Your message contains only $_POST['message'] for now. If you want to append other values, use concatenation on your $message variable.

$message .= ($name . $phone . $address . $etc)

Notice: A $foo .= $bar construction stands for $foo = $foo . $bar.

Do not forget about whitesigns such as spaces or new lines wherever you want. Simply concatenate ' ' or "\n".

After that, just send a mail using your $message as message.

Upvotes: 1

Related Questions