HI, DOES ANY ONE KNOW WHAT IS THE RIGHT STEPS TO MAKE THIS FORM MAIL TO WORK?

HE IS THE CODE:

1. <html>
2. <head>
3. <title> send mailf from the form </title>
4. </head>
5. <body>
6. <?php
7. echo "<p> your name is: <b>$_POST[name]</b>,</p>";
8. echo "<p> your Email address is: <b>$_POST[email]</b></p>";
9. echo "<p> Your message was: <br>";
10.echo "$_POST[message]</p>";
11. $msg ="Name: $_POST[name]\n";
12. $msg .="Email: $_POST[email]\n";
13. $msg .="message: $_POST[message]\n";
14. $recipient = "ero100@live.com";
15. $mailheaders ="reply-to: $_POST[email]";
16. mail($recipient, $subject, $msg, $mailheaders);
17. ?>
18. </body>
19.</html>

HE IS THE ERROR MESSAGE:

your name is: Mr. Jhonh,

your Email address is: Myemail@hotmail.co.uk

Your message was:
what is this error???? CANT FIGURE IT OUT...


Notice: Undefined variable: subject in C:\wamp\www\phptest\listing9.11.php on line 19

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\phptest\listing9.11.php on line 19

A few observations:
1. When you post code, you should use [code] tags to have it format properly.
2. You don't need the <html> <head> and <body> statements. PHP takes care of that.
3. $subject on line 16 isn't defined (at least in what you have shown us).
4. The default is that mail doesn't actually get sent from the local (test) environment. It can be done but you will have to make some changes (if you need this, I'm sure that you can find references from an internet search).

A few observations:
1. When you post code, you should use [code] tags to have it format properly.
2. You don't need the <html> <head> and <body> statements. PHP takes care of that.
3. $subject on line 16 isn't defined (at least in what you have shown us).
4. The default is that mail doesn't actually get sent from the local (test) environment. It can be done but you will have to make some changes (if you need this, I'm sure that you can find references from an internet search).

heh, I'm not sure what strange auto_prepend_file setting you're using but PHP does NOT automatically insert any HTML tag.

WAMP/XAMP does not come with an SMTP server so you'll have to configure the php.ini file to point to another SMTP server.

And as noted before, you haven't set the $subject variable to anything.

One more thing, it's common practice for ISP's to block port 25. So if you are trying to set up a mailserver from your home connection, you might be out of luck. ISP's block port 25 to make sure people don't spam, or have viruses/crapware that uses their computers to send spam.

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\phptest\listing9.11.php on line 19
..This error occured because u are running the application on your local machine ,ie local host and no mail server is set up on your local machine .Upload your file to some server and it will work fine because the mail server will be there in the sever .

To solve the first e_notice error, simply assign a value to the $subject variable before sending the mail and as for the second error, as previously mentioned it means that the mail function cannot connect to the wamp mail service. So to solve that first error the code will be as follows:

<html>
<head>
<title> send mailf from the form </title>
</head>
<body>
<?php 
echo "<p> your name is: <b>".$_POST['name']."</b>,</p>";
echo "<p> your Email address is: <b>".$_POST['email']."</b></p>";
echo "<p> Your message was: <br>";
echo $_POST['message']."</p>";
$msg ="Name: ".$_POST['name']."\n";
$msg .="Email: ".$_POST['email']."\n";
$msg .="message: ".$_POST['message']."\n";
$recipient = "ero100@live.com";
$mailheaders ="reply-to: ".$_POST['email'];
$subject='subject'; //this was added
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>

So to solve the rest, it will require resetting up a localhost mail server on your computer but the above script should be fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.