quaypc Posted August 10, 2007 Share Posted August 10, 2007 Hi, Is anybody able to help me with some script to send my form to my email address. Don't want to use MySQL for this because I don't think it warrents it. I've got very little experiance with php. I have got 5 fields; $name, $companyname, $address, $tel & $email. I want to send all this information to my email address. Have tried to do this for about a week and i'm really stuck!! CAN ANYONE HELP ME PLEAE!!? Quote Link to comment https://forums.phpfreaks.com/topic/64234-solved-help-sending-form-to-my-email/ Share on other sites More sharing options...
stervyatnik Posted August 10, 2007 Share Posted August 10, 2007 (I cut n' pasted this from another poster I (hopefully!) helped) I use FormMail.php, and it works GREAT! Here's a sample form, with the appropriate action: [pre] <form name="form1" method="post" action="formmail.php"> <input name="recipient" type="hidden" value="your.email@address.com"> <input name="subject" type="hidden" value="Type your subject here"> <p>Name</p> <input name="name" type="text" id="name"> <p>Email</p> <input name="email" type="text" id="email"> <p>Comment/Question:</p> <textarea name="comment" rows="6" id="comment"></textarea> </form> [/pre] Note that it references "formmail.php" in the action. You just have to load formmail.php into the same directory as your form (or you can reference a path to it, of course), and change a couple of parameters in the formmail.php file, and it automatically processes ALL your form info. In formmail.php, you have to set the referrers - so people can't really use your formmail.php script for spamming. Then you're ready to go. Forgot to mention: Make sure you're set up to use PHP on your Web server, else it won't work. Most Apache/Linux Web hosting servers have this enabled, but you may need to work with Windows hosting server admins to set it up. Check with your hosting company to make sure you have PHP enabled. Here's a link to formmail.php: http://www.dtheatre.com/scripts/formmail.php Hope that helps! Dan sends... Quote Link to comment https://forums.phpfreaks.com/topic/64234-solved-help-sending-form-to-my-email/#findComment-320276 Share on other sites More sharing options...
Fadion Posted August 10, 2007 Share Posted August 10, 2007 I wrote this code in another thread of nearly the same topic, but im modifying it for u. <form id="form1" name="form1" method="post" action=""> <input type="text" name="name" /> <input type="text" name="companyname" /> <input type="text" name="address" /> <input type="text" name="tel" /> <input type="text" name="email" /> <input type="submit" name="button" id="button" value="Submit" /> </form> <?php if(array_key_exists('name', $_POST)){ $name = $_POST['name']; $companyname = $_POST['companyname']; $address = $_POST['address']; $tel = $_POST['tel']; $email = $_POST['email']; $to = "youremail@domain.com"; $subject = "Email from your site"; $message = "This information has been submited to your website: \n\n"; $message .= "Name: $name\n"; $message .= "Company: $companyname\n"; $message .= "Address: $adress\n"; $message .= "Tel: $tel\n"; $message .= "Email: $email\n"; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $headers .= "To: Your Name <$to>\n"; $headers .= "From: Your Site <admin@domain.com>\n"; if(@mail($to, $subject, $message, $headers)){ echo "Your data was sent succesfully"; } else{ echo "There was a problem sending your email. Plese retry later"; } } ?> Make further modifications to $to and $headers variable. If u have problems, just tell. Quote Link to comment https://forums.phpfreaks.com/topic/64234-solved-help-sending-form-to-my-email/#findComment-320425 Share on other sites More sharing options...
quaypc Posted August 14, 2007 Author Share Posted August 14, 2007 Cheers GuiltyGear, That's worked a treat. Thanks again!! Quote Link to comment https://forums.phpfreaks.com/topic/64234-solved-help-sending-form-to-my-email/#findComment-323553 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.