$5 to whoever can fix my Contact Form

Ascent

Seasoned Veteran
Joined
Sep 29, 2008
Messages
4,880
Reaction score
7
FP$
0
I have a Contact Form on the homepage of my WordPress website.

The 'Send' button doesn't do anything.

Below is the code we're using.

contact_process.php:

Code:
<?php

include dirname(dirname(__FILE__)).'/mail.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{

$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
//$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);


$error = '';

// Check name

if(!$name)
{
$error .= 'Please enter your name.<br />';
}

// Check email

if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}

// Check message (length)

if(!$message || strlen($message) < 10)
{
$error .= "Please enter your message. It should have at least 10 characters.<br />";
}


if(!$error)
{
$mail = mail(CONTACT_FORM, 'Contact form by: '.$name, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());


if($mail)
{
echo 'OK';
}

}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}

}
function ValidateEmail($value)
{
$regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i';

if($value == '') { 
return false;
} else {
$string = preg_replace($regex, '', $value);
}

return empty($string) ? true : false;
}
?>

mail.php:

Code:
<?php
// Where will you get the forms' results?
define("CONTACT_FORM", '[email protected]');
?>

And here's the corresponding code placed on my homepage:

Code:
<div class="slide" id="slide5" data-slide="5" data-stellar-background-ratio="0.5">
	<div class="container clearfix">
		<h1><span><?php echo $data['contact_us_heading']; ?></span></h1>
        <div class="page_excerpt"><?php echo nl2br(stripslashes($data['contact_us_text'])); ?></div>
		<div class="contact_block">
			<div class="grid_12">
				<div class="contact_form">  
					<div id="note"></div>
					<div id="fields">
						<form id="ajax-contact-form" action="">
							<span class="float_left"><input type="text" name="name" value="" placeholder="Name" /></span>
                            <span class="float_right"><input type="text" name="email" value="" placeholder="Email" /></span>
                            <div class="clear"></div>
							<textarea name="message" id="message" placeholder="Message"></textarea>
							<div class="clear"></div>
							<input type="reset" class="contact_btn" value="Clear Form" />
							<input type="submit" class="contact_btn send_btn" value="Send" />
							<div class="clear"></div>
						</form>
					</div>
				</div>
			</div>
			<div class="clear"></div>
		</div>

	</div>
	
</div>

Question is - why isn't my 'Send' button functioning? It does nothing when I click on it.

I'll pay $5 USD via PayPal to whoever can figure this one out.

Thanks.
 
Is this hosted on a VPS? If so have you installed the mail-server package as it will be required to send PHP-Mail through SMTP.
 
No, it's on shared hosting.

I already have installed the famous "WP-Mail-SMTP" plugin. Still doesn't work. =(
 
You haven't defined an action so it's not connecting to a script meaning its not being told to do anything when the button is pressed. In <form action="" within the "" the execution file should be listed, in your case contact_process.php
 
Tindris said:
You haven't defined an action so it's not connecting to a script meaning its not being told to do anything when the button is pressed. In <form action="" within the "" the execution file should be listed ex. Submit.php

So where exactly would I make this change? And what do I put?
 
Where you define the form you need te action="" to link to a file which tells the form what todo when submit is pressed, ex. PHP commands for the smtp mail. Or use HTML emailing instead, I can't write the code for you, I'm on a mobile device unfortunately
 
The change I made is bolded. Still didn't work though.

<div class="slide" id="slide5" data-slide="5" data-stellar-background-ratio="0.5">
<div class="container clearfix">
<h1><span><?php echo $data['contact_us_heading']; ?></span></h1>
<div class="page_excerpt"><?php echo nl2br(stripslashes($data['contact_us_text'])); ?></div>
<div class="contact_block">
<div class="grid_12">
<div class="contact_form">
<div id="note"></div>
<div id="fields">
<form id="ajax-contact-form" action="contact_process.php">
<span class="float_left"><input type="text" name="name" value="" placeholder="Name" /></span>
<span class="float_right"><input type="text" name="email" value="" placeholder="Email" /></span>
<div class="clear"></div>
<textarea name="message" id="message" placeholder="Message"></textarea>
<div class="clear"></div>
<input type="reset" class="contact_btn" value="Clear Form" />
<input type="submit" class="contact_btn send_btn" value="Send" />
<div class="clear"></div>
</form>
</div>
</div>
</div>
<div class="clear"></div>
</div>

</div>

</div>
 
You need to make one final change, you need to define a method in your form, in this case post.
The change is below, I have bolded it for you.

<div class="slide" id="slide5" data-slide="5" data-stellar-background-ratio="0.5">
<div class="container clearfix">
<h1><span><?php echo $data['contact_us_heading']; ?></span></h1>
<div class="page_excerpt"><?php echo nl2br(stripslashes($data['contact_us_text'])); ?></div>
<div class="contact_block">
<div class="grid_12">
<div class="contact_form">
<div id="note"></div>
<div id="fields">
<form id="ajax-contact-form" action="contact_process.php" method="post">
<span class="float_left"><input type="text" name="name" value="" placeholder="Name" /></span>
<span class="float_right"><input type="text" name="email" value="" placeholder="Email" /></span>
<div class="clear"></div>
<textarea name="message" id="message" placeholder="Message"></textarea>
<div class="clear"></div>
<input type="reset" class="contact_btn" value="Clear Form" />
<input type="submit" class="contact_btn send_btn" value="Send" />
<div class="clear"></div>
</form>
</div>
</div>
</div>
<div class="clear"></div>
</div>

</div>

</div>
 
Still doesn't work. =( I think something is wrong with the 'Send' button.
 
Ascent said:
>
<div class="page_excerpt"><?php echo nl2br(stripslashes($data['contact_us_text'])); ?></

Can you give me a link to your contact form?
 
The other thing that could be the problem is the action, if the files are not in the same directory then it won't be able to find the file.

Try putting your whole path in the action directory. It will look something like this: /home/cpanelusernamehere/public_html/path/to/file/contact_process.php

Change cpanelusernamehere to the username you use to login to your web control panel. Change path/to/file to the folder structure to get to the folder that contact_process.php is located (So if it is in a folder called contact in a folder called includes it would be something like public_html/includes/contact/contact_process.php)
I hope that is easy enough for you to understand that, it is 3am where I am 😉
 
Code:
    <?php
    // Where will you get the forms' results?
    define("CONTACT_FORM", '[email protected]');
    ?>

You need to fill out the mail.php file, you need to add your e-mail.
 
What Kindle says. You may want to try posting a error code or ok in the code to see if it's working or not. If it posts an ok, It means that your email in the code is just plain wrong. If there's an error, it will tell you the particular error.
 
Back
Top Bottom