Submitting Form Not Displaying Variables - html

When I submit my form an email is sent to my email address with details entered in the form but when I recieve the email the data is blank here is my code
<?php
$form = '<form action="test2.php" method="POST">
<table width="300" style="border: 1px solid black;">
<tr>
<td>Name <td><input type="text" id="name">
<tr>
<td>Phone Number <td><input type="text" id="telephone">
<tr>
<td colspan="2">
<input type="submit" name="submit" value="submit"/></div>
</tr>
</table>';
echo $form;
$to = 'redacted#redacted.redacted';
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$body = "<div>Name: $name <br>Telephone Number: $telephone<br></div>";
// subject
$subject = 'Call Back Requested';
// message
$message = $body;
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Call Back Request <contact-us-form#yellowgrid.co.uk>' . "\r\n";
if(isset($_POST['submit'])){
mail($to, $subject, $message, $headers);
}
?>
The problem is when I submit the form the I recieve an email that says
Name (Nothing)
Phone Number (Nothing)
Can anyone tell me where I am going wrong
Thanks In Advance
Adam

You have to specify the name attribute for your inputs:
<input type="text" id="name" name="name">
<input type="text" id="telephone" name="telephone">
instead of
<input type="text" id="name">
<input type="text" id="telephone">

Just after a quick look you should swap your $body to read
$body = '<div>Name: ' . $name . '<br>Telephone Number: ' . $telephone . '<br></div>';
Try that out and see if it works

you have alot of mistakes in closing tags .. and its bad practice to display a whole html form using echo .. check out this code:
<?php
extract($_POST);
if ( isset($submit) )
{
$to = 'adam.albison#yellowgrid.co.uk';
$body = "<div>Name: $name <br>Telephone Number: $telephone<br></div>";
$subject = 'Call Back Requested';
$message = $body;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:' . "\r\n";
$headers .= 'From: Call Back Request <contact-us-form#yellowgrid.co.uk>' . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
<html>
<form action="test2.php" method="POST">
<table width="300" style="border: 1px solid black;">
<tr>
<td>Name </td>
<td> <input type="text" id="name" name="name" /> </td>
</tr>
<tr>
<td>Phone Number </td>
<td> <input type="text" id="telephone" name="telephone" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" name="submit" value="submit"/> </td>
</tr>
</form>
</html>

Related

PHP mail () function sending email

Here is the trouble I'm having I have a page called contacts.html on this page I have a contact form with the following code
` <h2 class="top-1 p3">Contact form</h2>
<form id="form" method="post" action="html_form_send.php" >
<fieldset>
<label for="first_name"><strong>First Name:</strong><input type="text" name="first_name" value=""></label>
<label for="last_name"><strong>Last Name:</strong><input type="text" name="last_name" value=""></label>
<label for="email"><strong>Email:</strong><input type="text" name="email" value=""></label>
<label for="telephone"><strong>Phone:</strong><input type="text" name="telephone" value=""></label>
<label for="comments"><strong>Your Message:</strong><textarea></textarea></label>
<br> <div class="btns">ClearSend</div>`
This isn't the whole code just the part containing the form. I'm using GoDaddy to host and it doesn't support X-mailer. I have to use the PHP's mail( ) function. So I've been looking at [http://php.net/manual/en/function.mail.php][1]. Below is the code I have in the html_form_send.php file. The form sends this is just a template I'm not sure how to get the values (ex: first_name, last_name, comments) and write it into the php file. I tried doing $to = $_POST['first_name']; and then using .$data['first_name'] but that didn't work. Please discard the random table info
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
[1]: http://us2.php.net/manual/en/function.mail.php
Thanks!

Website contact Form Problems

Firstly I've searched current thread's and tried 99% of the working fixes provided by the community,
My problem is i am receiving no email's via
www.vapescotts.co.uk
This contact form is placed at the bottom, The odd thing is the website is an altered version of a working website. So I'm clueless to why this version don't work.
<form name="htmlform" method="post" action="html_form_send.php">
<table width="100%">
</tr>
<tr>
<td valign="top">
<label for="first_name"><p>First Name</p></label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="50">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name"><p>Last Name</p></label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="email"><p>Email Address</p></label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone"><p>Telephone Number</p></label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="50">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments"><p>Your Comments</p></label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="38" rows="12"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:left">
<input type="image" src="submit.png" input type="submit" value="Submit" height: "251px"; width: "293px"></i>
</td> </td>
</tr></tr>
</table></table>
</form></form>
</div> </div>
And here is the html_form_send.php configuration
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "vapescotts#gmail.com";
$email_subject = "Scotts Custard Cream Enquiry";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for your enquiry, Redirecting back to Scott's Custard Cream.
<br />If you are not redirected automatically,<a href='http://www.vapescotts.co.uk'>Click Here</a>
<meta http-equiv="refresh" content="3;url=http://www.vapescotts.co.uk" />
<?php
}
die();
?>
Thank's again to the StackOverflow Community.
some servers block mail function better to try SMTP PHP Mailer.
Here we go send email using Gmail SMTP server through PHP Mailer
Try this code, might help you out. Edit this code as per your convenience.
$to = "webmaster#example.com";
$subj = "Contact Form Request";
$body = "There is a new contact form report, Kindly check it out.";
$body .= "<table border='1' cellpadding='5'>";
$body .= "<tr><td>Name:</td><td>".$name."</td></tr>";
$body .= "<tr><td>Email:</td><td>".$email."</td></tr>";
$body .= "<tr><td>Subject:</td><td>".$subject."</td></tr>";
$body .= "<tr><td>Message:</td><td>".$msg."</td></tr>";
$body .= "</table>";
$headers = "From: $email" . "\r\n";
$headers .= "Reply-To: " . strip_tags($email) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$succ = mail( $to, $subj, $body, $headers );
if ( $succ || $succ != '' ) {
echo "Mail Sent";
} else {
echo "Failed";
}

