Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am trying to send contact form data to an email id. Page showing success message but i am not getting any email. And how can i receive all contact information in email box.

HTML ode for contact form:
HTML
<form method="post" action="sendEmail.php">
<div>
	
<div id="main">

<div class="comment1">
<p><input type="text" placeholder="your name..." name="name" id="name" /></p> 
</div>

<div class="comment2">
<p><input type="text" placeholder="your e-mail..." name="email" id="email" /></p> 
</div>

<div class="comment1">
<p><input type="text" placeholder="your suburb..." name="suburb" id="suburb" /></p> 
</div>

<div class="comment2">
<p><input type="text" placeholder="your mobile no..." name="mobile" id="mobile"/></p> 
</div>

<div class="comment1">
<p><input type="text" placeholder="prefer date...(dd/mm/yyyy)" name="date" id="date" /></p> 
</div>

<div class="comment2">
<p><input type="text" placeholder="prefer time...(hh/mm)" name="time" id="time" /></p> 
</div>

<div class="comment3">
<p><input type="text" placeholder="subject..." name="subject" id="subject"/></p> </div>


<div class="textarea">
<p><textarea placeholder="message..." name="comments" id="comments" rows="14" cols="5"></textarea></p>
</div>

<div class="buttoncontact">	
<p><input type="submit" name="submit" id="submit" value="Submit"/></p>
</div>


PHP code for sendEmail.php. I dont know where is problem

PHP
	$name = trim($_POST['name']);
	$email = $_POST['email'];
	$suburb = $_POST['suburb'];
        $mobile = $_POST['mobile'];
        $date = $_POST['date'];
        $time = $_POST['time'];
        $subject = $_POST['subject'];
        $comments = $_POST['comments'];

	
	$site_owners_email = 'owner@example.com'; // Replace this with your own hosting email address
	$site_owners_name = 'Test email'; // replace with your name

	
	if (strlen($name) < 2) {
		$error['name'] = "Please enter your name";	
	}
	
	if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
		$error['email'] = "Please enter a valid email address";	
	}
	if (strlen($suburb) < 3) {
		$error['suburb'] = "Please enter your suburb.";
	}

	if (strlen($mobile) < 10) {
		$error['mobile'] = "Please enter your mobile no. Only numerics!!";
	}

	if (strlen($date) < 3) {	
		$error['date'] = "Please enter your booking date.";
	}

	if (strlen($time) < 3) {
		$error['time'] = "Please enter your booking time.";
	}

        if (strlen($subject) < 2) {
		$error['title'] = "Please enter a subject";	
	} 
	if (strlen($comments) < 3) {
		$error['comments'] = "Please leave your message.";
	}
	
	if (!$error) {
		
		require_once('phpMailer/class.phpmailer.php');
		$mail = new PHPMailer();
		
		$mail->From = $email;
		$mail->FromName = $name;
		$mail->Subject = "Website Contact Form";
		$mail->AddAddress($site_owners_email, $site_owners_name);
		$mail->AddAddress('', '');
		$mail->Message = $comments;
		
		$mail->Mailer = "smtp";
		$mail->Host = "my host";
		$mail->Port = "port";
		$mail->SMTPSecure = "None";
		
		$mail->SMTPAuth = true; // turn on SMTP authentication
		$mail->Username = "my@email.com"; // SMTP username
		$mail->Password = "password"; // SMTP password
		
		$mail->Send(); 

		
		echo "<li class="success"> Congratulations, " . $name . ". We've received your email. We'll be in touch as soon as we possibly can! </li>";
		
	} # end if no error
	else {
		$response = (isset($error['name'])) ? "<li>" . $error['name'] . "</li> \n" : null;
		$response .= (isset($error['email'])) ? "<li>" . $error['email'] . "</li> \n" : null;
	        $response .= (isset($error['suburb'])) ? "<li>" . $error['suburb'] . "</li>\n" : null;
	        $response .= (isset($error['mobile'])) ? "<li>" . $error['mobile'] . "</li>\n" : null;
	        $response .= (isset($error['date'])) ? "<li>" . $error['date'] . "</li>\n" : null;
	        $response .= (isset($error['time'])) ? "<li>" . $error['time'] . "</li>\n" : null;
	        $response .= (isset($error['subject'])) ? "<li>" . $error['subject'] . "</li>\n" : null;
		$response .= (isset($error['comments'])) ? "<li>" . $error['comments'] . "</li>\n" : null;

		echo $response;
	} # end if there was an error sending

?>
Posted
Updated 18-Jan-14 4:17am
v2

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