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:
Sir,

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

PHP
<?php 
$errors = '';
$myemail = 'sukirti@domain.in';//<-----Put Your email address here.
$host = "smtp.domain.in";
 $myemail = "sukirti@domain.in";
 $password = "*********";
if(empty($_POST['userName'])  || 
   empty($_POST['userEmail']) || 
   empty($_POST['userMsg']))
{
    $errors .= "\n Error: all fields are required";
}

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

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $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";
	
	mail($to,$email_subject,$email_body,$headers);
	//redirect to the 'thank you' page
	header('Location: index.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>Contact form handler</title>
</head>

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


</body>
</html>






Please help on this.
Posted
Comments
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