Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have added the below code to send mail in php. But i didnt received any mail from contact form.

$errors = '';
$myemail = '';//<-----Put Your email address here.
$host = "";
 $myemail = "";
 $password = "*********";
if(empty($_POST['userName'])  || 
   empty($_POST['userEmail']) || 
    $errors .= "\n Error: all fields are required";

$name = $_POST['userName']; 
$email_address = $_POST['userEmail']; 
$message = $_POST['userMsg']; 

if (!preg_match(
    $errors .= "\n Error: Invalid email address";

if( empty($errors))
	$to = $myemail; 
	$email_subject = "Contact form submission: $name";
	$email_body = "You have received a new message. ".
	" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; 
	$headers = "From: $myemail\n"; 
	$headers .= "Reply-To: $email_address";
	//redirect to the 'thank you' page
	header('Location: index.html');
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""> 
	<title>Contact form handler</title>

<!-- This page is displayed only if there is some error -->
echo nl2br($errors);


Please help on this.
Richard MacCutchan 2-Oct-15 8:00am    
Google will find you many samples of sending email from browsers. Check that your parameters are correct, and that the SMTP server accepts your mail requests.
SukirtiShetty 2-Oct-15 8:12am    
As it doesnot showed me any error and I have configured smtp in Php.ini file
Richard MacCutchan 2-Oct-15 10:05am    
You can configure what you like in Php.ini, but if the server does not accept your mail request it will not work. The issue needs you to do somediagnosis to find out whether the message actually gets accepted by the server, and sent on. And whether your spam filter is rejecting it.
Did you debug?
SukirtiShetty 3-Oct-15 0:01am    
As i am new in PHP can you please help me on this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900