With an HTML contact form such as
HTML contact form
<h1>Contact Form</h1>
<p>Please fill in the following details and click on SEND.</p>
<form action="mail_contact.php" method="POST">
<p>Name<br> <input type="text" name="name"></p>
<p>Email Address<br> <input type="email" name="email"></p>
<p>Message<br><textarea name="message" rows="6" cols="50"></textarea><br>
<input type="submit" value="Send"><input type="reset" value="Clear"></p>
</form>
I am trying to stop spam messages getting through by checking for certain words being used in the message.
I have a .txt file which has words I want to filter for such as
File: spamwords.txt
CAN-SPAM
SEO
keywords
Keywords
In the PHP coding I have
mail_contact.php
<?php
// Create Variables
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Function to deal with errors
function died($error) {
echo 'We are very sorry, but there were error(s) found with the form you submitted.';
echo 'These errors appear below.<br><br>';
echo $error.'<br>';
echo 'Please press <b>back</b> and fix these errors.';
die();
}
// Validate email address
$error_message = "";
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message .= 'The email address you entered does not appear to be valid.<br>';
}
if(strlen($error_message) > 0) {
died($error_message);
}
// Prevent spammers from using contact form
//Create an array containing the words in the message
$MessageArray = explode(" ", $message);
//Get SPAM words from file and store them in an array
$SpamWords = file_get_contents('/spamwords.txt');
$SpamArray = explode("\r\n", $SpamWords);
//Cycle through all the words in the message
foreach($MessageArray as $word){
//Check the word for SPAM words, if it is don't send the email
if(in_array($word, $SpamArray)){
echo '<h1>Spam Guard</h1>';
echo '<p>Here in European Community, the Privacy and Electronic Communications Regulations 2003 cover the sending of email marketing. This legislation says that organisations must only send marketing emails to anyone if they have agreed to receive them, except where there is a clearly defined customer relationship.</p>';
echo '<p>It appears that you are attempting to send an unsolicited message (e.g. a marketing message).</p>';
echo '<p>We as an organisation do not send unsolicited messages and we request that you do the same for us.</p>';
echo '<p>If you are not attempting to send an unsolicited message, there may be an error in the system so please accept our apologies.</p>';
die();
}
}
//If we've made it to this point, our message doesn't contain any obvious SPAM words
// Formulate Email
$formcontent='Message: \n $message \n \n From: $name $email';
$recipient = << my email address >>;
$subject = 'Contact Form Message';
$mailheader = 'From: $name <$email> \r\n';
mail($recipient, $subject, $formcontent, $mailheader) or die('Error!');
echo 'Thank you for contacting us. We will be in touch with you very soon via your email address<br>' . $email;
?>
When I test this out with a message containing the word SEO for example SEO test message it should display the Spam Guard message to the visitor - hence the echo commands - and then not send the email to me, but it displays the thank you message and sends me the email.
Can anyone see where I have gone wrong as it has stumped me
[Additional Note]
I have been using a CAPTCHA mechanism but some still get through
Your explode function needs double quotes around its delimiter:
$SpamArray = explode("\r\n", $SpamWords);
With single quotes, explode will attempt to split on the \r\n literal.
Or you could use file() instead of filter_get_contents() which will return the file as an array, with each line per key. trim() each line that's returned and you have your resulting array:
$SpamArray = array_map("trim", file('/spamwords.txt'));
Eureka!!!
I had to take the forward slash out of $SpamWords = file_get_contents('/spamwords.txt');
mail_contact.php [Edited]
<?php
// Create Variables
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Function to deal with errors
function died($error) {
echo 'We are very sorry, but there were error(s) found with the form you submitted.';
echo 'These errors appear below.<br><br>';
echo $error.'<br>';
echo 'Please press <b>back</b> and fix these errors.';
die();
}
// Validate email address
$error_message = "";
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message .= 'The email address you entered does not appear to be valid.<br>';
}
if(strlen($error_message) > 0) {
died($error_message);
}
// Prevent spammers from using contact form
//Create an array containing the words in the message
$MessageArray = explode(" ", $message);
//Get SPAM words from file and store them in an array
$SpamWords = file_get_contents('spamwords.txt');
$SpamArray = explode("\r\n", $SpamWords);
//Cycle through all the words in the message
foreach($MessageArray as $word){
//Check the word for SPAM words, if it is don't send the email
if(in_array($word, $SpamArray)){
echo '<h1>Spam Guard</h1>';
echo '<p>Here in European Community, the Privacy and Electronic Communications Regulations 2003 cover the sending of email marketing. This legislation says that organisations must only send marketing emails to anyone if they have agreed to receive them, except where there is a clearly defined customer relationship.</p>';
echo '<p>It appears that you are attempting to send an unsolicited message (e.g. a marketing message).</p>';
echo '<p>We as an organisation do not send unsolicited messages and we request that you do the same for us.</p>';
echo '<p>If you are not attempting to send an unsolicited message, there may be an error in the system so please accept our apologies.</p>';
die();
}
}
//If we've made it to this point, our message doesn't contain any obvious SPAM words
// Formulate Email
$formcontent='Message: \n $message \n \n From: $name $email';
$recipient = << my email address >>;
$subject = 'Contact Form Message';
$mailheader = 'From: $name <$email> \r\n';
mail($recipient, $subject, $formcontent, $mailheader) or die('Error!');
echo 'Thank you for contacting us. We will be in touch with you very soon via your email address<br>' . $email;
?>
Check this out, it will be useful
Spam Word Blocker PHP
You can generate random variable name and random value for hidden input and save in session. After form submitting you can check they in $_REQUEST var. Also you can use interval between form rendering and submitting. Don't try to check spam words just protect from bots and don't use simple captcha.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
So have a single form which only gets the email of the person and sends it to the email address I assigned. But I guess I wrote the code in a wrong way since I am getting errors. I have seen other stackoverflow problems but I am not sure why this isnt working.
This is the form in html.
<form style="margin-bottom:50px;" name="contactform" action="contact-form-handler.php" class="news-letter "method="post">
<div class="subscribe-hide">
<input type="text" name="email" class="form-control" placeholder="Email Address" >
<button type="submit" class="btn"><i class="fa fa-envelope"></i></button>
</div><!-- /.subscribe-hide -->
</form><!-- /.news-letter -->
and here is the PHP code in a different file.
<?php
$errors = '';
$myemail = 'masnadhossain#live.com';
empty($_POST['email']))
{
$errors .= "\n Error: all fields are required";
}
$email_address = $_POST['email'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission";
$email_body = "You have received a new message. ".
" Here are the details:".
"Email: $email_address\n ";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
The error I get is server error 500
Your code have syntax error pleas check it.
Line no 3 should be:
if (empty($_POST['email']))
{
$errors .= "\n Error: all fields are required";
}
1.) The first problem you have is that you are sending the email address from a form input via post but you did not utilize it.
2.) To and From variables are having the same email address masnadhossain#live.com which is creating conflicts
3.) The Preg_Match for checking Email address validity is errorneous. I have re-written your code below.
If you are posting the users email(eg gmail,yahoomail etc) from a form input, this code will get you going.
In case you want to intialize the email within the code just change
$email_address = strip_tags($_POST['email']);
to may be
$email_address = 'user1#gmail.com';
Finally, the From variable must be the email address pointing to your website address. in this case I think it is masnadhossain#live.com
This code is working. please mark it as correct answer if it solve your problem....
<?php
//Users email address coming from form input eg. gmail,yahoomail etc.
$email_address = strip_tags($_POST['email']);
//validate the email address
$email_val= filter_var($email_address, FILTER_VALIDATE_EMAIL);
if (!$email_val){
echo "<font color=red><b>Invalid Email Address</b></font>";
exit();
}
$to=$email_val;
$subject = "Contact form submission";
$message = "Here is the message;
// set the from variable to any email pointing to your website
$from = "masnadhossain#live.com";
$headers = "From:" . $from;
$sent=mail($to,$subject,$message,$headers);
if($sent) {
print "<br><font color=green><b>Your mail was sent Successfully</b></font>";
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
} else {
print "<br><font color=orange><b>We encountered an error sending your mail.</b></font>";
}
?>
I need my contact form on my website to be adjusted. It's a PHP/Ajax Contact Form.
Currently i have a problem - When a client fills out my contact form NAME - EMAIL - SUBJECT - MESSAGE there is an issue with my DREAMHOST Server due to their new anti spam policy and i dont receive some messages - If their email is #hotmail.com that's fine. But if their email is #gmail.com i dont get the message etc.
DREAMHOST TELLS ME:
Thanks for contacting Tech Support I checked the logs for the form on your site and did see that the emails are being bounced by the server due to recently implemented anti spam policies which won't allow email sent from the server using non-Dreamhost outgoing servers or "send from" email addresses. You can read more details on this policy here:
http://wiki.dreamhost.com/Sender_Domain_Policy_and_Spoofing
Your mail form uses the visitor's email address as the 'From' address which in most cases is not a Dreamhost hosted email address. Due to the spam policy above, the server will block mail being sent off the server if the email addresses are not using Dreamhost mail servers. So what you will need to do is either set the mail form to use your Dreamhost hosted address as the 'From' address.
Or you will need to find another mail form that will allow you to set a fixed email address as the 'From' address. This way you can set a Dreamhost hosted email address in the form as the 'From' address.
THE CODE AS FOLLOWS:
<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/
include dirname(dirname(__FILE__)).'/config.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
include 'functions.php';
$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) < 15)
{
$error .= "Please enter your message. It should have at least 15 characters.<br />";
}
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $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>';
}
}
?>
All i need to know is what i need to do to the code so i can receive all submissions of my contact form. I would really be grateful if someone could help.
Replace the following:
mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
with just:
$mail = mail(WEBMASTER_EMAIL, $subject, $message,"X-Mailer: PHP/" . phpversion());
and add the user's email address to your message if you need to. What you are doing right now is called spoofing and even when well-intentioned, you are essentially committing fraud. It would be the equivalent of someone calling you to show interest in your product and you taking down their physical address and putting that in the upper-left corner of an envelope and then sending yourself a letter saying that the caller is interested. In addition to this just being a fairly-odd way of doing things, it also suggests an electronic paper trail that suggests the user actually emailed you, which they did not. I personally would be uncomfortable finding out my email address was used in this way after filling out an online form.
I have built a website and I want to have an e-mail contact form on the web page, so that someone can send me a message.
I am using the code from this website: http://www.w3schools.com/php/php_secure_mail.asp
I am using the part that says PHP Stopping E-mail Injections
Even though my site gets very few hits per day (like less than 10 visitors) I am finding that I am getting 3 or 4 messages every day from "spammers" who just seem to be sending me random messages that are not related to the subject matter of the website.
I am fairly new to all this, so I would like to ask the question: Why is my PHP e-mail form attracting Spam and what can I do to stop it?
Ideally I would like to make it as easy as possible for the real users to contact me, and I would prefer it if I didn't have to use a CAPTCHA if possible.
Thanks so much
Code I am using:
<html>
<body>
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['email']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("someone#example.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
}
else
{//if "email" is not filled out, display the form
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text'><br>
Subject: <input name='subject' type='text'><br>
Message:<br>
<textarea name='message' rows='15' cols='40'>
</textarea><br>
<input type='submit'>
</form>";
}
?>
There is a simple way to get rid of most spammers:
output an input field inside your form that as display: none; as a style. Ideally that is specified in an external css file.
Put that input field inside your form and give it an important name, like "name2" or something.
Then, when eveluating input, discard all requests that have avalue inside that field, as a real user can not see and and thus can't enter a value. Whereas spam bots most likely fill all fields they find on a page.
I'm using a PHP form to forward data to an email address. Everything seems to work fine except the the error message ["You have not entered an email"] appears when the page is loaded, before any input from the user is entered, rather than through validation when submitted.
The form is here http://www.soulwatt.com/contact.php
Note: I found this PHP code online after doing a search on how to forward data to email, so it is not mine. Please excuse the lack of proper code formatting.
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "soulwatt.com Contact Data!!";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Comments"} = "Comments";
$body = "Soul Watt has received the following information:\n\n";
foreach($fields as $a => $b) {
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
$headers2 = "From: noreply#soulwatt.com";
$subject2 = "Thank you for contacting Soul Watt!";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.soulwatt.com";
if($from == '') {
print "You have not entered an email. Please enter your email and try again.";
}
else {
if($name == '') {
print "You have not entered a name.<br />Please enter your name and try again.";
}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send) {
print "<p><span>THANK YOU FOR CONTACTING US!</span></p>";
print "<p><span>Someone will get back to you as soon as possible, usually within 48 hours. If you need immediate assistance regarding booking Soul Watt, please call Randy at (828) 729-3199.</span></p>";
}
else {
print "<p><span>We encountered an error sending your mail, please notify webmaster#soulwatt.com</span></p>";
}
}
}?>
Thanks for your help!
These 2 lines:
$from = $_REQUEST['Email'] ;
if($from == '') {
print "You have not entered an email. Please enter your email and try again.";
}
Mean that you check the email request (POST and GET) key. The first time you load this page this WILL be empty. You could add a check if there was a POST at all, for instance if there was submitted.
To be honest, there might a lot of problems with your code: a user can add all sorts of stuff in there, probably even add stuff in the headers to add 'to' fields and all.. You might be making a spam-machine here. This part: $headers = "From: $from"; just adds the request field FROM in your headers....
You'd want to wrap your validation section in
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
... do validation here ...
}
... print form here ...
That will only run the validation code AFTER you submit the form. As it stands now, it's running each time the page is loaded, so of course there's no form data to validate the first time around.
Does your form fields have the same name that you're checking?
I mean for
$from = $_REQUEST['Email'];
You should have
<input type='text' name='Email' /> <!-- Note the Capital E -->
I add my comments here:
Use $_POST or $_GET. Avoid $_REQUEST. That way you've more controll over your app.
Also, don't check emptiness with =="" try empty($from)
OK So if the form is on http://www.soulwatt.com/contact.php and you have
<form method="post" action="contact.php" name="contact_form" id="contact_form">
action="contact.php" : That means it is proccessing the form on the same address so you will see the results of the form processing on the same page, and since the form is empty, and you're checking it regardless of it having been posted or not, you get that error
The following code sends me an email holding the following variables. One of the last if statements says if(mail) then echo "You will be contacted soon". When the script runs I get echoed back "You will be contacted soon", however, I never receive an email.
I do have a smaller contact script (posted after this first and larger one) that does work.
Note: contants.php and functions.php are both included and work fine
WEBMASTER_EMAIL is defined in contanstants.php and is correct, because
my smaller contact script uses the same variable, and emails me fine.
Thanks for the help
<?php
// pull constant variables
include("php/constants.php");
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post) {
include ("php/functions.php");
}
// general info
$name = stripslashes($_POST['contact']);
$phone = $_POST['phone'];
$email = trim($_POST['email']);
$time_to_reach = $_POST['time-to-reach']; // what the best time to reach them?
// delivery info
$delivery_address = $_POST['del-address'];
$delivery_city = $_POST['del-city'];
$delivery_state = $_POST['del-state'];
$delivery_zip = $_POST['del-zip'];
// moving city info if applicable
$moving_address = $_POST['move-address'];
$moving_city = $_POST['move-city'];
$moving_state = $_POST['move-state'];
$moving_zip = $_POST['move-zip'];
// date needed
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
// how long do you need the storage?
$storage_length = $_POST['time-length'];
// how many containers do you need?
$quantity_containers = $_POST['number-of-containers'];
// how did you hear about us?
$tracker = $_POST['tracker'];
// message
$message_holder = htmlspecialchars($_POST['message']);
$error = '';
// check general info
if(!$name) { $error .= 'Please enter your name.<br />'; }
if(!$email) { $error .= 'Please enter an e-mail address.<br />'; }
if($email && !ValidateEmail($email)) { $error .= 'Please enter a valid e-mail address.<br />'; }
if(!$time_to_reach) { $error .= 'Please select the best time to reach you.<br />'; }
// check delivery info
if(!$delivery_address) { $error .= 'Please enter you current address.<br />'; }
if(!$delivery_city) { $error .= 'Please enter your current city.<br />'; }
if(!$delivery_state) { $error .= 'Please enter your current state.<br />'; }
if(!$delivery_zip) { $error .= 'Please enter your current zip code.<br />'; }
// check date needed
if(!$month) { $error .= 'Please enter the approximate date you need the storage.<br />'; }
if(!$day) { $error .= 'Please enter the approximate date you need the storage.<br />'; }
if(!$year) { $error .= 'Please enter the approximate date you need the storage.<br />'; }
// check length of time needed
if(!$storage_length) { $error .= 'Approximatly how long will you need the storage unit for?<br />'; }
// check quantity of storages
if(!$quantity_containers) { $error .= 'How many containers will you need?<br />'; }
// check advertising tracker
if(!$tracker) { $error .= 'Please let us know how you\'ve heard of us.<br />'; }
// check message (length)
if(!$message_holder || strlen($message_holder) < 10) {
$error .= "Please enter your message. It should have at least 10 characters.<br />";
}
// build email message
$message = "Name: {$name}
Phone: {$phone}
Email: {$email}
Best time to reach: {$time_to_reach}\n
-----------------------------------------------------
Delivery address: {$delivery_address}
{$delivery_city}, {$delivery_state} {$delivery_zip}
Moving address: {$moving_address}
{$moving_city}, {$moving_state} {$moving_zip}
-----------------------------------------------------
Date needed: {$month}/{$day}/{$year}
Length of time needed: {$storage_length}
Number of containers: {$quantity_containers}
Where did you hear about us?
{$tracker}\n
Message: {$message_holder}\n";
if(!$error) {
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: residential-quote#stocor.com\r\n"
."Reply-To: ".$name."<".$email.">\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail) {
echo '<p>Thank you, you will be contacted soon.</p>';
}
} else {
echo '<div class="notification_error">'.$error.'</div>';
}
?>
The following script, contact script, does work meaning I receive an email.
<?php
// pull constant variables
include("php/constants.php");
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post) {
include ("php/functions.php");
}
// variables
$name = stripslashes($_POST['name']);
$phone = $_POST['phone'];
$email = trim($_POST['email']);
$tracker = $_POST['tracker'];
$message_holder = htmlspecialchars($_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 />';
}
// validate email
if($email && !ValidateEmail($email)) {
$error .= 'Please enter a valid e-mail address.<br />';
}
// check advertising tracker
if(!$tracker) {
$error .= 'Please let us know how you\'ve heard of us.';
}
// check message (length)
if(!$message_holder || strlen($message_holder) < 10) {
$error .= "Please enter your message. It should have at least 10 characters.<br />";
}
// build email message
$message = "Name: {$name} \n
Phone: {$phone} \n
Email: {$email} \n
Where did you hear about us?
{$tracker}\n\n
Message: {$message_holder}\n";
if(!$error) {
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: contact#stocor.com\r\n"
."Reply-To: ".$name."<".$email.">\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail) {
//header("Location: thank_you.php");
echo "Thank you. You will be contacted soon.";
}
} else {
echo '<div class="notification_error">'.$error.'</div>';
}
?>
Using the naked mail function is just asking for trouble ( http://en.wikipedia.org/wiki/E-mail_injection , php specific info: http://www.damonkohler.com/2008/12/email-injection.html ), and prevents simple debugging. I suggest you use an object wrapper around the mail function, both because this has benefits when you filter the headers, by making it a non-standard target for php mail form header injection spammers, and by allowing you to debug the messages easier by just dumping the created mail object and reviewing it's contents. For debugging it also allows you to provide a "just echo out the mail at the end" alternative for local testing on machines where you don't have/don't want to have a mail server, and don't want to even try to send out mail while you're just testing functionality.
Here is a wrapper (freely available for modification and use) that I created and use myself:
http://github.com/tchalvak/ninjawars/blob/master/deploy/lib/obj/Nmail.class.php
Alternatively just check out PEAR mail: http://pear.php.net/package/Mail/
It's not jumping out at me, why don't you try turning the errors all the way up and see if that works.
error_reporting(1);
At the top of the script.
EDIT: Sorry, I see now you do have error reporting turned on. Make sure your INI file is set properly too. Try removing the ^ E_NOTICE so that you see those warnings, too.
I've had problems where mail() wouldn't say anything at all (and it would execute as if successful) when it didn't really. If you're bent on using mail(), you can use SwiftMailer, which generally throws helpful exceptions when something goes awry and includes a transport class Swift_MailTransport which uses mail() but is all dressed up in a nice object-oriented interface.
So, due to the nature of the problem (mail is being accepted for delivery - $mail is true), the problem is likely in the message content. Do you have access to the mail server itself? Can you check the logs? var_dump() the $subject, $message, and set the headers to a var and var_dump() that as well. Examine the contents with a fine tooth comb. Remove suspect characters and line breaks until it does work.
One thing to try... (though, the fact that your other mail is being accepted says this is likely not the case)
http://www.php.net/manual/en/function.mail.php
If messages are not received, try
using a LF (\n) only. Some poor
quality Unix mail transfer agents
replace LF by CRLF automatically
(which leads to doubling CR if CRLF is
used). This should be a last resort,
as it does not comply with ยป RFC 2822.
The problem with mail() is that its just feeding mail to the local sendmail daemon. It doesn't give you any active feedback on the mail, and the relay headers sometimes get you spam de-rated.
I'd check out http://sourceforge.net/projects/phpmailer/
Try wrapping lines in the message to 70 characters with
$message = wordwrap($message, 70);
Try replacing \r\n in the additional headers with \n in case your mail function is replacing \n for \r\n and you're ending-up with \r\r\n