spum0n1
spum0n1

Reputation: 26

Can't find whats wrong in my php for contact form

the php in my contact form doesn't seem to be working. I'm getting a " Please correct the following error:

Write your message Hit the back button and try again" If anyone with experience could share some advice, I'd very much appreciate it. Thanks !

<?php
/* Set e-mail recipient */
$myemail = "[email protected]";

/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$phone = check_input($_POST['phone'], "Enter phone number");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "

Name: $name
E-mail: $email
Phone: $phone

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $phone, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>


 <div class="wrapper">  
    <div id="contact_form">
    <form name="form1" id="ff" method="post" action="form.php">

        <label>
        <span>Name*:</span>
        <input type="text" placeholder="Please enter your name" name="name" id="name" required autofocus>
        </label>

        <label>
        <span>Phone:</span>
        <input type="tel" placeholder="Please enter your phone" name="phone" id="phone">
        </label>



        <label>
        <span>Email*:</span>
        <input type="email" placeholder="[email protected]" name="email" id="email" required>
          </label>

           <label>
        <span>Message:</span>
       <textarea placeholder="message"></textarea>
        </label>


        <input class="sendButton" type="submit" name="Submit" value="Send">      
    </form>
    </div>
   </div>

Upvotes: 0

Views: 118

Answers (1)

David
David

Reputation: 218847

You're looking for a value called "message":

$_POST['message']

But you don't have a form element named "message" in your form.

Add a name to your textarea:

<textarea name="message" placeholder="message"></textarea>

Upvotes: 3

Related Questions