简体   繁体   中英

Sending mail with PHP not working

My script to send an email via PHP is not working and I don't know why as there is no specific error. Please advise:

test@test.com is replaced with my real email address.

udrew_email("test@test.com", $_REQUEST["txtEmail"], "Gears Message", $_REQUEST["txtName"], $_REQUEST["txtMessage"]);

<?php
function udrew_email($strTo, $strFromEmail, $strSubject, $strFromName, $strBody)
{
$strHeaders = "From: " . $strFromName . "<" . $strFromEmail . ">" . "\r\n";
if (mail($strTo, $strSubject, $strBody, $strHeaders)) {
    echo("<p>Message successfully sent!</p>");
} else {
    echo("<p>Message delivery failed.</p>");
}
}
?>

I get "Message delivery failed."

I've also tried placing constants in all the variables instead of requesting from my form.

Any help would be appreciated. Thanks.

mail() returns false if it was unable to handle the email over to an smtp server. On unix, that'd be the local sendmail/postfix/exim. On Windows, it's whatever smtp server is configured in php.ini SMTP and smtp_port options.

That can be because the smtp server isn't running or is mis-configured. It can also be because the email is so badly formed the server rejects it outright without even TRYING to deliver it onwards.

Check and make sure that your mail server is running, and that you have one installed and set up. If it is then check the log files for your mail server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM