PHP Email Function sending a blank body message with subject & sender email - php

I am trying to make a quote forum that sends the input to an email. I have PHP sending the email, displaying the subject and the senders email, but it doesn't display the main body of content in the email that is sent.. here is my code:
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<div class="quote_text">Send us some of your information and we will get back to you as soon as possible. Let's get this ball rolling.</div>
<br /><br />
<span class="important">* = required fields</span><br />
<form action="" method="POST" enctype="multipart/form-data">
<table width="814" height="310" border="0">
<tr>
<td width="419">
<input type="hidden" name="action" value="submit">
Your Name:<span class="important">*</span><input name="name" type="text" value="" size="30"/><br /><br />
Your Email:<span class="important">*</span><input name="email" type="text" value="" size="30" placeholder="example#example.com"/><br /><br />
Phone Number:<input name="phone" type="text" value="" size="10" maxlength="12" placeholder="(xxx)-xxx-xxxx" /><br /><br />
Company Name:<input name="company_name" type="text" value="" size="30"/><br /> <br />
</td>
<td width="385">
Address of Installation:<span class="important">*</span>
<input name="install_address" type="text" value="" size="30"/><br /><br />
City:<span class="important">*</span><input name="city" type="text" value="" size="30"/><br /><br />
State:<span class="important">*</span><input name="state" type="text" value="" size="30"/><br /><br />
Zip Code:<span class="important">*</span><input name="zip" type="text" value="" size="30"/><br /><br /><br /><br />
</td>
</tr>
<tr>
<td height="102">
Fence Type Description:<br /><textarea name="description" rows="6" cols="45"></textarea>
Number of Corners:<input name="corners" type="text" value="" size="30"/>
</td>
<td><br />
Linear Feet:<input name="linear" type="text" value="" size="30"/><br />
OR<br />
Acres:<input name="acres" type="text" value="" size="30"/><br /><br />
Number of Gate Openings:<input name="gate_opening" type="text" value="" size="30"/>
</td>
</tr>
</table><br><br>
<input type="submit" value="Send email"/>
</form>
<?php
} else {
// Grab forum elements and push into variables for the email
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$company_name = $_REQUEST['company_name'];
$install_address = $_REQUEST['install_address'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$zip = $_REQUEST['zip'];
$description = $_REQUEST['description'];
$corners = $_REQUEST['corners'];
$linear = $_REQUEST['linear'];
$acres = $_REQUEST['acres'];
$gate_opening = $_REQUEST['gate_opening'];
//Build Email
$message="$name<br />
$email<br />
$phone<br />
$company_name<br />
$install_address<br />
$city<br />
$state<br />
$zip<br />
$description<br />
$corners<br />
$linear<br />
$acres<br />
$gate_opening<br />";
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($install_address="")||($city="")||($state="")|| ($zip=""))
{
echo "Please fill the required fields. Click here to try again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Blue Ridge Fencing - Quote Forum";
mail("info#blueridgefenceco.com", $subject, $message, $from);
echo "Email sent! We will get back to you as soon as possible.";
}
}
?>
Thank you so much for you help!

Related

How to get POST Form data into an email

I am making a form for my customer to fill out when they order a product.
I am trying to make it so when they hit submit it emails the data to my email and it cc's them. The email will have styling in it. I can't figure out how to get it to put the data into the email. I am currently using PHPMailer.
Here is the php file
<?php
$FirstName = $_POST['First_Name'];
$LastName = $_POST['Last_Name'];
$Email = $_POST['Email'];
$Company = $_POST['Company'];
$dochtml = new DOMDocument();
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SetFrom('No-Reply#LDSVacuum.com');
$mail->Subject = 'Request';
$mail->AddAddress('Chase.Price#LDSVacuum.com');
$mail->AddCC($Email);
$strhtml = '
<div align="center">
<font face="arial" color="#336699" size="6">
Request
</font>
</div>
<div>
<font face="arial" color="#336699" size="5">
Customer Information
</font>
<p>
<label for="fname">
<font face="arial" color="#336699" size="4">
First Name:
</font>
</label>
<br />
<input type="text" name="fname" id="fname" size="50">
</p>
<p>
<label for="lname">
<font face="arial" color="#336699" size="4">
Last Name:
</font>
</label>
<br />
<input type="text" name="lname" id="lname" size="50">
</p>
<p>
<label for="email">
<font face="arial" color="#336699" size="4">
Email Address:
</font>
</label>
<br />
<input type="text" name="email" id="email" size="50">
</p>
<p>
<label for="company">
<font face="arial" color="#336699" size="4">
Company Name:
</font>
</label>
<br />
<input type="text" name="company" id="company"size="50">
</p>
</div>
';
$dochtml->loadHTML($strhtml);
$fname = $dochtml->getElementById('fname');
$fname->value=$FirstName;
$lname = $dochtml->getElementById('lname');
$lname->value=$LastName;
$email = $dochtml->getElementById('email');
$email->value=$Email;
$company = $dochtml->getElementById('company');
$company->value=$FirstName;
$mail->Body = $strhtml;
$mail->Send();
if(!$mail->Send()) {
echo 'Unknown Error has Occured. Please try again Later.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}else {
echo 'Thank You, $FirstName . We have emailed your request to Info#LDSVacuum.com . Your email $Email has been cc to the email.';
}
?>
Here is the form
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="POST" name="contactform" autocomplete="off" id="nipplerequest" action="http://localhost/emailform.php">
<p>
<label for='First_Name' class="FG3" width="157">
<span class="red">
*
</span>
First Name:
</label>
<br />
<input type="text" name="First_Name" id="First_Name" class="FG2" size="50" placeholder="John">
<br />
<label for='Last_Name' class="FG3">
<span class="red">
*
</span>
Last Name:
</label>
<br />
<input type="text" name="Last_Name" class="FG2" size="50" placeholder="Johnson">
<br />
<label for='Email' class="FG3">
<span class="red">
*
</span>
Your Email Address:
</label>
<br />
<input type="text" name="Email" id="Email" class="FG2" size="50" placeholder="John_Johnson#company.com">
<br />
<label for='Company' class="FG3">
<span class="red">
*
</span>
Company Name:
</label>
<br />
<input type="text" name="Company" class="FG2" size="50" placeholder="Company Inc.">
<br />
</p>
</form>
<br />
<input type="Submit" value="Submit">
You are:
Creating a string of HTML
Creating a DOM from that string of HTML
Modifying that DOM by setting values
Emailing the original string of HTML and ignoring the DOM you generated
You need to convert the DOM back into HTML ($modified_html = $dochtml->saveHTML()) and send that instead of your original string.

Second submit button not working in php

I have been having problems with the second button not running like the first button. this is the code I have:
<p>
<form method="POST">
<input placeholder="Username" type="text" name="username"><br /><br />
<input placeholder="password" type="password" name="password"><br /><br />
<input value="Login" type="submit" name="log_In">
</form>
</p>
</div>
<?php
if(isset($_POST['log_In'])) {
#$f_name = $_POST['fname'];
#$s_name = $_POST['sname'];
#$stud_Id = $_POST['studId'];
#$uname = $_POST['uname'];
#$pass = $_POST['pass'];
#$rpass = $_POST['rpass'];
#$email = $_POST['email'];
#$remail = $_POST['remail'];
#var_dump($f_name);
header("Location:home.php");
}
?>
</div>
<div align="right">
<div>
<p>
<h2>Sign Up</h2>
</p>
<p>
<form>
<input placeholder="Forename" type="text" name="fname" id="Forename"><br /><br />
<input placeholder="Surname" type="text" name="sname"><br /><br />
<input placeholder="Student Id" type="text" name="studId"><br /><br />
<input placeholder="Username" type="text" name="uname"><br /><br />
<input placeholder="password" type="password" name="pass" min="6" max="32"><br /><br />
<input placeholder="Re-type password" type="password" name="rpass" min="6" max="32"><br /><br />
<input placeholder="Email" type="" name="email"><br /><br />
<input placeholder="Re-type Email" type="remail" name="remail"><br /><br />
<input value="Sign Up" type="submit" name="sign_Up">
</form>
</p>
</div>
<?php
if(isset($_POST['sign_Up'])) {
header("Location:home.php");
}
?>
</div>
"if(isset($_POST['sign_up'])) {" is not being run and is just refreshing the page and removing all items from the form.
thanks
By default <form> method is GET. So if(isset($_POST['sign_Up'])) won't work. Change it to if(isset($_GET['sign_Up'])).
Or change your second form tag to:
<form method="POST">
Remember not to use header function after generating HTML content, move it to top!
header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
So it will be better if it is like this:
<?php
if(isset($_POST['log_In']) || isset($_POST['sign_Up'])) {
header("Location:home.php");
}
?>
<form method="POST">
<input placeholder="Username" type="text" name="username">
<br />
<br />
<input placeholder="password" type="password" name="password">
<br />
<br />
<input value="Login" type="submit" name="log_In">
</form>
<div align="right">
<div>
<p>
<h2>Sign Up</h2>
</p>
<p>
<form method="post">
<input placeholder="Forename" type="text" name="fname" id="Forename">
<br />
<br />
<input placeholder="Surname" type="text" name="sname">
<br />
<br />
<input placeholder="Student Id" type="text" name="studId">
<br />
<br />
<input placeholder="Username" type="text" name="uname">
<br />
<br />
<input placeholder="password" type="password" name="pass" min="6" max="32">
<br />
<br />
<input placeholder="Re-type password" type="password" name="rpass" min="6" max="32">
<br />
<br />
<input placeholder="Email" type="" name="email">
<br />
<br />
<input placeholder="Re-type Email" type="remail" name="remail">
<br />
<br />
<input value="Sign Up" type="submit" name="sign_Up">
</form>
</p>
</div>
</div>
You forgot to add method="post"
<form method="post">
<input placeholder="Forename" type="text" name="fname" id="Forename"><br /><br />
<input placeholder="Surname" type="text" name="sname"><br /><br />
<input placeholder="Student Id" type="text" name="studId"><br /><br />
<input placeholder="Username" type="text" name="uname"><br /><br />
<input placeholder="password" type="password" name="pass" min="6" max="32"><br /><br />
<input placeholder="Re-type password" type="password" name="rpass" min="6" max="32"><br /><br />
<input placeholder="Email" type="" name="email"><br /><br />
<input placeholder="Re-type Email" type="remail" name="remail"><br /><br />
<input value="Sign Up" type="submit" name="sign_Up">
</form>
in second form you have not define the method if method is not defined it will accept the GET method default so change your second form tag by
<form action="" method="POST">

