spainsoccerfreak Posted January 27, 2009 Share Posted January 27, 2009 Ok here the code for both html and php I need this info to send to an email address I try it and after I hit submit it just shows me these on the screen (red text) Why doesnt it show me the name instead of the post and also I get nothing to my email please help my job depends on it! Thank You, " .$_POST["name"].", for your message!"; echo "you email address is: .$_POST["email"].""; echo "your message was:"; echo $_POST["message"].""; //start building the mail string $msg = "Name: ".$_POST["name"]."\n"; $msg = "E-mail: ".$_POST["email"]."\n"; $msg = "Message: ".$_POST["message"]."\n"; //set up the mail $recipient = "jessicarondon1@yahoo.com"; $subject = "Form Submition Results"; $mailheaders = "From: my site"; $mailheaders = "Reply - To: .$_POST["email"]; //send the mail mail mail($recipient, $subject, $msg, $mailheaders); ?> HTML <html> <head> <title> E-mail Form </title> </head> <body> <form action="sendmail.php" method= "POST"> <p>Name:</p> <input type="text" size="25" name="name"> <p>Email Address</p> <input type="text" size="25" name="email"> <p>Message:</p> <textarea name="message" cols="30" rows="5"></textarea> <p><input type="submit" value="send" /></p> </form> </body> </html> and PHP <html> <head> <title> Sending Email Form in listing </title> </head> <body> <?php echo "<p>Thank You, <b>" .$_POST["name"]."</b>, for your message!</p>"; echo "<p>you email address is: <b> .$_POST["email"]."</b></p>"; echo "<p>your message was:<br />"; echo $_POST["message"]."</p>"; //start building the mail string $msg = "Name: ".$_POST["name"]."\n"; $msg = "E-mail: ".$_POST["email"]."\n"; $msg = "Message: ".$_POST["message"]."\n"; //set up the mail $recipient = "jessicarondon1@yahoo.com"; $subject = "Form Submition Results"; $mailheaders = "From: my site"; $mailheaders = "Reply - To: .$_POST["email"]; //send the mail mail mail($recipient, $subject, $msg, $mailheaders); ?> </body> </html>[/] Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 27, 2009 Author Share Posted January 27, 2009 help Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 27, 2009 Share Posted January 27, 2009 How are you invoking the form? Also, when posting code, please use tags, not color tags. Ken Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 27, 2009 Share Posted January 27, 2009 1. It looks like PHP is not enabled in the environment you are running. 2. In the code for building the variables for the email you are redefining several of the variables instead of concatenating $msg = "Name: ".$_POST["name"]."\n"; $msg = "E-mail: ".$_POST["email"]."\n"; $msg = "Message: ".$_POST["message"]."\n"; $msg would only be set to that last line. Need to use something like this: $msg = "Name: ".$_POST["name"]."\n"; $msg .= "E-mail: ".$_POST["email"]."\n"; $msg .= "Message: ".$_POST["message"]."\n"; and for the $mailheaders you would need to separate the values instead of just concatenating them together as-is: $mailheaders = "From: my site" . . "\r\n"; $mailheaders .= "Reply - To: .$_POST["email"]; Here is some "corrected" code <html> <head> <title> Sending Email Form in listing </title> </head> <body> <?php $name = trim($_POST['name']); $email = trim($_POST['email']); $msg = trim($_POST['message']); echo "<p>Thank You, <b>$name</b>, for your message!</p>\n"; echo "<p>Your email address is: <b>$email</b></p>"; echo "<p>Your message was:<br />".nl2br($msg)."</p>"; //start building the mail string $msg = "Name: $name\n"; $msg .= "E-mail: $email\n"; $msg .= "Message:\n$msg\n"; //set up the mail $recipient = "jessicarondon1@yahoo.com"; $subject = "Form Submition Results"; $mailheaders = "From: my site"; $mailheaders .= "Reply - To: " .$_POST["email"]; //send the mail mail if (mail($recipient, $subject, $msg, $mailheaders)) { echo "<br><br>Message sent." } else { echo "<br><br>Problem sending email." } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 27, 2009 Author Share Posted January 27, 2009 Ok thanks for the help but I put the code in that was given to me in orevious post after I hit submit this is what shows up on the next screen Thank You, $name, for your message! \n"; echo " Your email address is: $email "; echo " Your message was: ".nl2br($msg)." "; //start building the mail string $msg = "Name: $name\n"; $msg .= "E-mail: $email\n"; $msg .= "Message:\n$msg\n"; //set up the mail $recipient = "jessicarondon1@yahoo.com"; $subject = "Form Submition Results"; $mailheaders = "From: my site"; $mailheaders .= "Reply - To: " .$_POST["email"]; //send the mail mail if (mail($recipient, $subject, $msg, $mailheaders)) { echo " Message sent." } else { echo " Problem sending email." } ?> instead of the name email and sent email please help Also how do I check to see if PHP is enable in my enviroment and if is nto how do I fix it? Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 27, 2009 Share Posted January 27, 2009 Your web server needs to be configured to run PHP. There are plenty of tutorials out there on how to install and configure it. It's not somethign that I would try and do through a forum. Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 27, 2009 Author Share Posted January 27, 2009 Ok I did heres screen I get XAMPP Status This page offers you one page to view all information about what's running and working, and what isn't working. Component Status Hint MySQL database ACTIVATED PHP ACTIVATED HTTPS (SSL) ACTIVATED Common Gateway Interface (CGI) ACTIVATED Server Side Includes (SSI) ACTIVATED SMTP Service DEACTIVATED FTP Service DEACTIVATED Some changes to the configuration may sometimes cause false negatives. All reports viewed with SSL (https://localhost) do not function! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 27, 2009 Share Posted January 27, 2009 Again, how are you invoking the form? It MUST be invoked typing the URL into the address area, not by double-clicking a HTML file. Ken Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 27, 2009 Author Share Posted January 27, 2009 OK I tried it type in the address URL Still wont work I do not know if it matter but I have it at these location *file:///C:/xampp/htdocs/xampp/test101.html* then *file:///C:/xampp/htdocs/xampp/sendmail1.php* is the file that doesnt show correct the php Quote Link to comment Share on other sites More sharing options...
Sudden Posted January 27, 2009 Share Posted January 27, 2009 If the first file contains PHP code it must be saved as .php Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 27, 2009 Share Posted January 27, 2009 OK I tried it type in the address URL Still wont work I do not know if it matter but I have it at these location *file:///C:/xampp/htdocs/xampp/test101.html* then *file:///C:/xampp/htdocs/xampp/sendmail1.php* is the file that doesnt show correct the php Are you opening those files in your web browser with the URL of "file:///C:/xampp/htdocs/xampp/test101.html"? If so, that was what kenrbnsn was stating. You need to call the files through a web server. In this case it would be "http://localhost/test101.html" for the first file. Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 27, 2009 Author Share Posted January 27, 2009 WOW I feel really nto smart LOL that did help now I got these error message but I think is the coding for email 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:\xampp\htdocs\xampp\sendmail1.php on line 27 Problem sending email. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 28, 2009 Share Posted January 28, 2009 The web server cannot send email - it needs to make a request via an email server (web server = web pages, email server = email). Since you showed some details for XAMPP, I am assuming you are currently testing this on your local machine. So, even once you get this configured on your local machine, you may also need to make changes in the production environment. This page explains the php.ini settings you need to set in a Windows environment: http://www.php.net/manual/en/mail.setup.php Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 28, 2009 Author Share Posted January 28, 2009 ok I have changed the php.ini (yes I am testing in my local machine )to the mail settings bellow still wont work but when I go to my localhost and status is says Component Status Hint MySQL database ACTIVATED PHP ACTIVATED HTTPS (SSL) ACTIVATED Common Gateway Interface (CGI) ACTIVATED Server Side Includes (SSI) ACTIVATED SMTP Service DEACTIVATED FTP Service DEACTIVATED I dont know if SMTP being deactivated is not letting it go thru <php.ini> [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. ;sendmail_from = jessicarondon1@yahoo.com <php.ini> Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 28, 2009 Share Posted January 28, 2009 I dont know if SMTP being deactivated is not letting it go thru Yes, that is the problem. You need to point the php.ini configuration for the mail server to an active mail server. If you are not running one on your machine then you need to point it to a valid mail server. Find the mail server settings you use for your email and point it to that one. Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 28, 2009 Author Share Posted January 28, 2009 Can I use my yahoo email address will that work? Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 28, 2009 Share Posted January 28, 2009 It has nothing to do with your email address. Yahoo! does not allow you to use them as an SMTP service (at least not with their free accounts). GMail does, but you are required to pass a username and password. I don't know how that is configured within PHP to work. Let me try to explain this more plainly. When you want to access a webpage your browser must contact a web server and request the page. The webserver then finds the page and returns it to your browser. In the case of server-side pages, such as PHP, the web server will process the page and return the output to the browser. Your XAMPP environment has all of that and was the reason you were getting garbage by trying to make your browser open the php files directly. You were not going through the web server to process the files. In the same way you need an email server to send emails. When you use a service like yahoo, the web page is communicating with the web server to send and receive the email displayed on the web page. Your browser does not communicate with the web server, the web pages do. Non web based email is typically done with an email client like Outlook. It will be configured to send and recieve email directly with the email server. You "should" be able to find out the SMTP server for whatever ISP you are currently using and use that since most ISPs do not require authentication for people already logged into their network. I run XAMPP as well. Within my XAMPP install there is an email service called "Mercury". I have not used it, so I don't know what configurations may, or may not, be needed (it wouldn't start on my machine and I don't have the time to research). You could try enabling it through the XAMPP control panel and using localhost. however, as stated before, this would only work in your XAMPP environment. Your production environment would probably be different. Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 28, 2009 Author Share Posted January 28, 2009 Ok I tried with a local server my company uses no the error message is this **Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in C:\xampp\htdocs\xampp\sendmail1.php on line 27** <php code> <html> <head> <title> Sending Email Form in listing </title> </head> <body> <?php $state = trim($_POST['state']); $school = trim($_POST['school']); $district = trim($_POST['district']); echo "<p>Thank You for your message!</p>\n"; echo "<p>Your State is: <b>$state</b></p>"; echo "<p>Your district is:<b>$district</b></p>"; //start building the mail string $msg = "State: $state\n"; $msg .= "School: $school\n"; $msg .= "District:$district\n"; //set up the mail $recipient = "xxxxxxxx@mycompany.com"; $subject = "Form Submition Results"; $mailheaders = "From: my site"; $mailheaders .= "Reply - To: " .$_POST["email"]; //send the mail mail if (mail($recipient, $subject, $msg, $mailheaders)) { echo "<br><br>Message sent."; } else { echo "<br><br>Problem sending email."; } ?> </body> </html> <code> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 28, 2009 Share Posted January 28, 2009 When you concatenate headers, you need to put in a "\r\n" at the end of each line. Also, the "Reply To" header is wrong and the "From" header needs to be a valid email address. Try: <?php //set up the mail $recipient = "xxxxxxxx@mycompany.com"; $subject = "Form Submition Results"; $mailheaders = "From: my site<my.site@my.site.com>\r\n"; $mailheaders .= "Reply-To: " .$_POST["email"] ."\r\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 28, 2009 Author Share Posted January 28, 2009 ok sam error **Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in C:\xampp\htdocs\xampp\sendmail1.php on line 27** Now lien 27 in my php is *if (mail($recipient, $subject, $msg, $mailheaders))* Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 28, 2009 Share Posted January 28, 2009 Try using a valid email address here: $mailheaders = "From: my site\r\n"; Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 28, 2009 Author Share Posted January 28, 2009 $mailheaders = "From: my site<name.lastname@mycompany.com>\r\n"; Still says error line 27 **Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in C:\xampp\htdocs\xampp\sendmail1.php on line 27** Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 28, 2009 Author Share Posted January 28, 2009 Same error replaced the email with my email at work ($mailheaders = "From: my site<name.lastname@mycompany.com>\r\n" which is the port SMTP I used but gives me same error message ; Still says error line 27 **Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in C:\xampp\htdocs\xampp\sendmail1.php on line 27** Quote Link to comment Share on other sites More sharing options...
spainsoccerfreak Posted January 28, 2009 Author Share Posted January 28, 2009 ini_set fixed it Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.