0

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:

[email protected] is replaced with my real email address.

udrew_email("[email protected]", $_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.

1
  • Have you configured the server to send email? Commented Oct 19, 2011 at 19:21

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This was definitely a problem. I have since configured it and still get the same error though. What would be the next step to troubleshoot?
Check the mail sever logs to see why the message is being rejected/bounced?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.