-2

I put this code on top of the same page:

<?php 
    if(isset($_POST['submit'])){
        $to = "rightysahu@gmail.com";
        $from = $_POST['email'];
        $first_name = $_POST['first_name'];
        $message = $first_name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
        echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";

        }
    ?>

And here is html (same page) coding:

<form action="" method="post" >
    <input type="text" name="first_name" placeholder="Name" />
        <input type="text" name="email" placeholder="Email" />
        <textarea name="message" placeholder="Message"></textarea>
        <input type="submit" name="submit"  value="Submit" />
    </form>

Form submitted successfully but did not get e-mails(inbox). PLease find out errors.(running on my site not on local server.)

righty
  • 1
  • 2

2 Answers2

1

For sending email need to configure machine.

If you are using linux machine then you can check this very good tutorial for how to configure Postfix mail on ubuntu/linux.

https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04

vijay
  • 731
  • 5
  • 15
0

$subject is not defined in your code. Also if you are running the code locally, use this. Check if the mail function executes by enclosing it in an if.

Community
  • 1
  • 1
Abey
  • 1,408
  • 11
  • 26