problems with mail() function.....

here’s my sctipt, it comes up as Warning: Failed to Connect in c:easyphpwww1home1.php on line 20, but i do not understand why that is, because i copied almost exactly from a tutorial to test, but it does not seem to work…please help.

<? if($action == "send_mail") { $recipient = '[email protected]'; $subject = "Just a test from $name"; $body_of_email = " This is the contents of the email from Name: $name Who's email is: $email and who's URL is: $url "; $additional_headers = "From: $emailn"; if(mail($recipient, $subject, $body_of_email, $additional_headers)) { print("mail successfully sent to $recipient"); } else { print("oops! something didn't work right above, check the syntax of your code"); } } else { ?> Name: Your Email: URL: <? } ?> [/php] [b]MOD EDIT: Add PHP bb code tags[/b]

It looks like to me that line 20 is the line with the PHP_SELF on it.

Check the SOURCE of that page after it’s been displayed and see if it’s indeed displaying the ACTION page properly.

A couple of other things besides what Paul mentioned are:

Change your opening line from:

if($action == "send_mail")


if($_POST['action'] == "send_mail")

This wont get rid of the connect error I dont think, so check the SMTP setup on your server. If you have access to your PHP.ini file, try changing the value of sendmail_from to your e-mail address.

actually line 20 is the line with the mail() function. And on the action page, it says unable to connect, and also says, oops! something didn’t work right above, check the syntax of your code, (sorry, forgot to mention it).
please help

Ok, First of all the "oops! something didn’t work right above,… " is part of your code. It’s basically saying the MAIL fucntion did not work.

Now as carella Points out, you should be using the super global array. This will work when the register globals are off (which is a safer mode) or when the register globals are on, however just calling $action will NOT work if your register globals are off.

Ok, now to the root of your error. I suspect (now that we know the “Offending line”) that you do not have SMTP set up properly (again as carella suggested). If you are using a *nix solution, you don’t need to set it up, however on windows system (which based on your error message, you are on) you have to set up this information in the PHP.INI file otherwise the MAIL() function won’t work.

Sponsor our Newsletter | Privacy Policy | Terms of Service