0

I am trying to write some php code to send email for a form in html but it's not working as expected. The function returns a success messsage but i didn't get any mails in my inbox. I have referred other similar questions like : PHP mail function doesn't complete sending of e-mail but doesn't get any idea.

My PHP code:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$Mobile = $_POST['Mobile'];
$message = $_POST['message'];

$formcontent=" From: $name \n Phone: $Mobile \n Message: $message";

$subject = "Query";


$header = "From: Team <team.noreply@gmail.com>\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";

if(mail($email, $subject, $formcontent, $header))
{
    echo "Thank You!" . " -" . "<a href='index.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}   
else 
{
    echo '<p>Something went wrong. Please try again!</p>';
}

?>


I am hosting my website on 000webhosting.com using free account.

I came to know that free hosting doesn't provides all the functionalities and i'm not sure whether there's something wrong with my code or it's related to webhosting servers.

Kindly help me out and if there's issue with server then pls let me know if there's some server where i can test my code.

Thanks

Anand
  • 361
  • 1
  • 9
  • 23
  • @mario Sir i have already gone through that link and have also mentioned it in my question. please read the full description of the question again. – Anand Apr 20 '20 at 07:20
  • "doesn't get any idea" indicates you should read it again. There's nothing wrong with the code per se. – mario Apr 20 '20 at 07:22
  • I am trying to host websites on 000webhosting.com using free account. Can that be reason for mail not going through ? – Anand Apr 20 '20 at 07:28
  • 1
    You should check with the hosting provider whether they allow mail to be sent in this way. We don't know the specifics of each provider's configuration. As per the main answer to that thread (https://stackoverflow.com/a/24644450/5947043) I would also suggest using PHPMailer to create the email in PHP, it's a bit less error-prone than `mail()` (although as mario says, there's nothing obviously wrong with your existing code). Also have you checked the log files on the server for any clues? Or asked the hosting provider if they can see problems with your account? – ADyson Apr 20 '20 at 08:45
  • Thanks @ADyson for help... I just wanted to check if there's somthing missing in my code that i'm unable to figure out on my own – Anand Apr 20 '20 at 09:56

0 Answers0