Form mail, how to make it work?

Reply

Join Date: Apr 2009
Posts: 7
Reputation: ero10 is an unknown quantity at this point 
Solved Threads: 0
ero10 ero10 is offline Offline
Newbie Poster

Form mail, how to make it work?

 
0
  #1
Apr 26th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 224
Reputation: chrishea is an unknown quantity at this point 
Solved Threads: 32
chrishea's Avatar
chrishea chrishea is offline Offline
Posting Whiz in Training

Re: Form mail, how to make it work?

 
0
  #2
Apr 26th, 2009
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).
Chris
See my list of PHP development tools at:
InnovationsDesign.net
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,419
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 229
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Form mail, how to make it work?

 
0
  #3
Apr 26th, 2009
Originally Posted by chrishea View Post
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.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 66
Reputation: vidaj is an unknown quantity at this point 
Solved Threads: 14
vidaj vidaj is offline Offline
Junior Poster in Training

Re: Form mail, how to make it work?

 
0
  #4
Apr 26th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 37
Reputation: shefeekj has a little shameless behaviour in the past 
Solved Threads: 2
shefeekj shefeekj is offline Offline
Light Poster

Re: Form mail, how to make it work?

 
0
  #5
Apr 27th, 2009
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 .
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,518
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: Form mail, how to make it work?

 
0
  #6
Apr 27th, 2009
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:
  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. $subject='subject'; //this was added
  17. mail($recipient, $subject, $msg, $mailheaders);
  18. ?>
  19. </body>
  20. </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.
Last edited by cwarn23; Apr 27th, 2009 at 7:06 am.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC