Mail Function not working when i fetch mail id from database.

  • Answered
$subject = "Appointment From The Doctors Villa"; $fullname=$_POST['fullname']; $mailid=$_POST['mailid']; $ph=$_POST['ph']; $date=$_POST['date']; $time=$_POST['time']; $error_message = ""; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message= "First Name : ".clean_string($fullname)."\n"; $email_message .= "Email Id : ".clean_string($mailid)."\n"; $email_message .= "Mobile : ".clean_string($ph)."\n"; $email_message .= "Date : ".clean_string($date)."\n"; $email_message .= "Time : ".clean_string($time)."\n"; // create email headers $headers = 'From: '.$mailid."\r\n". 'Reply-To: '.$mailid."\r\n" . 'X-Mailer: PHP/' . phpversion(); if(mail( $to ,$subject,$email_message,$headers)) { ?> alert ("Thankyou For Your Appointmet With !!"); window.location="../home.php?uname=";

We are not able to do a lot of code troubleshooting as that would require testing. We do not have your testing environment, so unless it is very obvious we could be incorrect at what we advise.

Your title mentions you get mailid from the database, but your code shows that it is coming from a POST. Also you set the $to=$email; but I see no place where $email is set to anything. I can only see the code presented here, but that is what I see.

You will need to print out your variables on the screen (var_dump or echo) and see if you are actually getting what you are expecting.

Kindest Regards,
Scott M