user3225171
user3225171

Reputation: 13

Php contact form not working well

So I have built my website and I planned on using a php based contact page to send emails to my email address I made this and I receive an e-mail but no content or summary... so here is my html:

<form action="Php/sendemail.php" method="POST">
<div id="form-inner">

<input type="text" class="input" name="name" id="name" placeholder="Name">
<input type="email" class="input" name="email" id="email" placeholder="E-mail">
<textarea class="input textarea" name="message" id="message" placeholder="Your message here"></textarea>    

<input type="submit" class="button" value="Send message" id="button">
</div>
</form>

and here is my php:

$subject = "Contact form submitted!";
$to = '[email protected]';

$body = <<<HTML
$message
HTML;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

mail($to, $subject, $message, $headers);

header('Location: /Contact.php');
?>

I really do not understand why this is happening if you can please help ! Thnaks

Upvotes: 0

Views: 70

Answers (1)

John Conde
John Conde

Reputation: 219934

This is because you are not geeting the value from the $_POST superglobal:

$body = <<<HTML
$message
HTML;

should be:

$message = $_POST['message'];
$body = <<<HTML
$message
HTML;

Of course there are other ways to do this like just putting $_POST['message']; in the message body but this illustrates how to get the submitted form values.

(You will also want to do things like clean up (i.e. trim(), etc) the submitted values and also defend against header injections as well).

Upvotes: 1

Related Questions