Problem with PHP mail()

bstop

New Member
Messages
4
Reaction score
0
Points
0
I am attempting to use php to email me with the response to a webform and for some reason the email is never getting to me. I have included the php code below. Any help in figuring out what I'm doing wrong would be greatly appreciated.

<?php
$to = "ckuehn1701@yahoo.com";
$subject = "FAQ";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

$send = mail($to, $subject, $body);
if($send) {echo "Data has been submitted to $to!";}
else {echo "We encountered an error submitting your question, please try again.";}


?>
 

TheMan177

New Member
Messages
179
Reaction score
0
Points
0
I just tested that and it seems to work fine. Maybe the issue could be with Yahoo's filter.
 

Jake

Developer
Contributors
Messages
4,057
Reaction score
5
Points
0
You need to make sure you send headers or your email account might think it is spam... has happened to me... but it looks fine other than that. Try something like this:

<?php
$to = "ckuehn1701@yahoo.com";
$subject = "FAQ";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n";
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";


$send = mail($to, $subject, $body, $headers);
if($send)
{ echo "Data has been submitted to $to!"; }
else
{ echo "We encountered an error submitting your question, please try again."; }

?>
 
Last edited:

cheesycraps

New Member
Messages
7
Reaction score
0
Points
0
Also, do you have, at least, the Intermediate PHP version (v2) activated on your account so the mail() function would be enabled?

Your code seemed to be working just fine with me when I tested it.
 

archjones

New Member
Messages
6
Reaction score
0
Points
0
I'm having the same problem, but I haven't checked my spam yet. I had an email form on my site, but I didn't receive any mail (friends sent emails to test it). I removed the form and just gave an email address (not the x10hosting email) since I can't afford to lose any business right now. :happysad:
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Yahoo does block mail from the cossacks server.

Try a google account, which always seems to work for me.

Unfortunately, X10 accounts have been abused somewhat and has resulted in a number of mail servers logging them as blacklisted.

I can't see anything wrong with your code, other than there is a bug in php mail for From headers.

This can be resolved using the following immediately before the mail part.

ini_set(sendmail_from,'webmaster@wherever.com');

Also, in your headers, you could add.

$headers .= 'X-Mailers: PHP /'.phpversion() . "\r\n";
 
Top