zapper13 Posted March 11, 2009 Share Posted March 11, 2009 PLease help me cuz i am a noob with php codes. I self read a little on php code and came up with this. However, when i clicked on submit, the error page appears instead of your mail was sent successfully. Where did i go wrong? I followed the instructions completely. I am using yahoo webhosting. <?php $to = "[email protected]"; $subject = "nothing"; $text = $_REQUEST['text']; $email = $_REQUEST['email']; $list = $_REQUEST['list']; $contactno = $_REQUEST['contactno']; $headers = "From: $email"; $sent = mail($to, $subject, $text, $email, $list, $contactno, $headers); if($sent) {print "your mail was sent successfully"; } else {print "error"; } ?> Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/ Share on other sites More sharing options...
revraz Posted March 11, 2009 Share Posted March 11, 2009 replace your mail line with this and see if it works $sent = mail($to, $subject, "hello", "FROM: $to"); Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782052 Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 yeah, you are probably looking for: $sent = mail($to, $subject, "$text\n$email\n$list\n$contactno", $headers); Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782057 Share on other sites More sharing options...
zapper13 Posted March 11, 2009 Author Share Posted March 11, 2009 i tried the post submitted by revraz and it worked but i only received a hello from the content of the email...when i tried the post submitted by rhodesa the error page came out again...what is happening? Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782071 Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 What are you putting in for a email in your form? Maybe the data is not being passed from the form properly. What is the HTML for your form? Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782077 Share on other sites More sharing options...
zapper13 Posted March 11, 2009 Author Share Posted March 11, 2009 This is my html code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="contactprocess.php"> <p> <label> <input type="text" name="text" id="text" /> </label> </p> <p> <label> <input type="text" name="email" id="email" /> </label> </p> <p> <label> <select name="list" id="list"> <option value="hello">hello</option> <option value="bye">bye</option> <option value="huh">huh</option> </select> </label> </p> <p> <label> <input type="text" name="contactno" id="contactno" /> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782081 Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 In the future, please use [ code ][ /code ] tags (without the spaces) when posting. There is a button with a # on it when you are posting that will insert them for you. I just loaded this up for a test, and it worked for me: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $to = "[email protected]"; $subject = "nothing"; $text = $_REQUEST['text']; $email = $_REQUEST['email']; $list = $_REQUEST['list']; $contactno = $_REQUEST['contactno']; $headers = "From: $email"; $sent = mail($to, $subject, "$text\n$email\n$list\n$contactno", $headers); if($sent) {print "your mail was sent successfully"; } else {print "error"; } exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <p> <label> <input type="text" name="text" id="text" /> </label> </p> <p> <label> <input type="text" name="email" id="email" /> </label> </p> <p> <label> <select name="list" id="list"> <option value="hello">hello</option> <option value="bye">bye</option> <option value="huh">huh</option> </select> </label> </p> <p> <label> <input type="text" name="contactno" id="contactno" /> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782091 Share on other sites More sharing options...
zapper13 Posted March 11, 2009 Author Share Posted March 11, 2009 oh thanks you so much guys. i finally managed to get it to work. the problem was actually the $header part. somehow yahoo web hosting disable unknown email addresses to be sent so when i change that field to "From: $to" as revraz stated, it worked perfectly. however i got another question. i will like to know how to instead of printing "your email has been sent successfully" or "error", the submit button will load another webpage Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782114 Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 if($sent){ header('Location: newpage.php'); exit; } Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782117 Share on other sites More sharing options...
revraz Posted March 11, 2009 Share Posted March 11, 2009 That is a common issue, the Webhost will only use a valid email as the FROM address that is on that domain, to try and prevent spam. Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-782145 Share on other sites More sharing options...
zapper13 Posted March 13, 2009 Author Share Posted March 13, 2009 oh and one more thing i will like to ask...how do you actually make the form submitted send to another email other than [email protected]? Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-783551 Share on other sites More sharing options...
rhodesa Posted March 13, 2009 Share Posted March 13, 2009 to send to multiple emails, just update $to: $to = "[email protected],[email protected]"; to send a separate email (like a thank you for registering), you just copy/paste the code you have already and change the values to what you want Link to comment https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/#findComment-783647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.