Hello,
I'm trying to setup a basic contact form notification system on a website I'm making for somebody. It was working yesterday but due to an error in my script, it accidentally sent about 45 or 50 email notifications to my email address. Ever since then, I haven't been able to send anymore emails with the PHP mail() function.
I'm thinking it's being tagged as "spam" and being discarded. Is there a way to fix this? I've already edited the email body a little but it still isn't working.
Here's my code (I changed all the emails to "Test <test@test.com>" in this code for privacy reasons):
I'm trying to setup a basic contact form notification system on a website I'm making for somebody. It was working yesterday but due to an error in my script, it accidentally sent about 45 or 50 email notifications to my email address. Ever since then, I haven't been able to send anymore emails with the PHP mail() function.
I'm thinking it's being tagged as "spam" and being discarded. Is there a way to fix this? I've already edited the email body a little but it still isn't working.
Here's my code (I changed all the emails to "Test <test@test.com>" in this code for privacy reasons):
PHP:
<?php
include('config.php');
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$message = trim($_POST['message']);
$ref = trim($_GET['ref']);
$errors = array();
if(!isset($_POST['ajax'])) {
if($name == '' || $name == "Name") {
$errors[] = "Name is required.";
}
else if(strlen($name) < 3) {
$errors[] = "Name must be at least 3 characters long.";
}
if($email == '' || $email == "Email Address") {
$errors[] = "Email address is required.";
}
else if(!isValidEmail($email)) {
$errors[] = "Email address is not valid.";
}
if($phone == '' || $phone == "Phone Number") {
$errors[] = "Please enter your phone number.";
}
else if(!isValidPhone($phone)) {
$errors[] = "Please enter a valid phone number. <em>Ex: 810-555-5555</em>";
}
if($message == '' || strlen($message) < 20 || $message == "Message") {
$errors[] = "Please enter a message that is at least 20 characters long.";
}
if(!empty($errors)) {
$_SESSION['contact_msg'] = "Please fix the following errors:<ul>";
foreach($errors as $key => $val) {
$_SESSION['contact_msg'] .= '<li>' . $val . '</li>';
}
$_SESSION['contact_msg'] .= "</ul>
<style type='text/css'>
#main-box {
margin-top: 0;
}
</style>";
$_SESSION['contact_msg_type'] = 'error';
header("Location: $ref");
exit;
}
}
else {
if($name == '' || $name == 'Name') {
echo "Please enter your name.";
exit;
}
if(strlen($name) < 3) {
echo "Please enter at least three characters for \"Name\".";
exit;
}
if($email == '' || $email == 'Email Address') {
echo "Please enter your email address.";
exit;
}
if(!isValidEmail($email)) {
echo "Please enter a valid email address.";
exit;
}
if($phone == '' || $phone == 'Phone Number') {
echo "Please enter your phone number.";
exit;
}
if(!isValidPhone($phone)) {
echo "Please enter a valid phone number. <em>Ex: 810-555-5555</em>";
exit;
}
if($message == '' || strlen($message) < 20 || $message == 'Message') {
echo "Please enter a message that is at least 20 characters long.";
exit;
}
}
$to = "Test <test@test.com>";
$subject = "New Contact Form Submission";
$date = date("l, F j, Y \a\\t g:i A");
$body = "Hello,
There has been a new contact form submission on your website.
Here is the information about the message:
Name: $name
Email Address: $email
Phone Number: $phone
Date/Time Sent: $date
$name wrote:
$message
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
To send a reply to $name, just reply to this email notification.";
$headers = 'Content-type: text/plain' . "\r\n" .
'From: Test <test@test.com>' . "\r\n" .
'Reply-To: '.$email . "\r\n" .
'MIME-Version: 1.0' . " \r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers) or die("ERROR: Could not send email.");
if(isset($_POST['ajax'])) {
echo "success";
}
else {
$_SESSION['contact_msg'] = "Thanks! We will reply to you via email soon.";
$_SESSION['contact_msg_type'] = 'success';
header("Location: $ref");
exit;
}
?>