submit form and send email in php

<?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:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_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.
    }
?>

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

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

</body>
</html> 

3
1
Nicolas Jove 120 points

                                    &lt;?php 
if(isset($_POST['submit'])){
    $to = &quot;[email protected]&quot;; // 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 = &quot;Form submission&quot;;
    $subject2 = &quot;Copy of your form submission&quot;;
    $message = $first_name . &quot; &quot; . $last_name . &quot; wrote the following:&quot; . &quot;\n\n&quot; . $_POST['message'];
    $message2 = &quot;Here is a copy of your message &quot; . $first_name . &quot;\n\n&quot; . $_POST['message'];

    $headers = &quot;From:&quot; . $from;
    $headers2 = &quot;From:&quot; . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo &quot;Mail Sent. Thank you &quot; . $first_name . &quot;, we will contact you shortly.&quot;;
    // 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=&quot;&quot; method=&quot;post&quot;&gt;
First Name: &lt;input type=&quot;text&quot; name=&quot;first_name&quot;&gt;&lt;br&gt;
Last Name: &lt;input type=&quot;text&quot; name=&quot;last_name&quot;&gt;&lt;br&gt;
Email: &lt;input type=&quot;text&quot; name=&quot;email&quot;&gt;&lt;br&gt;
Message:&lt;br&gt;&lt;textarea rows=&quot;5&quot; name=&quot;message&quot; cols=&quot;30&quot;&gt;&lt;/textarea&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt; 

3 (1 Votes)
0
4.25
4
A. M. 130 points

                                     
&lt;form method=&quot;post&quot; action=&quot;subscriberform.php&quot;&gt;
&lt;textarea name=&quot;message&quot;&gt;&lt;/textarea&gt;
&lt;input type=&quot;submit&quot;&gt;
&lt;/form&gt;

4.25 (4 Votes)
0
3.8
5
Colellis 125 points

                                    
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;FeedBack Form With Email Functionality&lt;/title&gt;
&lt;link href=&quot;css/elements.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;/head&gt;
&lt;!-- Body Starts Here --&gt;
&lt;body&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;!-- Feedback Form Starts Here --&gt;
&lt;div id=&quot;feedback&quot;&gt;
&lt;!-- Heading Of The Form --&gt;
&lt;div class=&quot;head&quot;&gt;
&lt;h3&gt;FeedBack Form&lt;/h3&gt;
&lt;p&gt;This is feedback form. Send us your feedback !&lt;/p&gt;
&lt;/div&gt;
&lt;!-- Feedback Form --&gt;
&lt;form action=&quot;#&quot; id=&quot;form&quot; method=&quot;post&quot; name=&quot;form&quot;&gt;
&lt;input name=&quot;vname&quot; placeholder=&quot;Your Name&quot; type=&quot;text&quot; value=&quot;&quot;&gt;
&lt;input name=&quot;vemail&quot; placeholder=&quot;Your Email&quot; type=&quot;text&quot; value=&quot;&quot;&gt;
&lt;input name=&quot;sub&quot; placeholder=&quot;Subject&quot; type=&quot;text&quot; value=&quot;&quot;&gt;
&lt;label&gt;Your Suggestion/Feedback&lt;/label&gt;
&lt;textarea name=&quot;msg&quot; placeholder=&quot;Type your text here...&quot;&gt;&lt;/textarea&gt;
&lt;input id=&quot;send&quot; name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Send Feedback&quot;&gt;
&lt;/form&gt;
&lt;h3&gt;&lt;?php include &quot;secure_email_code.php&quot;?&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;!-- Feedback Form Ends Here --&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;!-- Body Ends Here --&gt;
&lt;/html&gt;
Copy

3.8 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
submit form also on email php send submit form information to email php email htm form using php how to send email using php form PHP send email when post is submitted create an html form that on submit send an email with the fields php create an html form that upon submit send an email with the fields php php form submit action and send email php send email after form submitted how to send form into email using php send html form data to email using php php code to send form into email how to create a form in html and send it to email without php how to make a php form send to email create php to email form php submit form email simple php form to email php form send email on submit form php to email email with form php php form send to mail email on form submition php code send a form to email in php php email form info php form send data to email php form submit email php form post email email form data php how to make php form send email send form to email with php submit form php send mail code php submit form to email php email form result php email submit form get email from form php send email by php form php code for sending email from a form how to send form data to email in php php send form by email when we submit a form mail will sent in php sending form data to an email php form data send to email using php sending email php form html how to send an email via form php send email using php from a form send email form server email id php send form data email using php how to send email after form submit with php PHP email form code how to host email send form php how to send email with the form action php php form email address php form that sends email how to send data to email on submit in php how to send data to email from php form send an email when a contact form was submitted php get form data and send to email using php send email php form form to email php form email submit php send email from html form with php what is the output of php_email_form send php form to email explained php sending email form sending html form data to an email address using php process html form to email with php php email send form php form to email send form data to email php php send form data to email php form to email format php form to email script php send form to email php form send email form send email php send form data in email php send email through php form send html form to email php how to send email form php how to send data from html form to email in php how to send form data to email using php sending html form data to an email address without php submit form and send email in php Send an email on form submission using PHP php send an email from form send form input to email php php code for form submission to email send email from email address in php form How to send HTML form data to email using PHP how to send email from php form t how to send email from php form form to send email php php send html email form how to send an email from php form ho to get email on form php how to send form data to email php send email using html form and php form submit email php php code to send email from a form submission php send email from form send email from html form php sending an email on form submission using php send submitted information php to my email form email submit php code submit form to email php make an form to send email with php php form email send php send email form sending an email from form using php send email with php html form on submit sending form data into an email php form php email send send form email php send email with php from html form on submit not able to receive sender email id by php email form how to make a php script that sends an email after form is sbumbited send email using php after submitting form form action send email php send email when form is submitted php
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source