PHP mail() function - email not sending but there are no errors

Status
Not open for further replies.

elitepet

New Member
Messages
24
Reaction score
0
Points
1
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):

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;
}
?>
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
That shouldn't be getting tagged as spam, but there is the ever-present possibility that your mails are stuck in a queue somewhere (perhaps behind a bunch of stuff that is spam. If the queue hasn't actually overflowed yet, you won't get a failure report back immediately. If you don't begin to receive the mails in the next few hours, please post back to this thread; we made need to get an admin to kick the server or something.
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
That shouldn't be getting tagged as spam, but there is the ever-present possibility that your mails are stuck in a queue somewhere (perhaps behind a bunch of stuff that is spam. If the queue hasn't actually overflowed yet, you won't get a failure report back immediately. If you don't begin to receive the mails in the next few hours, please post back to this thread; we made need to get an admin to kick the server or something.

Thanks for replying. I still haven't gotten the emails though.
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
That shouldn't be getting tagged as spam, but there is the ever-present possibility that your mails are stuck in a queue somewhere (perhaps behind a bunch of stuff that is spam. If the queue hasn't actually overflowed yet, you won't get a failure report back immediately. If you don't begin to receive the mails in the next few hours, please post back to this thread; we made need to get an admin to kick the server or something.

Emails still aren't sending with the PHP mail function.
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
I've removed you from the email blacklist, so you should be able to send emails again now (you were automatically added to the blacklist likely because of that programming error you mentioned). Just try to make sure it doesn't happen again :)
 

elitepet

New Member
Messages
24
Reaction score
0
Points
1
I've removed you from the email blacklist, so you should be able to send emails again now (you were automatically added to the blacklist likely because of that programming error you mentioned). Just try to make sure it doesn't happen again :)
Thank you :)
 
Status
Not open for further replies.
Top