SendMail.php script not passing $phone value

I purchased a html templte from themeforest, and it comes with a form and script. The form asks for basic name, email, and comments. I added a phone field. The script runs, and it send out mail correctly. However, the body of the email does not contain the phone number, like it is not being passed through. I am not well versed in PHP, and the template author has no idea. Any help is much appreciated!

Here is my form code:

<form method="post" action="sendEmail.php"> <div> <div id="main"> <div class="contact1"> <p> <input type="text" placeholder="your name" name="name" id="name" class="commentfield" /> </p> </div> <div class="contact2"> <p> <input type="text" placeholder="your e-mail adress" name="email" id="email" class="commentfield" /> </p> </div> <div class="contact3"> <p> <input type="text" placeholder="your phone number" name="phone" id="phone" class="commentfield" /> </p> </div> <p> <textarea name="comments" placeholder="problem you are having" id="comments" rows="12" cols="5" class="textarea"></textarea> </p> <div class="buttonmain1"> <p> <input type="submit" name="submit" class="buttontextmain1" id="submit" value="Get Help Now" /> </p> </div> <ul id="response"></ul> </div> </div> </form>

And here is the SendMail.php:

[php]<?php

$name = trim($_POST['name']);
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];

$site_owners_email = '[email protected]'; // Replace this with your own hosting email address
$site_owners_name = 'Dr. Blank'; // 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 (!preg_match('/^\(?[0-9]{3}\)?|[0-9]{3}[-. ]? [0-9]{3}[-. ]?[0-9]{4}$/', $phone)) { 

	$error['phone'] = "Please enter your phone number";	
}

if (strlen($comments) < 3) {
	$error['comments'] = "Please tell us what the problem is.";
}

if (!$error) {
	
	require_once('phpMailer/PHPMailerAutoload.php');
	$mail = new PHPMailer();
	
	$mail->FromName = $name;
	$mail->Subject = "Website LANDING PAGE (AdWords) Contact Form";
	$mail->AddAddress($site_owners_email, $site_owners_name);
	$mail->AddAddress('', '');
	$mail->Body = "Name: ".$_POST['name']."\r\n"."Email: ".$_POST['email']."\r\n"."Phone: ".$phone."\r\n"."Comments: ".$_POST['comments'];
	
			
		$mail->IsSMTP();
	$mail->Host = "mail.domain.com";
	 $mail->Port = 26;
	 $mail->SMTPSecure = "tls"; 
	
	$mail->SMTPAuth = true; // turn on SMTP authentication
	$mail->Username = "[email protected]"; // SMTP username
	 $mail->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['phone'])) ? "<li>" . $error['phone'] . "</li> \n" : null;
	$response .= (isset($error['comments'])) ? "<li>" . $error['comments'] . "</li>" : null;
	
	echo $response;
} # end if there was an error sending

?>[/php]

I have also tried thos code, but the output is still blank where the phone number should be:

[php] $mail->Body = “Name: “.$_POST[‘name’].”\r\n”.“Email: “.$_POST[‘email’].”\r\n”.“Phone: “.$_POST[‘phone’].”\r\n”."Comments: ".$_POST[‘comments’];
[/php]

For shits and giggles, modify this like $mail->Body to this,

[php]$mail->Body = print_r( $_POST, true);[/php]

I actually got it working, but thanks so much for taking the time to reply!

There was a JS script which did the post, and the $phone variable was not added in correctly. Once added, it brought the value over just fine.

Thanks again!

Chris

I would have figured a JavaScript submission would have dropped the action in the form, but I guess the designer left it in.

Sponsor our Newsletter | Privacy Policy | Terms of Service