Mail function not working

0 Saud Ahmad · July 5, 2015
Why is my mail function not working for this form? I have tried every possible thing!! :(

if (isset($_POST['name1']) && isset($_POST['mobile1']) && isset($_POST['email1']) && isset($_POST['message1'])){
 $name1 = $_POST['name1'];
  $mobile1 = $_POST['mobile1'];
   $email1 = $_POST['email1'];
    $message1 = $_POST['message1'];

    if (!empty($name1) && !empty($mobile1) && !empty($email1) && !empty($message1)){

    $to = 'example@gmail.com';
    $subject = 'Query Mail';
    $body = $message1;
    $headers = 'From: '.$email1;

    if (@mail($to, $subject, $body, $headers)){
     echo 'Mail sent! Thanks for contacting us. We\'ll get back to you shortly!';
    } else {
     echo 'Sorry! Unable to send the mail. Please try again later!';
    }
    }
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Zaeem Hasan · July 5, 2015
Are you sending mail through paid web hosting? Because its not gonna work through local host
0 ahmed sabry · July 6, 2015
it doesn't work on localhost 
0 Abdul Jabbar · August 4, 2015
use gmail smtp service with php mailer class and all done...:)
0 Ian Arbuckle · August 5, 2015
Try the SMTP with php mailer class like suggested above or set up a digital ocean server.
  • 1

PHP

107,221 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators