Click to See Complete Forum and Search --> : mail() will not work under Linux


kwestberg
07-21-2004, 11:44 PM
I have a PHP script that I use to create and send email messages from an HTML form, it works fine under a Unix host, but when I run it under a Linux host all the code runs fine except for the mail() function, it returns back a false completion code and no email gets sent. I talked with the Linux hosting techs and they said everything was enabled and the sendmail_path and switches were set OK. ( /usr/sbin/sendmail -t -i ).

Can anyone help me with why the mail() doesn't work under the Linux host?



<?
if (empty ($name)) {
echo "<br><center><b><font size=+1 color=red>Please input correct Name!</font></b></center>";
exit; }

$pattern = ".+@.+\..+";
if (!eregi ($pattern, $email)) {
echo "<br><center><b><font size=+1 color=red>Please input correct Email address!</font></b></center>";
exit; }

$message = "You have received an inquiry from your WebSite. \n";
$message = $message.date('j M Y, H:ia')."\n";

while ($element = each ($_POST))
{
if ($element["key"] == "Subject") continue;
if ($element["key"] == "MailTo") continue;
if ($element["key"] == "MailFrom") continue;
if ($element["key"] == "ReDirect") continue;
if ($element["key"] == "Reply_Message") continue;
$message = $message."\n".$element["key"].": ====> ". $element["value"];
}

if (mail ($MailTo, $Subject, $message, "from: $email")) {
echo "<center><br><font size=+1 color=red><b>Your Registration was successfully sent.<br>You will recieve a response back within 24 hours, <br>Thank You for using our WebSite!</b></font></center>";
} else {
echo "<center><br><font size=+1 color=red><b>There was an email send problem....Your message was not sent. </font></b>";}

?>

yelvington
07-24-2004, 11:48 AM
The F in From: should be capitalized. Read the RFC's.

It's possible that the mail was accepted for delivery but was misaddressed or spamfiltered at the recipient end. Depending on the hosting service you use, it's possible that the entire address block is blackholed.

Try a simple test case. Replace dest and from in the following:

<?php
$dest = "youraddresshere";
$from = "youraddresshere";
$msg = "This is a test from $from to $dest.";

mail($dest,
"Test mail to $dest",
$msg,
"From: $from");
?>

kwestberg
07-24-2004, 01:27 PM
yelvington,
I tried your script replacing the to and from like you said, it did not work. I then put a return code check in your code and it came back false.....
I think my hoster has something not set right.

Thanks