-1

When I submit the contact form, it runs the script and redirects back to the header, but no email is ever sent. I think I have some bugs in my code, but can't figure out where.

The HTML code is:

<form action="../php/mail.php" method="POST" enctype="multipart/form-data" name="Email Form" class="pure-form pure-form-stacked">
                <fieldset>

                    <label for="name">Name</label>
                    <input id="name" name="name" type="text" placeholder="Your Name">


                    <label for="email">Email</label>
                    <input id="email" name="email" type="email" placeholder="Your Email">

                    <label for="message">Message</label>
                    <!--<input id="password" type="password" placeholder="Your Password">-->
                    <input id="message" name="message" type="text" placeholder="Your Message">

                    <button type="submit" class="pure-button">Submit</button>
                </fieldset>
            </form>

The PHP script is:

<?php
$from = $_POST["email"]; // sender
$name = $_POST["name"];
$message = $_POST["message"];
$message = wordwrap($message, 70);
mail("myemail@gmail.com","My Contact Form",$message,"From: $from\n");
header( 'Location: http://www.mywebsite.com');
?>

1 Answers1

-1

Try the below code it will work.

$to = "myemail@gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" ;

mail($to,$subject,$txt,$headers);
header( 'Location: http://www.mywebsite.com');
Ajit Singh
  • 1,132
  • 1
  • 13
  • 24