Question:
php mail function?? get sent on spam?
Pals
2008-07-18 22:22:37 UTC
I have the following code::


$to = "someone@example.net";
$subject = "You had made a Blunder";
$message = "You are a stupid \n you are fellow";
$headers = "From: webmaster@example.com" . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)){
echo("

Message successfully sent!

");
} else {
echo("

Message delivery failed...

");
}
?>

on sending this mail, it gets sent on spam..
How can i fix it??, Someone please help me.
Three answers:
Some Guy
2008-07-18 22:34:33 UTC
The PHP mail function always gets sent through the host's mail server, and more header information gets added, that could possibly trigger a spam alert (if the host's domain is different from the sender domain, and the host hasn't registered their servers as being safe).



For example: if you're hosted with, say, DreamHost, your email would have your "from" in there (example.com), but also dreamhost.com.



Contact your host and ask if they have a workaround; in the meantime, tell your visitors to add your domain (example.com) to their address book, to prevent it from being marked spam.
zoredache
2008-07-19 03:27:48 UTC
}} on sending this mail, it gets sent on spam..



I believe you are saying it gets flagged as spam? It may be that the web server you are running from is blacklisted. You could try sending via a different mail server.



You also might want to take a look at something like phpmailer (http://phpmailer.codeworxtech.com/) instead of calling mail() directly.
just "JR"
2008-07-19 01:23:40 UTC
Above answer correct.

One note:

if (mail ($to, $subject, ...

is a bit superfluous: the mail() function will return true is the function has executed successfully.

THIS DOES NOT MEAN your message has been REALLY sent! (There is no way you can be sure that the recipient HAS received the message...)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...