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>
Related
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.
I've made a html using html, and it contains some radio buttons. How would I know which button is selected? I need to send the selected option to my email, but I don't quite understand how it would be incorporated into my php script. Thank you all so much!
Below is my php script:
<?php
$to = 'dinefour4#gmail.com';
$subject = 'The subject';
$name = $_POST['name'];
$email = $_POST['email'];
$option = $_POST['place']; <-- is this the way to know the selected button?
$mobile = $_POST['mobile'];
$message = <<<EMAIL
$name
$email
$mobile
EMAIL;
$header = '$email';
if($_POST) {
mail($to, $subject, $message, $header);
}
?>
<div id="signup">
<form action="signup.php" method="POST" onsubmit="return validate()">
<label name = "sutitle"> <font size="7"> sign up here!</font></label> <br/>
<label ><font size="5" >Name:</font>
<input type="text" name="name" required ></label><br />
<label ><font size="5">Mobile:</font>
<input type="text" name="mobile" required></label><br />
<label ><font size="5">Email: </font>
<input type="text" name="email" required></label><br />
<label> <font size="5">Where to meet your Friends?</font><br/>
<input type="radio" name="place" value="revelle" > <font size="5">Revelle </font><br>
<input type="radio" name="place" value="muir"> <font size="5">Muir </font><br>
<input type="radio" name="place" value="warren"> <font size="5">Warren </font><br>
<input type="radio" name="place" value="erc" > <font size="5">ERC </font><br>
<input type="radio" name="place" value="village"> <font size="5">The Village </font><br>
</label>
<input type="submit" value="Submit">
</form>
<?php
$to = 'dinefour4#gmail.com';
$subject = 'The subject';
$name = $_POST['name'];
$email = $_POST['email'];
$option = ""
if(isset($_POST['place']))
{
$option = $_POST['place'];
}
$mobile = $_POST['mobile'];
$message = <<<EMAIL
$name
$email
$mobile
EMAIL;
$header = '$email';
if($_POST) {
mail($to, $subject, $message, $header);
}
?>
<div id="signup">
<form action="signup.php" method="POST" onsubmit="return validate()">
<label name = "sutitle"> <font size="7"> sign up here!</font></label> <br/>
<label ><font size="5" >Name:</font>
<input type="text" name="name" required ></label><br />
<label ><font size="5">Mobile:</font>
<input type="text" name="mobile" required></label><br />
<label ><font size="5">Email: </font>
<input type="text" name="email" required></label><br />
<label> <font size="5">Where to meet your Friends?</font><br/>
<input type="radio" name="place" value="revelle" > <font size="5">Revelle </font><br>
<input type="radio" name="place" value="muir"> <font size="5">Muir </font><br>
<input type="radio" name="place" value="warren"> <font size="5">Warren </font><br>
<input type="radio" name="place" value="erc" > <font size="5">ERC </font><br>
<input type="radio" name="place" value="village"> <font size="5">The Village </font><br>
</label>
<input type="submit" value="Submit">
If the radio button is selected, then it will set in '$option' variable. Otherwise '$option' variable will be empty.
I have a html form where i want 3 fields to be mandatory. If the user doesn't fill any one of those fields, then the form shouldn't be submitted and it should tell the user to fill in the mandatory one's. I've used PDO and i dont know how to do it. If someone could help me. Down below i've given both my html and php files.
HTML:
<html>
<head>
<title>Data Insertion</title>
</head>
<body>
<p><span class="Error">* required field.</span></p>
<form method="post" action="su.php">
<h2>Please Fill In Details</h2>
<label for="name">Name </label>
<input type="text" Placeholder="Enter your name" name="name" id="name" />
<span class="Error">*</span>
<br />
<br />
<label for="age">Age </label>
<input type="text" name="age" id="age" placeholder="Enter your age" />
<br />
<br />
<label for="mailid">MailId </label>
<input type="text" name="mailid" id="mailid" placeholder="Enter your Mail Id" />
<span class="Error">*</span>
<br />
<br />
<label for="gender">Gender </label>
<br />
<label for="male">Male </label>
<input type="radio" name="gender" id="gender" value="Male" id="male" />
<label for="female">Female </label>
<input type="radio" name="gender" id="gender" value="Female" id="female" />
<br />
<br />
<label for="qualification">Qualification </label>
<select name="qualification" value="Qualification" id="qualification">
<option value="B.E">SSLC</option>
<option value="P.G">HSC</option>
<option value="SSLC">UG</option>
<option value="HSC">PG</option>
</select>
<br /><br />
<label for="hobbies">Hobbies </label>
<br />
<input type="checkbox" name="hobbies" id="hobbies" value="Cricket" />Cricket
<input type="checkbox" name="hobbies" id="hobbies" value="Music" />Music
<input type="checkbox" name="hobbies" id="hobbies" value="Swimming" />Swimming
<br /><br />
<label for="textarea">Address </label>
<br />
<textarea name="address" id="textarea" rows="15" cols="30"></textarea>
<span class="Error">*</span>
<br /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
PHP:
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
try {
$conn = new PDO("mysql:host=$servername;dbname=testing", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['submit'])){
$name = $_POST['name'];
$age = $_POST['age'];
$mailid = $_POST['mailid'];
$gender = $_POST['qualification'];
$hobbies = $_POST['address'];
if($name !='' || $mailid !='' || $address !=''){
$sql = "Insert into user (Name, Age, MailId, Gender, Qualification, Hobbies, Address)
values ('".$_POST["name"]."', '".$_POST["age"]."', '".$_POST["mailid"]."', '".$_POST["gender"]."', '".$_POST["qualification"]."', '".$_POST["hobbies"]."', '".$_POST["address"]."')";
$conn->exec($sql);
echo "Thank you for registering";
} else {
echo "<p>Insertion failed <br/> Please enter the required fields !";
}}
}
catch(PODException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
?>
Try adding the html 5 attribute "required" on all the required input elements. For example
<input type="text" Placeholder="Enter your name" name="name" id="name" required />
You should also check the POST variables in the php code though, as this doesn't really prevent someone from abusing your service. Ex.
if(!isset($_POST['somevar'])) {
// Do insert
}
In html You should use javascript (e.g. jQuery) to control onsubmit event and validate if mandatory fields are filled with proper values, check this link: jQuery.submit()
In php You should check and validate each var before create and execute query. Simple article about it is here: Sanitize and Validate Data with PHP Filters
This would be good for the start I think ;)
Query string should contain placeholders and then statement should be prepared for execution, check this link:
PDOStatement::bindParam
I have a webpage that has two contact forms and the second one is working fine but I can't seem to get the first one to work. I am fairly new to php. Thanks in advance for the help. Here's the html:
<h3>Message Us</h3>
<form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
<input type="hidden" name="scrollx" id="scrollx" value="0" />
<input type="hidden" name="scrolly" id="scrolly" value="0" />
<div id="msgbox1">
<label for="name2">Name:</label>
<input type="text" id="name2" name="name2" placeholder=" Required" />
<label for="email2">Email:</label>
<input type="text" id="email2" name="email2" placeholder=" Required" />
<label for="phone">Phone:</label>
<input type="text" id="phone" name="phone" placeholder="" />
<label for= "topic">Topic:</label>
<select id="topic" name="topic">
<option value="general">General</option>
<option value="stud">Property Price Enquiry</option>
<option value="sale">Bull Sale Enquiry</option>
</select>
</div><!--- msg box 1 -->
<div id="msgbox2">
<textarea id="message" name="message" rows="7" colums="25" placeholder="Your Message?"></textarea>
<p id="feedback2"><?php echo $feedback2; ?></p>
<input type="submit" value="Send Message" />
</div><!--- msg box 2 -->
</form><!--- end form -->
</div><!--- end message box -->
And here's the php:
<?php
$to2 = '418#hotmail.com'; $subject2 = 'MPG Website Enquiry';
$name2 = $_POST ['name2']; $email2 = $_POST ['email2']; $phone = $_POST ['phone']; $topic = $_POST ['topic']; $message = $_POST ['message'];
$body2 = <<<EMAIL
This is a message from $name2 Topic: $topic
Message: $message
From: $name2 Email: $email2 Phone: $phone
EMAIL;
$header2 = ' From: $email2';
if($_POST['submit']=='Send Message'){
if($name2 == '' || $email2 == '' || $message == ''){
$feedback2 = '*Please fill out all the fields';
}else {
mail($to2, $subject2, $body2, $header2);
$feedback2 = 'Thanks for the message. <br /> We will contact you soon!';
} } ?>
For the saveScrollPositions I use the following php and script:
<?php
$scrollx = 0;
$scrolly = 0;
if(!empty($_REQUEST['scrollx'])) {
$scrollx = $_REQUEST['scrollx'];
}
if(!empty($_REQUEST['scrolly'])) {
$scrolly = $_REQUEST['scrolly'];
}
?>
<script type="text/javascript">
window.scrollTo(<?php echo "$scrollx" ?>, <?php echo "$scrolly" ?>);
</script>
You have a mistake in your HTML part i.e.
<input type="submit" value="Send Message" />
add attribute name also in this input type like this-
<input type="submit" value="Send Message" name="submit" />
one thing more to correct in your php script is write-
$header2 = "From: ".$email2; instead of $header2 = ' From: $email2';
now try it.
What do you return in "saveScrollPositions" function? if you return false the form submit wont fire.
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!