emailing the contents of a form

How would I create a form in HTML that would email the content of the form to an email? Here is what I have.
<form action="mailto:email#example.com" enctype="text/plain" method="post">
<input name = "subject" placeholder = "Your Name"></input>
<br>
<textarea name = "message" placeholder = "Email Us." style = "height:100px;"></textarea>
<input type="submit" value="Submit" placeholder = "Submit"></input>
</form>
could I do this solely in HTML with the mailto: action? or would i need some php like
mail('email#example.com', $_POST['subject'], $_POST['message']);
Any suggestions?
Please try to use header as well to sending a email.
<?php
$to = 'connormemail#gmail.com';
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: connormemail#gmail.com' . "\r\n";
$retval = mail($to, $subject, $message, $headers);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
So there is all kind of wrong in what I'm about to post. Such as don't use tables to style your forms, etc. But I'm taking this off another site so it'll be simple. What you need is a mix of html for the form and php for the mailing.
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
Email Form
</td>
</tr>
</table>
So there is your basic form.
Here is your basic php. Place it in the same directory as your .html file: send_form_email.php (you must use this filename exactly)
Make sure to edit the parts indicated with your email and subject line.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
If you need to see this tutorial in it's entirety, it's located here:http://www.freecontactform.com/email_form.php
In order to make a custom form it is pretty easy to edit the html and related php elements, but if you don't know any php, etc. I'd just stick to the premade forms.

On button event send an mail in html

I'm using the following HTML:
<div>
<form method="post" action="mailto:hr#kine.com" >
<input type="submit" value="Send Email" />
</form>
</div>
However, when I try and load the page, I get the following error:
No webpage was found for the web address
Why does this happen, and how can I fix this?
Try below code to send email using php & html
<div>
<form method="post">
<input type="submit" name='submit' value="Send Email" />
</form>
</div>
<?php
if(isset($POST['submit']){
$to = 'hr#kine.com';
$subject = 'Website Change Reqest';
$headers = "From: test#example.com\r\n";
$headers .= "Reply-To: test#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = 'Test Email';
$message .= '<h1>Hello, World!</h1>';
mail($to, $subject, $message, $headers);
}
?>
I hope it can help you.

Call PHP form from HTML

contact-form.html
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
contact-form-handler.php
<?php
$errors = '';
$myemail = 'net.dev#spikyarc.net';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
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))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new 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');
}
?>
This both file i have put in wwwroot folder but when i submit html form it gives error The page cannot be displayed. I cannot find problem. Thanks for helping me.
set the action in the HTML form to:
contact-form-handler.php
like:
<form method="POST" name="contactform" action="contact-form-handler.php">
UPDATE 1: And check this:
Change
$email_subject = "Contact form submission: $name";
to
$email_subject = "Contact form submission:" . $name;
UPDATE 2: And this also:
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
to:
$headers = "From: " . $myemail . "\n";
$headers .= "Reply-To:" . $email_address;
UPDATE 3:
You validate the E-mail address $email_address but never use it.
Be sure to check the filename with that in the action!!