Creaing php contact form

56 views Asked by At

I'm new to php to I've tried to write my own php contact form to learn. Obviously having troubles now, here's my code:

<form action="mail-2.php" method="POST">
<p>Your Name (required)</p> <input type="text" name="name">
</br></br><p>Your Email (required)</p> <input type="text" name="email">
</br></br><p>Phone</p> <input type="text" name="phone">
</br></br>
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />

</br></br>
<input type="submit" name="saveForm" value="Send">
</form>

and php: mail-2.php

<?php
$to = "[email protected]";
$from = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Message: $message";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($to, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='index.html' style='text-decoration:none;color:#4A148C;'> Return Home</a>";
?>

can anyone help me to get this working? It goes to the thank you page after I click send but the email does not go through.

Also I need to add an attachment to the form too but after several attempts I think I failed

0

There are 0 answers