/    Sign up×
Community /Pin to ProfileBookmark

HTML Form…Submit to E-Mail

**hello again…**

Have to create 4 or 5 online forms for a website I built for my local area of NA. I found a basic HTML Form template at w3schools; & used that for my first form:

https://www.burlingtoncountyna.org/gsr.report.html

So…when users finish & hit the Submit button, the form (& all included info) needs to go to our secretary’s e-mail. I’ve read everything I can get my hands on regarding PHP, but for a beginner coder such as myself…informationals on the web never tell you precisely *take this snippet…customize it thusly; & place it here*…even the instructionals on w3schools are vague on this topic (for people such as myself). So…can someone take a look at that form page; & point me in the right direction, at least?

thanx,

**mark4man**

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@HarshShahNov 11.2020 — @doxology#1624915

It is better to use header('Location: thank_you.php'); instead of echo in the PHP handler to redirect the user to another page afterward.

Copy the entire code below into one file.

``<i>
</i>&lt;?php
if(isset($_POST['submit'])){
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "nn" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "nn" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?&gt;

&lt;!DOCTYPE html&gt;
&lt;head&gt;
&lt;title&gt;Form submission&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form action="" method="post"&gt;
First Name: &lt;input type="text" name="first_name"&gt;&lt;br&gt;
Last Name: &lt;input type="text" name="last_name"&gt;&lt;br&gt;
Email: &lt;input type="text" name="email"&gt;&lt;br&gt;
Message:&lt;br&gt;&lt;textarea rows="5" name="message" cols="30"&gt;&lt;/textarea&gt;&lt;br&gt;
&lt;input type="submit" name="submit" value="Submit"&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;<i>
</i>
``
×

Success!

Help @doxology spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...