tmyonline Posted July 30, 2007 Share Posted July 30, 2007 Dear all, I bought two books on PHP and followed the author's instructions closely but I can never be successful in submitting a form. The information on the form is supposed to be sent as a string through email once users click the "submit" button. Based on the books, I have configured the php.ini file and so on but things never worked. I'm too disappointed. Any ideas or suggestions ? Many thanks! Tommy Quote Link to comment https://forums.phpfreaks.com/topic/62572-how-to-send-a-form-as-an-email/ Share on other sites More sharing options...
gabrielkolbe Posted July 30, 2007 Share Posted July 30, 2007 Please submit your code where you set the headers and mailto scripts.. Quote Link to comment https://forums.phpfreaks.com/topic/62572-how-to-send-a-form-as-an-email/#findComment-311433 Share on other sites More sharing options...
tmyonline Posted July 30, 2007 Author Share Posted July 30, 2007 Please submit your code where you set the headers and mailto scripts.. Hi: Here's my code. Hope you can help. Many thanks and appreciations! Tommy <?php if (array_key_exists('ewComments', $_POST)) { // mail processing script // initialize variables $to = 'kngo252@yahoo.com'; $subject = 'Feedback from East-West Seasons'; // build the message $message = 'From: '.$_POST['name']."\n\n"; $message .= 'Email: '.$_POST['email']."\n\n"; $message .= 'Comments: '.$_POST['message']; // send the email mail($to, $subject, $message); } ?> <!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=iso-8859-1" /> <title>East-West Seasons</title> <?php include('style_rules_monthly.php'); ?> </head> <body> <div id="wrapper"> <div id="titlebar"><img src="images_common/<?php echo $theme; ?>_top.jpg" alt="East-West Seasons" width="738" height="122" /></div> <div id="maincontent"> <div id="nav"> <ul> <li><a href="index.php">Home</a></li> <li><a href="news.php">News</a></li> <li><a href="blog.php">Blog</a></li> <li><a href="gallery.php">Gallery</a></li> <li><a href="contact.php">Contact</a></li> </ul> </div> <h1>Send Us Your Comments</h1> <p>We hope you have enjoyed this site. If you have any comments, or would like further information, please use the following form. East-West Seasons will not use your email address for any other purposes than replying to you.</p> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="contactForm" id="contactForm"> <p> </p> <p> <label for="name">Name:</label> <br /> <input type="text" name="name" id="name" /> </p> <p> <label for="email">Email:</label> <br /> <input type="text" name="email" id="email" /> </p> <p> <label for="message">Message:</label> <br /> <textarea name="message" cols="60" rows="6" id="message"></textarea> </p> <p> <input name="ewComments" type="submit" id="ewComments" value="Send comments" /> </p> </form> </div> <div id="footer"> <p>© 2007 Khiem Ngo </p> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/62572-how-to-send-a-form-as-an-email/#findComment-311442 Share on other sites More sharing options...
gabrielkolbe Posted July 30, 2007 Share Posted July 30, 2007 Firstly ...under the <form> element, I would place a hidden field, (<input type="hidden" name="action" value="emailform"> ) - maybe your 'submit' button is not working.. Stick the submit buttons as <input type="submit" name="submit" value="submit"> keep it simple then, instead of -- if (array_key_exists('ewComments', $_POST)) {---i would say -- if ($_POST['action'] == "emailform") { bla bla the also place a 'tester'on your mail function like if ( mail($to, $subject, $message) { echo "hooray!"} else {echo "oh shit!"} Quote Link to comment https://forums.phpfreaks.com/topic/62572-how-to-send-a-form-as-an-email/#findComment-311456 Share on other sites More sharing options...
gabrielkolbe Posted July 30, 2007 Share Posted July 30, 2007 Test ever bit of the code, test if you get what you post, extra Quote Link to comment https://forums.phpfreaks.com/topic/62572-how-to-send-a-form-as-an-email/#findComment-311458 Share on other sites More sharing options...
tmyonline Posted July 31, 2007 Author Share Posted July 31, 2007 I just tested my site again and this is the error I got: "Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\htdocs\phpdw\contact.php on line 14" I opened php.ini file and did a search on "sendmail_from". I found that I had set "sendmail_from = tmng2005@yahoo.com". I'm incorporating your suggestions to the code. I'm wondering if the problem has anything to do with configuration or setting in the php.ini file. As far as line 14 in the code is concerned, it is "mail($to, $subject, $message);" Any further ideas ? ! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/62572-how-to-send-a-form-as-an-email/#findComment-311498 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.