-1

I want to send email using PHP. i have written code but emails are not getting sent. I have used PHP mail function to send email.

<?php
    $data = array();
    parse_str($_POST['formdata']['form'], $data);

    $fname = $data['fname'];
    $lname = $data['lname'];
    $email = $data['email'];
    $phone = $data['phone'];
    $message = $data['message'];

    $subject = "New Enquiry on the Website";

    if(mail($email,$subject, $message))
    {
        echo json_encode(array('status'=>TRUE));
    }

    else
    {
        echo json_encode(array('status'=>FALSE));
        $errormessage = error_get_last()['message'];
        print_r($errormessage);
    }
?>
hytsan
  • 85
  • 1
  • 10
  • 1
    You're trying to send them to an email address of `'email'`. You should use `$email` as the first argument to `mail()`. – BenM Apr 24 '20 at 07:05
  • i had hardcoded email there. so I removed hardcoded email id and wrote just email there. putting valid email id also doesnt work. – hytsan Apr 24 '20 at 07:08

1 Answers1

0

If you run this code in your localhost then you have to configure your localhost and php.ini

You can follow this link Send email from localhost

Or.

If you are run this code on your hosting then your hosting should have php send mail function enabled.

I hope you can understand.

smitexpert
  • 11
  • 7