html form entry data to my email [duplicate] - php

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I have a form on my website for people to fill out and I just want the information to be sent to me in an email when they press the submit button but i'm struggling with the PHP for it.
below is the form I have
<form action="senddata.php">
<label for="fullname"> full name:</label><br>
<input type="text" name="fullname" id="fullname"><br><br>
<label for="psn">PSN</label><br>
<input type="text" name="psn" id="psn"><br>
<label for="email">Email:</label><br>
<input type="text" name="email" id="email"><br>
<label for="contact"> Contact number</label><br>
<input type="text" name="contact" id="contact"><br>
<label for="team">Team supported</label><br>
<input type="text" name="team" id="team"><br>
<input type="submit" value="SUBMIT FORM">
</form>

This is how you should implement this.
<?php
if(isset($_POST['submit']))
{
$msg = "Full Name:".$_POST['fullname']."\n PSN:".$_POST['psn']."\n Email:".$_POST['email']."\n contact:".$_POST['contact']."\n Team:".$_POST['team'];
$msg = wordwrap($msg,70);
$header = 'From: yourmail#yourmail.com>' . "\n";
// send email
mail("'".$_POST['email']."'","Your mail subject goes here",$msg,$header);
}
?>
<form action="senddata.php" method="post">
<label for="fullname"> full name:</label><br>
<input type="text" name="fullname" id="fullname"><br><br>
<label for="psn">PSN</label><br>
<input type="text" name="psn" id="psn"><br>
<label for="email">Email:</label><br>
<input type="text" name="email" id="email"><br>
<label for="contact"> Contact number</label><br>
<input type="text" name="contact" id="contact"><br>
<label for="team">Team supported</label><br>
<input type="text" name="team" id="team"><br>
<input type="submit" name="submit" value="SUBMIT FORM">
</form>
you should add method for send your data. method="post"and you should use a name for your submit button to check whether your form is submitted or notname="submit"
refer this: php.net

Related

How to create a form that doesn't open email client when submitting the form

