The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Need help coding php script to send form data to email, Form Submission
icanswim70
post 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)
Attached Image
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 12 2019, 03:47 PM
Post #2


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 18,402
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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
icanswim70
post Sep 13 2019, 10:43 AM
Post #3


Newbie
*

Group: Members
Posts: 15
Joined: 23-May 19
Member No.: 26,898



QUOTE(pandy @ Sep 12 2019, 04:47 PM) *

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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 13 2019, 11:09 AM
Post #4


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 18,402
Joined: 9-August 06
Member No.: 6



If it's safe, you mean? I'm afraid I'm not competent to judge that.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
icanswim70
post Sep 13 2019, 11:23 AM
Post #5


Newbie
*

Group: Members
Posts: 15
Joined: 23-May 19
Member No.: 26,898



It appears to have basic error checking, and I know theres other php validation measures you can take, but for the simplicity of this site i'm hoping what's in the script already will suffice.

My question was does everything look like its linked correctly and email will send?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th October 2019 - 10:13 PM