Hi guys,
Hope you can help. I've moved a word press site from one cPanel host to another. Since doing so the contact form doesn't work. The PHP versions are the same, with similar modules and php settings.
The issue is, the form appears to send properly from the site, but the email never actually arrives. I tried changing the email its sending to, to a gmail account, a hotmail etc.
To make sure the server use the mail() function i did the below and received the email straight away:
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "
[email protected]";
$to = "
[email protected]";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>
Here is the code to process the contact form, I've changed the email address for obvious reasons! Also, the eregi function is deprecated but not sure how to replace it with the new email validation function, if someone could help with that too that'd be awesome. I removed the eregi check to ensure that wasn't causing the issue just FYI.
<?php
if(trim($_POST['checking']) !== ''){
$capchaError = true;
} else {
if(trim($_POST["name"]) === ''){
$formError = true;
} else {
$name = trim($_POST['name']);
}
if(trim($_POST["email"]) === '') {
$formError = true;
} elseif (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST["email"]))) {
$formError = true;
} else {
$email = trim($_POST['email']);
}
if(trim($_POST["number"]) === '') {
$formError = true;
} else { // validate phone to be either 10 or 11 digits
$number = trim($_POST["number"]);
$pattern = "/(((\+44)? ?(\(0\))? ?)|(0))( ?[0-9]{3,4}){3}/"; // allows for numbers 8 - 12 digits in length, starting 0 or +44
$match = preg_match($pattern,$number);
if ($match === 0) { // if validation fails
$formError = true;
} else { // if valiudation passes
$phone = trim($_POST["number"]);
}
}
if(trim($_POST["subject"]) === ''){
$formError = true;
} else {
$msgSubject = trim($_POST['subject']);
}
if(trim($_POST["message"]) === '') {
$formError = true;
} else {
if(function_exists("stripslashes")) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
if($formError !== true) {
$email_to = "
[email protected]";
$subject = "Message from the website";
$message = 'Name: '. $name . "\n\nPhone: " . $phone . "\n\nEmail: " . $email . "\n\nSubject: " . $msgSubject. "\n\nMessage: " . $comments;
$headers = 'From: '.$name.' <'.$email.'>';
mail($email_to, $subject, $message, $headers);
$sent = true;
}
if(isset($sent) && $sent == true) {
header("Location: /thank-you/");
} else {
header("Location: /message-not-sent/");
}
}
if($capchaError == true) {
header("Location: /message-not-sent/");
}
?>
The code for the form on the contact page is as follows (some details changed again):
<form action="http://www.site.co.uk/wp-content/themes/site/php/contactprocess.php" id="contact" method="post" class="threeQuarter">
<input type="text" id="name" name="name" placeholder="Name" required>
<input type="email" id="email" placeholder="Email" name="email" required>
<input type="tel" id="number" placeholder="Number" name="number" required>
<input type="text" id="subject" placeholder="Subject" name="subject" required>
<textarea id="message" placeholder="Message" name="message" required></textarea>
<span id="screenReader">Spam Protection - <i>Do not enter anything in this field</i>
<input type="text" name="checking" class="checking" placeholder="Ignore" value="" />
</span>
<button class="button fifth" name="serviceFormOne" type="submit">Send</button>
</form>
Thanks for any help.