Need help coding php script to send form data to email, Form Submission |
Need help coding php script to send form data to email, Form Submission |
icanswim70 |
Sep 12 2019, 03:01 PM
Post
#1
|
Newbie Group: Members Posts: 15 Joined: 23-May 19 Member No.: 26,898 |
Hey everyone,
I got everything ready for launch, just need this last bit done. Heres the form on the site (attached) Heres what i need: A php script to capture the "name" "email" and "enjoy" fields, and send them to my email address. Code with fields i want to capture: <div class="formstyle"> <form class="formz"> <p class="formtext">Your Name</p><input type="text" name="fullname" placeholder="What is your name?" required> <p class="formtext">Your Email</p><input type="text" name="email" placeholder="What is your email address?" required> <p class="formtext">Did you enjoy the site?</p> <label class="yesandno"> <input type="checkbox" name="enjoy"> <span class="slider"></span> </label><button type="submit">Submit</button> </form></center> </div> If anyone can code it that'd be a massive help. Thanks This post has been edited by icanswim70: Sep 12 2019, 03:06 PM Attached thumbnail(s) |
pandy |
Sep 12 2019, 03:47 PM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
There are oodles of ready-made form handling scripts.
Here you find a bunch in PHP. Check the corresponding category for other languages. https://www.hotscripts.com/category/scripts...orm-processors/ Take a little care choosing one though, read comments, google. There are probably still vulnerable scrips around. |
icanswim70 |
Sep 13 2019, 10:43 AM
Post
#3
|
Newbie Group: Members Posts: 15 Joined: 23-May 19 Member No.: 26,898 |
There are oodles of ready-made form handling scripts. Here you find a bunch in PHP. Check the corresponding category for other languages. https://www.hotscripts.com/category/scripts...orm-processors/ Take a little care choosing one though, read comments, google. There are probably still vulnerable scrips around. Thanks for your response. I found a free script i like, and have modified it, does it look correct? PS*** I KNOW SCRIPT WONT WORK ON LOCAL COMPUTER WHICH IS FINE*** Just need it to be good for live launch Heres the script i modified... <?php $errors = ''; $myemail = 'ifixitforyou70@gmail.com';//<-----Put Your email address here. if(empty($_POST['fullname']) || empty($_POST['email']) || empty($_POST['enjoy'])) { $errors .= "\n Error: all fields are required"; } $name = $_POST['fullname']; $email_address = $_POST['email']; $message = $_POST['enjoy']; if (!preg_match( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address"; } if( empty($errors)) { $from = 'effb@hotmail.com'; $to = 'ifixitforyou70@gmail.com'; $email_subject = "Thank you for subscribing: $name"; $email_body = "You have received a new message. ". " Here are the details:\n Name: $name \n Email: $email_address \n Did they enjoy the site? : $message"; $headers = "From: $myemail\n"; $headers = "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); //redirect to the 'thank you' page header('Location: contact-form-thank-you.html'); } ?> <!DOCTYPE HTML> <html lang="en" target="_blank"> <head> <title>Thank You!</title> </head> <body> <!-- This page is displayed only if there is some error --> <?php echo nl2br($errors); ?> </body> </html> And the html it refers to: <form name="subscribe" class="formz" action="contact-form-handler.php" method="post"> <p class="formtext">Your Name</p><input type="text" name="fullname" placeholder="What is your name?" required> <p class="formtext">Your Email</p><input type="text" name="email" placeholder="What is your email address?" required> <p class="formtext">Did you enjoy the site?</p> <label class="yesandno"> <input type="checkbox" name="enjoy"> <span class="slider"></span> </label><button type="submit">Submit</button> </form></center> This post has been edited by icanswim70: Sep 13 2019, 10:45 AM |
pandy |
Sep 13 2019, 11:09 AM
Post
#4
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
If it's safe, you mean? I'm afraid I'm not competent to judge that.
|
Lo-Fi Version | Time is now: 28th March 2024 - 11:41 PM |