Contact Form Not Working

Hello,

I’m designing a website for a client and it’s a mobile template from ThemeForest actually. The form is extremely simple but I can’t figure out why it won’t work. Originally it didn’t have the phone number field so I had to add that. Here’s the code.

<form id="contact_form" method="post" action="php/sendmail.php">
			<p>
				<label for="name">Name</label>
				<input type="text" id="name" name="name" />
			</p>
			<p>
				<label for="phone">Phone</label>
				<input type="text" id="phone" name="phone" />
			</p>
			<p>
				<label for="email">Email</label>
				<input type="email" id="email" name="email" />
			</p>
			<p>
				<label for="text">Message</label>
				<textarea id="text" name="text" rows="5" cols="3"></textarea>
			</p>
			<button type="submit" class="button form_submit">Send email</button>
		</form>
<?php
	
	if(($_POST["name"])&&($_POST["phone"])&&($_POST["email"])&&($_POST["text"])) { 
	
		$email_subject = 'You have a new letter from ' . $_POST["name"];
		$email_body    = '<p>From: <b>' . $_POST["name"] . '</b></p><p>' . $_POST["text"] . '</p>';
		$email_headers .= 'Content-type: text/html; charset=utf-8' . "\\r\
";
		$email_headers .= 'From: '. $_POST["email"] . " \\r\
"; 
		
		mail('email@gmail.com', $email_subject, $email_body, $email_headers);
	
	}

?>

I think there is some code that needs to be added for the phone number in the PHP file. Could that be why it’s not working? Using another email address it did receive, but it came way late and the information wasn’t complete.

Thanks for any help.

Define ‘wont work’. You’ve just visited the doctor, handed him an x-ray, and haven’t told him what’s wrong with you. :stuck_out_tongue:

Need some symptoms. Does the page change? does the form not load? Does it run but not send an email?

Hi,

Thanks for the response. The website is: CGrafiks Computer Service Center Crossville, TN if you want to take a look. It seems to be working now, however, I think I have some incorrect values as the information comes back like:

From: James Baker

Hello

The phone number and email does not show. I’m guessing I need to change a few things in the PHP file.

Here was the original code before I modified it:


<?php
	
	if(($_POST["name"])&&($_POST["email"])&&($_POST["text"])) { 
	
		$email_subject = 'You have a new letter from ' . $_POST["name"];
		$email_body    = '<p>From: <b>' . $_POST["name"] . '</b></p><p>' . $_POST["text"] . '</p>';
		$email_headers .= 'Content-type: text/html; charset=utf-8' . "\\r\
";
		$email_headers .= 'From: '. $_POST["email"] . " \\r\
"; 
		
		mail('mail@gmail.com', $email_subject, $email_body, $email_headers);
	
	}

?>


I’m just wanting to include a phone number. Thanks for the help.


       $email_body    = '<p>From: <b>' . $_POST["name"] . '</b></p><p>' . $_POST["text"] . '</p>';

Well, nowhere in that line does the phone # or email appear; so… yeah, it wont be in the email unless you put it in the email…

StarLion,

I’m not all that familiar with PHP. If there’s anyway you could provide some advice with the modifications to include the phone that would be a great help.

I’m gonna dangle the carrot here a bit, please dont feel like i’m trying to be dense or patronizing here.

If you’ve done HTML work, you can look at that line and tell where the paragraph containing the ‘text’ field begins and ends. Repeat that for the ‘email’ and ‘phone’ fields, and you should have your outcome.

(Insert line about ‘try it yourself and see what you get’ here)