Help - Search - Members - Calendar
Full Version: Contact form error
HTMLHelp Forums > Programming > Server-side Scripting
pnwdude
Hi everyone. I’m trying to figure out what’s wrong with the coding of my contact form. My website is based off a template which came with positive reviews and no mention of errors with sending messages from the form. When I attempt to send a message it just results in a continuous loading symbol. Here’s the code (with my email address replaced with something generic). Thank you.

<?php

/************************
* Variables you can change
*************************/

$mailto = “example@email.com"; // Enter your mail addres here.
$name = ucwords($_POST['name']);
$subject = "Message from $name"; // Enter the subject here.
$email = $_POST['email'];
$message = $_POST['message'];

if(strlen($_POST['name']) < 1 ){
echo 'email_error';
}

else if(strlen($email) < 1 ) {
echo 'email_error';
}

else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $email)) {
echo 'email_error';
}

else if(strlen($message) < 1 ){
echo 'email_error';

} else {

// NOW SEND THE ENQUIRY

$email_message="\n\n" .
"Name: " .
ucwords($name) .
"\n" .
"Email: " .
$email .
"\n" .
"Comments: " .
"\n" .
$message .
"\n" .
"\n\n" ;

$email_message = trim(stripslashes($email_message));
mail($mailto, $subject, $email_message, "From: \"$vname\" <".$email.">\nReply-To: \"".ucwords($name)."\" <".$email.">\nX-Mailer: PHP/" . phpversion() );

}
?>
Christian J
Please post the HTML form that goes with the above script.
pnwdude
QUOTE(Christian J @ Jan 27 2017, 02:03 PM) *

Please post the HTML form that goes with the above script.
Is this the section you need? Sorry, still learning...

<div id="contactFormArea">
<!-- Contact Form Start //-->
<form action="#" id="contactform">
<fieldset>
<label>Name</label>
<input type="text" name="name" class="textfield" id="name" value="" />
<div class="clear"></div>
<label>E-mail</label>
<input type="text" name="email" class="textfield" id="email" value="" />
<div class="clear"></div>
<label>Subject</label>
<input type="text" name="subject" class="textfield" id="subject" value="" />
<div class="clear"></div>
<label>Message</label>
<textarea name="message" id="message" class="textarea" cols="2" rows="4"></textarea>
<div class="clear"></div>
<label> </label>
<input type="submit" name="submit" class="buttoncontact" id="buttonsend" value="Submit" />
<span class="loading" style="display: none;">Please wait..</span>
<div class="clear"></div>
</fieldset>
</form>

pnwdude
Appears to be working now. I guess the page needed to be loaded from my server rather than my pc.
pandy
I should work locally provided the script is on a server and that you have the URL to it instead of the hash sign here.

CODE
<form action="#" id="contactform">


On the other hand this curly quote should stop if from working.

CODE
“example@email.com";


But maybe that happened when you edited the email out for the forum. Don't use Word and the like.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.