Firstaka Posted November 18, 2008 Share Posted November 18, 2008 I would like to be able to send the form to an e-mail address but I can't seem to figure out how. The webpage can be found here with the contact section that needs to be edited to the right: http://orientwatchusa.com/index-4.html Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/ Share on other sites More sharing options...
gevans Posted November 18, 2008 Share Posted November 18, 2008 To send form data to an email address you're going to need to use a server side script such as PHP. Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693081 Share on other sites More sharing options...
Firstaka Posted November 18, 2008 Author Share Posted November 18, 2008 Would this work? <?PHP $to = "you@your.com"; $subject = "Results from your Request Info form"; $headers = "From: Form Mailer"; $forward = 0; # redirect? 1 : yes || 0 : no $location = "thankyou.htm"; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; if ($_SERVER['REQUEST_METHOD'] == "POST") { foreach ($_POST as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } else { foreach ($_GET as $key => $value) { $msg .= ucfirst ($key) ." : ". $value . "\n"; } } mail($to, $subject, $msg, $headers); if ($forward == 1) { header ("Location:$location"); } else { echo "Thank you for submitting our form. We will get back to you as soon as possible."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693083 Share on other sites More sharing options...
gevans Posted November 18, 2008 Share Posted November 18, 2008 Yes that should work, but you can easily get spam messages, and it doesn't check to ensure that the email sent. But it's safe to put onlnie and try. Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693086 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 Okay what would you suggest to make it more secure? Also, As you can probably guess I didnt write the original source So I am bit confused how to actually implement this. Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693087 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 My recommendation would be as follows (for the easiest way to sort the problem); Change the current form code bellow; <form id="form" action="" enctype="multipart/form-data"> <div class="form"> <div class="indent-form"><input type="text" value="name" /></div> <div class="indent-form"><input type="text" value="e-mail" /></div> <div class="indent-form"><input type="text" value="phone" /></div> <p> <textarea cols="2" rows="2">message</textarea> <a class="link" href="mailto:info@orientwatchusa.com" onclick="document.getElementById('form').submit()">Send<img src="images/link_marker.gif" alt="" /></a></p> <p> </p> </div> </form> to this <form id="form" action="contact_send.php"> <div class="form"> <div class="indent-form"><input name="name" type="text" value="name" /></div> <div class="indent-form"><input name="email" type="text" value="e-mail" /></div> <div class="indent-form"><input name="phone" type="text" value="phone" /></div> <p> <textarea name="message" cols="2" rows="2">message</textarea> <input type="submit" value="Submit" name="submit" /></p> <p> </p> </div> </form> This will sort out your contact form, The code bellow should be copied and pasted into notepad (or any other text editor) and saved as contact_send.php <?php $to = "you@your.com"; $subject = "Results from your Request Info form"; $headers = "From: Form Mailer"; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; if(!isset($_REQUEST['name']) || empty($_REQUEST['name'])) die('You must fill in all details'); else $msg .= "Name: {$_REQUEST['name']}\n" if(!isset($_REQUEST['email']) || empty($_REQUEST['email'])) die('You must fill in all details'); else $msg .= "Email: {$_REQUEST['email']}\n" if(!isset($_REQUEST['phone']) || empty($_REQUEST['phone'])) die('You must fill in all details'); else $msg .= "Phone: {$_REQUEST['phone']}\n" if(!isset($_REQUEST['message']) || empty($_REQUEST['message'])) die('You must fill in all details'); else $msg .= "Message: {$_REQUEST['message']}\n" if(mail($to, $subject, $msg, $headers)) echo "Thank you for submitting our form. We will get back to you as soon as possible."; else echo "There was a problem sending your email, please try again later."; ?> This should work, but it was off the top of my head. If you have any questions or it doesn't work let me know Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693091 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 Thank you. It looks right but I can't try it right now. I will post tomorrow if I have any problems Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693138 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 So I uploaded the info to the site and when I click on the submit button I am redirected to a blank page. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693661 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 did you upload contact_send.php to your server? Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693663 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 Yes Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693666 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 Ok, check the following line is in properly; <form id="form" action="contact_send.php"> If it's the same and it still doesn't work navigate to the contact_send.php page in your browser without using the form; http://www.yourdomain/contact_send.php Let me know what it says. Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693670 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 http://www.orientwatchusa.com/index-4-test.html Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693675 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 Blank Page Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693676 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 sorry, me being silly - <form id="form" action="contact_send.php" method="post"> Also does your server support php? Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693677 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 <?php $to = "you@your.com"; $subject = "Results from your Request Info form"; $headers = "From: Form Mailer"; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; if(!isset($_REQUEST['name']) || empty($_REQUEST['name'])) die('You must fill in all details'); else $msg .= "Name: {$_REQUEST['name']}\n" if(!isset($_REQUEST['email']) || empty($_REQUEST['email'])) die('You must fill in all details'); else $msg .= "Email: {$_REQUEST['email']}\n"; if(!isset($_REQUEST['phone']) || empty($_REQUEST['phone'])) die('You must fill in all details'); else $msg .= "Phone: {$_REQUEST['phone']}\n"; if(!isset($_REQUEST['message']) || empty($_REQUEST['message'])) die('You must fill in all details'); else $msg .= "Message: {$_REQUEST['message']}\n"; if(mail($to, $subject, $msg, $headers)) echo "Thank you for submitting our form. We will get back to you as soon as possible."; else echo "There was a problem sending your email, please try again later."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693678 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 Did you change something? Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693686 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 Yes, have you uploaded the new script? what's it doing now? Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693689 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 Not yet. I am waiting for an update on another page to finish Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693697 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 New script same problem Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693708 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 How would I know if the server accepts PHP? Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693712 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 I Did a quick test and I think so. Look Here: http://www.orientwatchusa.com/PHPTEST.PHP Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693714 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 Yes, PHP is ok, add the following to the start of you php page (contact_send.php) ini_set('error_reporting', E_ALL); This will print any errors in the code Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693734 Share on other sites More sharing options...
Firstaka Posted November 19, 2008 Author Share Posted November 19, 2008 I was able to figure it out. THANKS SO MUCH! Quote Link to comment https://forums.phpfreaks.com/topic/133252-solved-send-form-to-e-mail/#findComment-693736 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.