954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Form mail, how to make it work?


6. <?php
7. echo " your name is: $_POST[name],


";
8. echo " your Email address is: $_POST[email]


";
9. echo " Your message was:
";
10.echo "$_POST[message]


";
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.

ero100@live.com
Newbie Poster
10 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

A few observations:
1. When you post code, you should use [code] tags to have it format properly.
2. You don't need the and 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).

chrishea
Nearly a Posting Virtuoso
1,428 posts since Sep 2008
Reputation Points: 210
Solved Threads: 230
 
A few observations: 1. When you post code, you should use [code] tags to have it format properly. 2. You don't need the and 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 doesNOT 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.

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

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.

vidaj
Junior Poster in Training
68 posts since Jul 2007
Reputation Points: 45
Solved Threads: 14
 

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 .

shefeekj
Light Poster
37 posts since Apr 2009
Reputation Points: 1
Solved Threads: 2
 

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: ";
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.

cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You