0

I know there have been a lot of post regarding this, but mine doesn't seem to work off here. The row gets fetched from the database fine but the mail is not sent. Here is my code.

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method = "POST">

<input type = "email" name = "email" placeholder = "Enter Your Email Address" required/>
<input type = "submit" name= "submit" value = "submit"/>

</form>

php code

function sendEmail(){
            $to = "someone@gmail.com";
            $subject = "the subject";
            $message = "First line";
            $headers = 'From: someone@example.com' . "\r\n" .'Reply-To: someone@example.com' . "\r\n" .'X-Mailer: PHP/' . phpversion();

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


if(isset($_POST['submit']) && $_POST['submit'] == 'submit'){
    $email = $_POST['email'];

    $sql = $db->prepare("SELECT * from users where email = ?");
    $sql->bind_param("s",$email);
    $sql->execute();
    $sql = $sql->get_result();

    if(($getRowCount = $sql->num_rows) == 1){
            sendEmail();
}
  • is Email column in the database is unique/contains unique values ? – Ravinder Reddy May 31 '16 at 17:56
  • This could be greatly reduced to create an [MVCE](http://stackoverflow.com/help/mcve). If you're certain the DB look up is working, you should omit it from the question. It looks like the entire issue pertains to your mail call: `mail($to, $subject, $message, $headers);` so only the `sendEmail()` function is helpful info here. See this for how to debug `mail()`: [PHP mail form doesn't complete sending e-mail](http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – HPierce May 31 '16 at 17:58

0 Answers0