PHP - How can a load page do some of the php

I wish every time I reload or refresh the page. The disabled textbox still disabled. Because my purpose is to modify the textbox once time and then it will be disabled forever. Is this possible?
Below is my code
<tr>
<td><?php echo $lang_txt['leader_id'][$lang]; ?></td>
<td>:</td>
<td><?php if($_POST['txtLeaderID'] == ""){?><input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php }
else
{
?>
<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php
}
?>
</td>
</tr>
Your variant will be worked with
if(!$_POST['txtLeaderID']){echo('<input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')} else {echo('<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')}
For example:
<?php
if (!$_POST['username']){
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>
But it didn't work, if we open it in a new tab. You must save this propery anywhere (session, cookie, sql)and check the stored values. it will be work in a new tab.
For example with session:
<?php
session_start();
if (!isset($_SESSION['data'])) {
$_SESSION['data'] = true;
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>

submitted my php form, but none of the values were sent

For some reason, the options are not showing up in my email. I can get the email to send just fine. I can see the body and all its comments, but none of the entries that the user made. I know I am doing something wrong, but I cannot determine what it is.
Also, feel free to mock me if it looks horrible. :)
$ToEmail = 'dmandrade1978#gmail.com';
$EmailSubject = 'Message from web page!!';
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$urphone = $_POST['urphone'];
$event = $_POST['event'];
$date = $_POST['date'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$hearaboutus = $_POST['hearaboutus'];
$body = <<<EMAIL
Email: $email <br />
Name: $name <br />
Comment: $comment <br />
Phone: $urphone <br />
Date: $urdate <br />
Comment: $comment <br />
How did you hear?: $hearaboutus <br />
Mail optiom: $mail <br />
EMAIL;
$header = "Content-type: text/html\r\n";
mail("$ToEmail", "$EmailSubject", "$body", "$header");
echo ("Message Sent!");
?>
<td class = "form">
<form action="?" method="get" enctype="text/plain">
<p class = "form">Name:<br />
<input type="text" name="name" id="name" /></p>
<p class = "form">E-mail:<br />
<input type="text" name="email" id="email" /></p>
<p class = "form">Phone #:<br />
<input type="text" name="urphone" id="urphone" /></p>
<p class = "form">Event type:<br />
<input type="text" name="event" id="event" /></p>
<p class = "form">Date of event:<br />
<input type="text" name="date" id="date" /></p>
<p class = "form" >Prefered method of contact:<br />
<span class = "contact">
<input type="radio" name="phone" id="phone" /> Phone<br />
<input type="radio" name="mail" id="mail" /> E-mail<br />
</span></p>
<p class = "form">How did you hear about us?:<br />
<select name="hearaboutus" id="hearaboutus" />
<option value="internet">Internet</option>
<option value="word of mouth">Friend/Family</option>
<option value="magazine">Magazine</option>
<option value="other">Other</option>
</select></p>
<p class = "form">Message, questions, or availability:<br />
<textarea rows="10" cols="30" name="comment" id="comment">
</textarea></p>
<input type="submit" value="Send email to us" id="submit">
<input type="reset" value="Reset and start over">
</form>
Change method="get"
to
method="post"
and remove enctype . It's not required in this case.
Also, why is there a ? in your action? You can keep action blank as it is posting to the same page.
To make things even simpler for you, copy paste the below code and run the file again
if(isset($_POST['submit']))
{
$ToEmail = 'dmandrade1978#gmail.com';
$EmailSubject = 'Message from web page!!';
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$urphone = $_POST['urphone'];
$event = $_POST['event'];
$date = $_POST['date'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$hearaboutus = $_POST['hearaboutus'];
$body = <<<EMAIL
Email: $email <br />
Name: $name <br />
Comment: $comment <br />
Phone: $urphone <br />
Date: $urdate <br />
Comment: $comment <br />
How did you hear?: $hearaboutus <br />
Mail optiom: $mail <br />
EMAIL;
$header = "Content-type: text/html\r\n";
mail("$ToEmail", "$EmailSubject", "$body", "$header");
echo ("Message Sent!");
}
?>
<td class = "form">
<form action="" method="post">
<p class = "form">Name:<br />
<input type="text" name="name" id="name" /></p>
<p class = "form">E-mail:<br />
<input type="text" name="email" id="email" /></p>
<p class = "form">Phone #:<br />
<input type="text" name="urphone" id="urphone" /></p>
<p class = "form">Event type:<br />
<input type="text" name="event" id="event" /></p>
<p class = "form">Date of event:<br />
<input type="text" name="date" id="date" /></p>
<p class = "form" >Prefered method of contact:<br />
<span class = "contact">
<input type="radio" name="phone" id="phone" /> Phone<br />
<input type="radio" name="mail" id="mail" /> E-mail<br />
</span></p>
<p class = "form">How did you hear about us?:<br />
<select name="hearaboutus" id="hearaboutus" />
<option value="internet">Internet</option>
<option value="word of mouth">Friend/Family</option>
<option value="magazine">Magazine</option>
<option value="other">Other</option>
</select></p>
<p class = "form">Message, questions, or availability:<br />
<textarea rows="10" cols="30" name="comment" id="comment">
</textarea></p>
<input type="submit" name="submit" value="Send email to us" id="submit">
<input type="reset" value="Reset and start over">
</form>

PHP email form is not sending all fields

here is my html form
<form action="formmail1.php" method="post" enctype="multipart/form-data">
<li>
Name<br /><input name="name" type="text" id="name" size="50" maxlength="50" /> <br />
First and Last Name<br /><br />
</li>
<li>
Phone<br /><input name="phone" Type="text" id="email" size="12" maxlength="12"/><br />
___-___-____<br /><br />
</li>
<li>
Email<br />
<input name="email" Type="text" id="email" size="50"/><br />
Valid email address<br /><br />
</li>
<li>
How do you want to be contacted?<br />
<input Type="radio" name="how_to_be_contacted" id="r1" class="radio" value="1" /><label for="r1">Email</label><br />
<input Type="radio" name="how_to_be_contacted" id="r2" class="radio" value="2" /><label for="r1">Phone</label><br /><br />
</li>
<li>
I would like information about...<br />
<input name="aquatic_therapy" type="checkbox" id="aquatic_therapy" />Aquatic Therapy <input name="occupational_therapy" type="checkbox" id="occupational_therapy" />Occupational Therapy<br />
<input name="speech_therapy" type="checkbox" id="speech_therapy" />Speech Therapy <input name="reflex_integration" type="checkbox" id="reflex_integration" />Reflex Integration
<br />
Select all that apply<br />
</li>
<br />
<li>
Message<br />
<textarea name="message" cols="50" rows="10" id="message"></textarea><br />
</li>
</ol>
<input id="submit" type="submit">
Here is my PHP
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
//send email
$name = $_REQUEST['name'] ;
$phone = $_REQUEST['phone'] ;
$email = $_REQUEST['email'] ;
$how_do_you_want_to_be_contcted = $_REQUEST['how_do_you_want_to_be_contcted'] ;
$information = $_REQUEST['information'] ;
$message = $_REQUEST['message'] ;
mail("email#nowhere.com", "Subject: Contact Us Form",
$message "From: $email" );
echo "Thank you for using our mail form";
else
//if "email" is not filled out, display the form
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
All that is sending is message text field but none of the other fields....
$_REQUEST['how_do_you_want_to_be_contcted'] won't work because the field name in the HTML code is how_to_be_contacted.
You're defining the phone field as $phone and then referring to $emailphone. That clearly won't work either.
mail("eweb#gmail.com", "Subject: Contact Us Form", $emailphone
$message "From: $email" );
This has syntax errors, so can't work at all as shown.
You haven't escaped any of the input values, so if someone enters something with invalid data it could break the program and/or result in the site getting hacked.
Checkboxes and Radio buttons aren't sent unless checked.
Here is another possibility:
the request name you are asking for is: how_do_you_want_to_be_contcted
in your form you call it: how_to_be_contacted

Categories