PHP mail function

Can someone help please.

The following code works perfectly when I plug an actual email into the code (copied the email posted by $_POST[“email”]), but the minute I use $_post[“email”] in the mail function it does not work.

I have added a print statement to my code to check that $_post[“email”] is okay and it is.

mail($_POST[“email”], ‘A test email’, $emailText, $header);

As long as you are using this exact function (notice the case on $_POST):

[php]mail($_POST[“email”], ‘A test email’, $emailText, $header);[/php]

Then I can’t see what the problem would be. Is the problem an error being displayed, no error or that the e-mail doesn’t arrive?

I have added:

$mailErr = mail($_POST["email"], 'A test email', $emailText, $header);
print $mailErr."<br />";

$mailErr is returning a “1”, but no email is being sent.

Just to be sure, if you echo out $_POST[‘email’], it gives you the correct response?

Have you sent mail successfully before from this machine?

Yes, I have another mail I send, where the email address is hardwired in to the mail command and it is perfect. Everything else is the same.

Apart from something being wrong with the $_POST field, I can’t think of anything that might be causing a problem. Is any validation done on the $_POST fields? Do you know if your server has Magic Quotes turned on?

Sponsor our Newsletter | Privacy Policy | Terms of Service