So i have a contact form on wordpress using ajax, but it dont work.
Here is the contact form:
<form action="http://www.ruiavelino.pt/wp-admin/admin-ajax.php" id="appoint-form" method="post">
<p>
<label class="display-ie8" for="apo_name">Full Name</label>
<input type="text" name="apo_name" class="required" id="apo_name" placeholder="Full Name" title="* Please enter your Full Name" />
</p>
<p>
<label class="display-ie8" for="apo_phone">Phone Number</label>
<input type="text" name="apo_phone" class="required" id="apo_phone" placeholder="Phone Number" title="* Please enter your Phone Number" />
</p>
<p>
<label class="display-ie8" for="apo_email">Email Address</label>
<input type="text" name="apo_email" class="email required" id="apo_email" placeholder="Email Address" title="* Please enter valide Email Address" />
</p>
<p>
<label class="display-ie8" for="apo_date">Appointment Date</label>
<input type="text" name="apo_date" class="required" id="apo_date" placeholder="Appointment Date" title="* Please select desired appointment date" />
</p>
<p>
<label class="display-ie8" for="apo_date">Message</label>
<textarea name="message" class="message required" cols="30" rows="5" placeholder="Message" title="* Please enter your message"></textarea>
</p>
<div class="captcha-container">
<img src="http://www.ruiavelino.pt/wp-content/themes/healthpress-theme/captcha/appointment_captcha.php" alt=""/>
<input type="text" class="captcha required" name="captcha" maxlength="5" title="* Por favor insira os caracteres presentes na imagem!"/>
</div>
<p>
<input type="submit" value="Pedir Consulta" class="readmore">
<input type="hidden" name="action" value="request_appointment" />
<input type="hidden" name="target" value="geral@clinica.ruiavelino.pt" />
<img src="http://www.ruiavelino.pt/wp-content/themes/healthpress-theme/images/loading.gif" id="apo-loader" alt="Loader" />
</p>
<p id="apo-message-sent"></p>
<div class="error-container"></div>
</form>
And the functions in functions.php:
add_action( 'wp_ajax_nopriv_send_message', 'send_message' );
add_action( 'wp_ajax_send_message', 'send_message' );
function send_message()
{
if(isset($_POST['email'])):
if($_POST['captcha'] != $_SESSION['rand_code'])
{
echo "Wrong Code!";
die;
}
$name = $_POST['author'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$address = $_POST['target'];
if(get_magic_quotes_gpc()) {
$message = stripslashes($message);
}
$e_subject = __('You Have Received a Message From ','framework') . $name . '.';
if(!empty($subject))
{
$e_subject = $subject . ':' . $name . '.';
}
$e_body = __("You have Received a message from: ", 'framework')
.$name
. "\n"
."Phone: " . $phone
. "\n"
.__("Their additional message is as follows.", 'framework')
."\r\n\n";
$e_content = "\" $message \"\r\n\n";
$e_reply = __("You can contact ", 'framework')
.$name
. __(" via email, ", 'framework')
.$email;
$msg = $e_body . $e_content . $e_reply;
if(wp_mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n","-f $address"))
{
_e("Message Sent Successfully!", 'framework');
}
else
{
_e("Server Error: WordPress mail method failed!", 'framework');
}
else:
_e("Invalid Request !", 'framework');
endif;
die;
}