I am coding up a website and have added a contact form. When I try and test out the form by submitting, it will just open up the email client for me to send it through the email client (it's opening up my apple mail automatically). I want the user to be able to submit the form without the email client on their device opening up, then I want to receive an email saying that a customer has sent me a message from my website. how do I do this? what am I missing or doing wrong?
<form method="post" action="myemailhere#gmail.com" action="action_page.php">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name...">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name...">
<label for="country">e-mail</label>
<input type="text" id="lname" name="lastname" placeholder="Your e-mail address...">
<label for="subject">Subject</label>
<textarea id="subject" name="subject" placeholder="Write something..." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
</div>
<form method="post" action="nuramelodyhill#gmail.com" >
<input type="submit" value="Send Email" />
</form>
Just Remove the action="myemailhere#gmail.com" - it will be work.
in PHP you can simply send email with
mail($to,$subject,$message);
Your code should be like this:
<form method="post" action="action_page.php">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name...">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name...">
<label for="country">e-mail</label>
<input type="text" id="email" name="email" placeholder="Your e-mail address...">
<label for="subject">Subject</label>
<textarea id="subject" name="subject" placeholder="Write something..." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
</div>
action_page.php
$subject=$_POST['subject'];
$message="First Name:".$_POST['firstname']."\n Last Name:".$_POST['lastname']." Email:".$_POST['email']."\n Subject:".$_POST['subject'];
mail($to,$subject,$message);
And also you using 2 forms here. If you want to use multiple forms on the same page, use JavaScript to fire the event.

How to use php to output details of a form from HTML5

<form id="superheroForm" action="submit.php" method="post">
<p><i>Please complete the form. Mandatory fields are marked with a </i><em>*</em></p>
<fieldset>
<legend>Contact Details</legend><br>
<label for="Name">Name <em>*</em></label>
<input id="name" name="name" placeholder="Jane " autofocus required><br>
<label for="telephone">Telephone <em>*</em></label>
<input id="telephone" placeholder="(xxx) xxx-xxxx" title="must be in the following format (xxx)-xxx-xxxx"
pattern=[0-9]{3}-[0-9]{3}-[0-9]{4} required><br>
<label for="email">Email <em>*</em></label>
<input id="email" type="email" required><br><br>
</fieldset>
</form>
I have another file named submit.php. Once the user clicks on submit application button, I am supposed to get the php response something like this:
Thanks for submitting your form
Name:
Telephone:
So far I have tried this directly in a new file named submit.php but it doesn't work at all: This is my php code:
<html>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</html>
</body>
Update:Solution: Sorry I did not install PHP the right way.
your php code should contain something like this
<?php
$name = $_POST['name'];
//then just echo them
echo $name;
?>
Change your superhero form like this..
<form id="superheroForm" action="submit.php" method="post">
<p><i>Please complete the form. Mandatory fields are marked with a </i><em>*</em></p>
<fieldset>
<legend>Contact Details</legend><br>
<label for="Name">Name <em>*</em></label>
<input type="text" id="name" name="name" placeholder="Jane " autofocus required> <br>
<label for="telephone">Telephone <em>*</em></label>
<input id="telephone" placeholder="(xxx) xxx-xxxx" name="tel" required><br>
<label for="email">Email <em>*</em></label>
<input id="email" type="email" required><br><br>
</fieldset>
</form>
and Your submit.php is like this
<?php
if(isset($_POST['name'])){
echo "Thanks for submitting your form ";
echo "Name:".$_POST['name'];
echo "Telephone:".$_POST['tel'];
}
?>
This is it.

How to send form data from my website to my email using php

I want to be able to send form data from my website to my email with php. However, I tried all of the examples online and none of them worked for me. I don't know why. Am I missing a plugin?
<form class="formmargin" id="email-form" action="send_form_email.php" method="post" target="iframe_dbcpmgmy" onsubmit="sent_dbcpmgmy = true" enctype="multipart/form-data">
<div style="float:left; width:50%; padding-right:2.5%">
<label for="name">Name:</label>
<input class="w-input" type="text" name="name" placeholder="Enter your name" id="name" required="required" data-name="Name">
<label for="company_name">Company Name:</label>
<input class="w-input" type="text" name="company_name" placeholder="Enter your company name" id="company_name" required="required" data-name="Company Name">
</div>
<div style="float:left; width:50%; padding-left:2.5%">
<label for="email_address">Email Address:</label>
<input class="w-input" type="email" name="email_address" placeholder="Enter your email address" id="email_address" required="required" data-name="Email Address">
<label for="phone_number">Phone Number:</label>
<input class="w-input" type="text" name="phone_number" placeholder="Enter your phone number" id="phone_number" required="required" data-name="Phone Number">
<label for="uploaded_file">Upload a file (Optional)</label>
<input type="file" name="uploaded_file" id="uploaded_file">
</div>
<input style="clear:both" type="submit" name="submit" value="Submit" class="submitbutton">
</form>
can someone tell me what i should put in the send_form_email.php file?
You will want to create a second page getting all of the post information then you will want to use the php mail function.
If you haven't already created the post variables they will look like this
$name = $_POST['name'];
$company = $_POST['company_name'];
$to = $_POST['email_address'];
If you want to format it to have new lines in the message, because by default it will be one huge line use \n as no html/css formatting will work easily
mail ($to , $subject , $message );

Receive form data on email

How may I get data of this form to be received in an email?
<form class="pa">
<fieldset>
<label>Name <em>*</em></label>
<input type="text" placeholder="">
<label>Email <em>*</em></label>
<input type="text" placeholder="">
<label>Age <em>*</em></label>
<input type="text" placeholder="">
<label>Phone <em>*</em></label>
<input type="text" placeholder="">
<label>Zip Code <em>*</em></label>
<input type="text" placeholder="">
<a class="submit pa" href="#"><img src="wp-content/themes/child/img/submit.png"</a>
</fieldset>
</form>
You'll need a server-side script to accept the form data, and send an email with it. You can do this PHP and several other languages. Judging by your sample code you have WordPress, so you might look into the ContactForm plugin.
wrap your input's with something like
<form class="pa" action="yourscript.php" method="post">
.
.
<label for="name">Name <em>*</em></label>
<input type="text" placeholder="" id="name" name="name">
.
<input type="submit" value="Submit" />
<!-- remove the a tag because that won't submit your form data or use type="image" -->
<input type="image" src="wp-content/themes/child/img/submit.png" />
</form>
then use $_POST['name'] to retrieve the value
you have to add name='' to each inputs to have them sent to your script eg <input type="text" id="name" name="name"> and they have to be different otherwise they might get overridden.
also your labels will need the for= to be useable which uses the id of the input eg <label for="name">Name <em>*</em></label>

Why won't my PHP form send emails correctly?

It sends the email, but without a body, subject or anything. This is what I get:
HTML:
<div class="contact-form">
<form action="mail.php" method="post">
<label for="name">Name:<input type="text" id="name" class="text" /></label>
<label for="email">Email:<input type="text" id="email" class="text" /></label>
<label for="message">Message:<textarea id="message"></textarea></label>
<input type="submit" class="submit" value="Send Message" />
</form>
</div>
PHP (mail.php):
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$recipient = "me#christianselig.com";
$subject = "Message From Website";
$headers = "From: " . $email;
mail($recipient, $subject, $message, $headers);
echo "Thanks! The message was sent. :)";
?>
Any insight? Thanks so much.
Forms fields are based on their names not their ids.
replace your :
id="(...)"
by
id="(...)" name="(...)"
You should have a look to Swift Mailer which is strongly safer than your current method.
You need to have a name attribute on your HTML input fields. That's what the form uses to create the indexes in the $_POST array. Corrected HTML is below
<div class="contact-form">
<form action="mail.php" method="post">
<label for="name">Name:<input type="text" id="name" name="name" class="text" /></label>
<label for="email">Email:<input type="text" id="email" name="email" class="text" /></label>
<label for="message">Message:<textarea id="message" name="message"></textarea></label>
<input type="submit" class="submit" value="Send Message" />
</form>
</div>
you need to give name attribute for each html element . Use below html code:
<div class="contact-form">
<form action="mail.php" method="post">
<label for="name">Name:<input type="text" id="name" name="name" class="text" /></label>
<label for="email">Email:<input type="text" id="email" name="email" class="text" /></label>
<label for="message">Message:<textarea id="message" name="message"></textarea></label>
<input type="submit" class="submit" value="Send Message" />
</form>
</div>
Into my server works, are you sure that in $_POST are set?
If you can't send email assicure you can try to set SMTP to send your email
Try to use something like phpmailer to send email.
In your form for every field you have to put:
- id="example_id"
- name="example_name"

Categories