send the form information to my email box with php - php

<input type="button" class="button" />
<form action="" method="">
<input type="text" name="name" />
<input type="text" email="email" />
<input type="text" phone="phone" />
<textarea name="message"></textarea>
<input type="submit" class="submit"/>
</form>
1,click the button, then popup the form, after the user fills out all the information in the form than click the submit button, send all the form information to my eamil box.
how to write the action part. and which method should i use? should i use mail function to send the email or other ways?
i may use jquery to pop up the form window, but i don't know how to collect the form information,then send it my email box.

It is a very broad question, but in a nutshell this is how it is done:
Post the form to a php file that will handle it and use PHP mail() function to send it:
<form action="process.php" method="POST">
process.php:
<?php
if (isset($_POST)):
foreach ($_POST as $key=>$value):
$message = "$key : $value \n";
endforeach;
mail('mymail#example.com', 'My Subject', $message);
endif;

You need to post it then send the email. Also, <input type="text" email="email" /> needs to be <input type="text" name="email" /> need to use the name attribute.
Try this:
<?php
if (!empty($_POST)){
$send_message = 'Name: ' . $_POST[name] . ' Email: ' . $_POST[email] . ' Phone: ' . $_POST[phone] . ' Message: ' . $_POST[message];
mail('youremail#email.com', 'Subject', $send_message);
}
?>
<form action="" method="post">
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="phone" />
<textarea name="message"></textarea>
<input type="submit" class="submit"/>
</form>

Related

AMP form submission into database

Form Submission using Amp template is not working, I can't post data from amp-form by using php .Simply No action is getting performed. How to fix it?
Mypage: http://samiakhalil.com/theinfotime/amp/register1.php
<?php
if (isset($_POST['register'])) {
$name = $_POST['name'];
$email = $_POST['email'];
echo $name;
}
?>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<form method="post"
action-xhr="https://ampbyexample.com/components/amp-form/submit-form-input-text-xhr"
target="_top">
<input type="text" class="data-input" name="name" placeholder="Name" required>
<input type="email" class="data-input" name="email" placeholder="Email" required>
<input type="submit" value="Register" name="register" class="button button-primary">
</form>
add
<input type="hidden" name="register" value="a">
button name is empty, i dont know

how to get data from an html form and use it to make an email with php?

I want to send an email from the browser, but my PHP knowledge and experience are not enough.
So I have a html form
<form>
<textarea value="Message" required></textarea>
<input type="text" value="Name" required>
<input type="text" value="Email" required>
<input type="text" value="subject" required>
<input type="reset" value="Reset" >
<input type="submit" value="Submit">
</form>
My question here is how to fill this php code so I can get data from the html form and then send the email.
$to = "my_email#example.com";
$name =
$message =
$from =
$headers =
mail($to,$name,$subject,$message,$headers);
You have to add an action and a method (POST or GET) in your form
<form action="yourpage.php" method="POST">
After that add a name attribute at all your input :
<input type="text" value="Name" name="name" required>
<input type="text" value="Email" name="mail" required>
In yourpage.php
Here the method was POST so :
$_POST['name']; //Here get the posted value in input named 'name'
$_POST['mail'];
You need to set the action in the form, and get the $_POST in PHP code, here is an example:
<form action="test.php">
<textarea value="Message" required></textarea>
<input type="text" name="Name" value="Name" required>
<input type="text" name="Email" value="Email" required>
<input type="text" name="subject" value="subject" required>
<input type="reset" value="Reset" >
<input type="submit" value="Submit">
</form>
//test.php file
<?php
$to = "my_email#example.com";
$name = $_POST['Name'];
$message = $_POST['Message'];
$from = 'test#test.com';
$headers = 'your headers';
mail($to,$name,$subject,$message,$headers);
?>

html form entry data to my email [duplicate]

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

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"

PHP Not getting text from textbox

Whenever I enter text into the textbox, it is not properly transferring to PHP. PHP reads the input as null, when in reality, there is text in there.
PHP code.
//Two Email Lines
$email_to = "contact#mywebsite.com";
$email_subject = "AUTO: REQUEST";
//Set equal to email form textbox
$email_form = $_POST['email_text'];
$email_message = "Email: " . $email_form . "";
//Create email headers
#mail($email_to, $email_subject,$email_message,$headers);
HTML code for the form
<div id="form">
<form method="post" action="Email_Form_Script.php" enctype="text/plain" onsubmit="window.open('FormPopUp.html','popup','width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');" >
<div>
<input type="text" class="text" name="e3text" id="emailForm" value="Enter your e-mail address" onfocus="if(this.value=='Enter your e-mail address') { this.value = '' }" onblur="if(this.value=='') { this.value = 'Enter your e-mail address' }" />
<input type="hidden" value="" name="email2"/>
<input type="hidden" name="loc" value="en_US"/>
<input type="submit" class="submit" value=""/></div>
</form>
</div>
Really confused as to why it is not working. I keep getting empty emails that just say " Email: " (No text after Email).
The line:
$email_form = $_POST['email_text'];
needs to match the name of the text in the form which in your case is name="e3text" so you should use:
$email_form = $_POST['e3text'];
Its because your form doesn't actually contain an input element named email_text which is referenced in your PHP code. You need to structure your HTML form code to at least look like this or change your PHP code to require $_POST['e3text'].
<div id="form">
<form method="post" action="Email_Form_Script.php" enctype="text/plain" onsubmit="window.open('FormPopUp.html','popup','width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');" >
<div>
<input type="text" class="text" name="email_text" id="emailForm" value="Enter your e-mail address" onfocus="if(this.value=='Enter your e-mail address') { this.value = '' }" onblur="if(this.value=='') { this.value = 'Enter your e-mail address' }" />
<input type="hidden" value="" name="email2"/>
<input type="hidden" name="loc" value="en_US"/><input type="submit" class="submit" value="" />
</div>
</form>
</div>
try this in your php code
$email_form = $_POST['e3text'];
"e3text" is the name of your text box so in php use this name
When you hit the submit button of your form, values are passed as:
name of the input field = value of the input field
Your field is name e3text - please refer to such field in your script, i.e. $_POST['e3text'].

Categories