This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I have created a form and would like the information to be sent to my email using php. The information submits, and I receive an e-mail, but the email only displays the first and last name of input by the individual submitting the form. I would like to know what is missing from either the php side or html side.
Thank You
<form name="contactform" method="post" action="appraisal_form.php">
<table width="500px">
<tr>
<td>
<label for="first_name">First Name *</label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name *</label>
</td>
<td>
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="email">Email Address *</label>
</td>
<td>
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="telephone">Telephone Number</label>
</td>
<td>
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<!--- Property Type-->
<tr>
<td>
<label for="lender">Lender *</label>
</td>
<td>
<input type="text" name="lender" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_officer">Loan Officer *</label>
</td>
<td>
<input type="text" name="loan_officer" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="property_address">Email Address *</label>
</td>
<td>
<input type="text" name="property_address" maxlength="100" size="30">
</td>
</tr>
<tr>
<td>
<label for="city">City *</label>
</td>
<td>
<input type="text" name="city" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="zip">Zip Code *</label>
</td>
<td>
<input type="text" name="zip" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="pin">PIN(Permenant Index Number) *</label>
</td>
<td>
<input type="text" name="pin" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="rooms">Number of Rooms *</label>
</td>
<td>
<input type="text" name="rooms" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="bath">Number of Bathrooms *</label>
</td>
<td>
<input type="text" name="bath" maxlength="80" size="30">
</td>
</tr>
<!--- Garage /yes or no-->
<tr>
<td>
<label for="plat">Plat of Survey *</label>
</td>
<td>
<input type="text" name="plat" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="borrow">Borrowers Name *</label>
</td>
<td>
<input type="text" name="borrow" maxlength="80" size="30">
</td>
</tr>
<!--- sale /refinance-->
<tr>
<td>
<label for="price">Purchase Price *</label>
</td>
<td>
<input type="text" name="price" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_amount">Loan Amount *</label>
</td>
<td>
<input type="text" name="loan" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="cod">C.O.D *</label>
</td>
<td>
<input type="text" name="cod" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="invoice">Invoice *</label>
</td>
<td>
<input type="text" name="invoice" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="comments">Comments *</label>
</td>
<td>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="submit" id="submit" value="Submit">
<input type="reset" name="Reset" id="reset" value="reset">
</td>
</tr>
</table>
</form>
PHP
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$lender = $_POST['lender']; // required
$loan_officer = $_POST['loan_officer']; // required
$property_address = $_POST['property_address']; // required
$city = $_POST['city']; // required
$zip = $_POST['zip']; // not required
$pin = $_POST['pin']; // required
$rooms = $_POST['rooms']; // required
$bath = $_POST['bath']; // required
$plat = $_POST['plat']; // required
$borrow = $_POST['borrow']; // not required
$price = $_POST['price']; // required
$cod = $_POST['cod']; // not required
$comments = $_POST['comments']; // required
$to = "rosaliam2#yahoo.com";
$subject = "New Appraisal Request";
$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 />';
}
mail($to, $subject, $message, "From" . $first_name . $last_name);
echo "Your Information has been sent";
?>
Actually there is no message variable to send!!
you are just sending $first_name and $last_name as headers!
Related
Submit to Database Success But Value Of Debit And Kredit are 0 and 1
<table>
<tr>
<td>
<input class="form-control" name="debit[]" type="text" placeholder="Debit" autocomplete="off" required />
</td>
<td>
<input class="form-control" name="Kredit[]" type="text" placeholder="Kredit" autocomplete="off" required />
</td>
</tr>
<tr>
<th>Total</th>
<th colspan="2">
<input class="form-control" name="total" type="text" jAutoCalc="{debit[]} + {kredit[]}" />
</th>
</table>
This is the error i receive
Parsing error:unrecognied value
(Error:valueNotParsed):<*>{debit[]}+{kredit[]}
Having a problem with ReCaptcha. Even if checkbox is checked, it still returns false. I have triple checked my keys and happy they are correct. I am using code based on that successfully used on another of my sites. Cannot see what is wrong.
For ease of reference, I have copied all the relevant coding. Hopefully someone will see straight away what I've done wrong.
Form Code:
<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" placeholder="Please enter your 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" placeholder="Please enter your surname" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="email" name="email" placeholder="Please enter your email address" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="tel" name="telephone" placeholder="Please enter your phone number" 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"><div class="g-recaptcha" data-sitekey="6LejdlwUAAAAAHb5qaNIhfDzxL1i9a9sCyw8dLzD"></div></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> <br> Email Form
</td>
</tr>
</table>
</form>
Code from the PHP:
<?php
// Code from ReCaptcha evaluation:
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "************************************";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are a spammer ! Your form has been rejected.</h2>';
} else
// End Code from ReCaptcha evaluation.
Many Thanks
Tim
This site is hosted on shared hosting, unfortunately, the only thing the host seems to make available is the access log, not the PHP error log, so I'm having trouble figuring out the specific error here.
I'm trying to do a very minimal, simple contact form in PHP, without much validation or complexity. Getting a 500 error, though I'm sure I'm overlooking something basic.
Any assistance greatly appreciated.
HTML:
<form name="htmlform" method="post" action="collins_contact.php">
<table width="450px" cellpadding="20px">
<tr><td> </td></tr>
<tr>
<td align="left">
<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> </td></tr>
<tr>
<td align="left">
<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> </td></tr>
<tr>
<td align="left">
<label for="email">Email Address</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="telephone">Telephone</label>
</td>
<td valign="top">
<input type="text" name="phone" maxlength="30" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="comments">Questions / Comments</label>
</td>
<td valign="top">
<textarea name="message" maxlength="1000" cols="25" rows="6"></textarea>
</td>
<tr><td> </td></tr>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
<tr><td> </td></tr>
</table>
</form>
PHP
<?php
if (isset($_POST["first_name"]) && isset($_POST["email"]) && isset($_POST["message"])) {
$name = $_POST["first_name"];
$email = $_POST["email"];
$subject = "Contact Form Submission";
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = "contact#domain.com";
if (mail($to, $subject, $message, $header)) {
header("Location: index.html");
} else {
echo("Error With Form Submission");
}
}
?>
Permissions needed to be changed to 0644 on the php file, then it worked.
I have recently created a contact form with PHP mailer which is finally working. However the success message is breaking my page and displaying in the top left corner instead of underneath the form. As you can see below.
This is the HTML:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
</table>
<input type="submit" value="Submit" name="submit">
<?php
if ($success) {
echo $success;
}
?>
</form>
It also creates a huge blank white area in the middle of my page under the form. Does anyone know why this is? or how I would go about debugging it?
You should put this in a div or a span
<div style="text-align:center;"> <?php
if ($success) {
echo $success;
}
?>
</div>
Try following code:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
<?php
if ($success) {?>
<tr><td colspan="2">
<?php echo $success; ?>
</td></tr>
<?php }
?>
</table>
<input type="submit" value="Submit" name="submit">
</form>
My users can enter more than one address but I want an actual button that generates the extra fields as only one address is compulsory and empty fields will look ugly! I also need the extra addresses to go into mysql database.
How would I do with Javascript if PHP is not possible
Some code that may help:
<td width="732" valign="top"><p>
<h3 class="main">Address Details</h3>
<p class="normal"> You are able to add up to 3 addresses but only 1 is compulsory.
However it would be helpful if you could insert 3 addresses:
<ul>
<li>Permanent home address</li>
<li>Postal address (where you will be from June to September)</li>
<li>Local address (where you currently live)</li>
</ul>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* $e <br>";
}
echo "</div>";
}
?>
<br>
<form action="address.php" method="post" name="regForm" id="regForm" >
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td>Street<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Street" type="text" id="Street" class="required" size="50">
</tr>
<tr>
<td>Line 2
</td>
<td><input name="Line2" type="text" id="Line2" class="required" size="50">
</tr>
<tr>
<td>Line 3
</td>
<td><input name="Line3" type="text" id="Line3" class="required" size="50">
</tr>
<tr>
<td>Town<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Town" type="text" id="Town" class="required" size="30">
</tr>
<tr>
<td>Postcode<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Postcode" type="text" id="Postcode" class="required" size="10">
</tr>
<tr>
<td>Country <font color="#CC0000">*</font></span></td>
<td><select name="Country" class="required" id="select8">
<option value="" selected></option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
(etc)
</select></td>
</tr>
<tr>
<td>Telephone Number<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Tele" type="text" id="Tele" class="required" >
</tr>
<tr>
<td>Fax<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Fax" type="text" id="Fax" class="required" >
</tr>
<tr>
<td>Mobile<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Mobile" type="text" id="Mobile" class="required" >
</tr>
<tr>
<td>Type <font color="#CC0000">*</font></span></td>
<td><select name="Type" class="required" id="select8">
<option value="" selected></option>
<option value="H">Home</option>
<option value="P">Postal</option>
<option value="L">Local</option>
</table>
<p align="center">
<input name="doAddress" type="submit" id="doAddress" value="Submit">
to fix your parse error - put ; at the end of line $numrows = 0 + $_GET['numrows']
to generate more fields dynamically - use javascript, really, it's way better for this task than php