Help - Search - Members - Calendar
Full Version: Need help coding php script to send form data to email
HTMLHelp Forums > Programming > Server-side Scripting
icanswim70
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
pandy
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
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>
pandy
If it's safe, you mean? I'm afraid I'm not competent to judge that.
icanswim70
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?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.