I have a simple contact form for my church website. It will email to the address(es) I put in the code. But here is what I want to add. I'd like the visitor to be able to enter reason for contact (Information or Prayer Request) and the message. But also, if they want to contact a specific staff member (selected from drop down), they can and it does not sent to the info/prayer email, but to that staff member's address. Right now, I have the staff dropdown list, but the email only goes to the designated address for the form in general, not to the staff member's address when chosen. Does that make sense?
In other words, someone will receive emails requesting info. or prayer and the staff members will receive email sent directly to them. Is that possible? Thank you in advance for any input.
Here is my HTML code:
<form id="contactusForm" method="post" action="connect.php">
<div><blockquote>Please fill out this short form and we will respond as soon as possible. Nothing is required except your reason for contact and your message.</blockquote>
</div>
<label for="reason">Reason</label>
</div><div class="col-75">
<select name="reason" id="reason" type="select" tabindex="1">
<option value="select">Select One</option>
<option value="prayer#mlc.org">Request For Prayer</option>
<option value="info#mlc.org">Request For Information</option>
<option value="john#mlc.org">Contact Pastor John</option>
<option value="dennis#mlc.org">Contact Assistant Pastor Dennis </option>
<option value="bryan#mlc.org">Contact Assistant Pastor Bryan</option>
<option value="kellie#mlc.org">Contact Kid's Pastor Kellie</option>
</select></div> </div><br>
<div class="row">
<div class="col-25">
<label for="name">Name</label>
</div>
<div class="col-75">
<input name="name" type="text" id="name" placeholder="Your name.." tabindex="3" title="Name" size="50" maxlength="50">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="phone">Phone</label>
</div>
<div class="col-75">
<input name="phone" type="tel" id="phone" placeholder="Your phone number.." tabindex="4" title="Phone" size="30" maxlength="30">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="email">Email</label>
</div>
<div class="col-75">
<input name="email" type="email" id="email" placeholder="Your email..." tabindex="5" title="Email" size="50" maxlength="50" >
</div>
</div>
<div class="row">
<div class="col-25">
<label for="state">State</label>
</div>
<div class="col-75">
<select name="state" id="state" type="select" tabindex="6">
<option value="">Select your state...</option>
<option value="NA">N/A</option>
<option value="AL">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="country">Country</label>
</div>
<div class="col-75">
<select name="country" id="country" type="select" tabindex="7">
<option value="">Select your country...</option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
</select>
</div>
</div>
<br><br>
<p>If you would like to email a specific staff member, please select one below.</p>
<br><br>
<div class="row">
<div class="col-25" id="selectStaff">
<label for="emailTo">Staff Member</label>
</div>
<div class="col-75">
<select name="emailTo" id="emailTo" type="select" tabindex="1">
<option value="select">Select One</option>
<option value="john#mlc.org">Pastor John</option>
<option value="dennis#mlc.org">Assistant Pastor Dennis</option>
<option value="bryan#mlc.org">Assistant Pastor Bryan</option>
<option value="dennis#missionlighthouse.org">Kid's Pastor Kellie</option>
</select>
</div>
</div>
<br><br>
<div class="row">
<div class="col-25">
<label for="message">Your Message:</label>
</div>
<div class="col-75">
<textarea name="message" type="text" maxlength="800" required="required" id="message" style="height:180px" placeholder="Type your message here..." tabindex="8"></textarea>
</div>
</div><br><br>
<input type="checkbox" name="contact_me_by_email_only" value="1" style="display:none !important" tabindex="-1" autocomplete="off">
<div class="row">
<input type="submit" tabindex="10" value="Submit">
</div>
</form>
PHP CODE:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHP/PHPMailer/vendor/autoload.php';
$reason = $_POST['reason'];
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING);
$email = $_POST['email'];
$state = $_POST['state'];
$country = $_POST['country'];
$emailto = $_POST['emailTo'];
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
//validation
if(empty($message)){
header("location: connect.html?nomessage");
}
$honeypot = FALSE;
if (!empty($_REQUEST['contact_us_by_email_only']) && (bool) $_REQUEST['contact_us_by_email_only'] == TRUE) {
$honeypot = TRUE;
log_spambot($_REQUEST);
# treat as spambot
} else {
# process as normal
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'test#mlc.org'; // SMTP username
$mail->Password = 'Password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('test#mlc.org', 'MLC Website');
$mail->addAddress('noone#nowhere.net', 'John G.');
$mail->addAddress('someone#gmail.com', 'Someone');
// Add a recipient
//Body Content
$body = "<p><strong>Hello</strong>, you have received a message submitted from the MLC Website.<br><br>
<br><strong>Message Topic:</strong><br>" . $reason.
"<br><br><strong>Name:</strong><br>" . $name.
"<br><br><strong>Phone:</strong><br>" . $phone.
"<br><br><strong>Email:</strong><br>" . $email.
"<br><br><strong>State:</strong><br>" . $state.
"<br><br><strong>Country:</strong><br>" . $country.
"<br><br><strong>Message:</strong><br>". $message."</p>";
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Email from MLC Website';
$mail->Body = $body;
$mail->AltBody = strip_tags ($body);
$mail->send();
header("Location: thankyou.html?sent");
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
Related
Hello my favorite people!
I am trying to send an email after submitting a form, with the AUTO INCREMENT number attached to the email because the AUTO INCREMENT number is the clients Job Card Reference Number. So far i have successfully created the insert script which inserts the data into the database perfectly, and also sends the email too. But does not attach the AUTO INCREMENT number into the email. The INT(11) AUTO INCREMENT primary key is "job_number" in my MySQL database.
Here is my insert page:
<form action="addnewrepairprocess.php" method="POST">
<div class="form-group">
<label for="date">Date</label>
<input type="date" name="date" id="date" class="form-control" placeholder="Job Card Date">
</div>
<div class="form-group">
<label for="client_full_name">Client Full Name</label>
<input type="text" name="client_full_name" class="form-control" id="client_full_name" placeholder="Mr. Laptop Man">
</div>
<div class="form-group">
<label for="client_email">Client Email Address</label>
<input type="email" name="client_email" class="form-control" id="client_email" placeholder="example#live.co.za">
</div>
<div class="form-group">
<label for="client_phone">Client Phone Number</label>
<input type="text" name="client_phone" class="form-control" id="client_phone" placeholder="071 984 5522">
</div>
<div class="form-group">
<label for="item_for_repair">Item For Repair</label>
<select name="item_for_repair" id="item_for_repair">
<option value="Laptop">Laptop</option>
<option value="Desktop">Desktop</option>
<option value="Television">Television</option>
<option value="Washing Machine">Washing Machine</option>
<option value="Tumble Dryer">Tumble Dryer</option>
<option value="Dishwasher">Dishwasher</option>
<option value="Microwave">Microwave</option>
<option value="Fridge">Fridge</option>
<option value="Printer">Printer</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-group">
<label for="repair_description">Repair Description</label>
<input type="text" name="repair_description" class="form-control" id="repair_description" placeholder="Laptop is dead...">
</div>
<div class="form-group">
<label for="hardware_details">Hardware Details</label>
<input type="text" name="hardware_details" class="form-control" id="hardware_details" placeholder="Black Lenovo Laptop with Charger">
</div>
<div class="form-group">
<label for="diagnostic_fee">Diagnostic Fee</label>
<input type="text" name="diagnostic_fee" class="form-control" id="diagnostic_fee">
</div>
<div class="form-group">
<label for="tech_assigned">Technician Assigned</label>
<select name="tech_assigned" id="tech_assigned">
<option value="Not Assigned Yet">Not Assigned Yet</option>
<option value="Brendon">Brendon</option>
<option value="Gabriel">Gabriel</option>
<option value="Tapiwa">Tapiwa</option>
<option value="Conrad">Conrad</option>
</select>
</div>
<div class="form-group">
<label for="current_status">Current Status</label>
<select name="current_status" id="current_status">
<option value="Pending">Pending</option>
<option value="In Progress">In Progress</option>
<option value="On Hold Spares Required">On Hold Spares Required</option>
<option value="On Hold Other Fault">On Hold Other Fault</option>
<option value="Repair Completed">Repair Completed</option>
</select>
</div>
<div class="form-group">
<label for="technician_notes">Technician Notes</label>
<input type="text" name="technician_notes" class="form-control" id="technician_notes">
</div>
<div class="form-group">
<label for="admin_notes">Admin Notes</label>
<input type="text" name="admin_notes" class="form-control" id="admin_notes">
</div>
<div class="form-group">
<label for="invoice_status">Invoice Status</label>
<select name="invoice_status" id="invoice_status">
<option value="Client Not Yet Invoiced">Client Not Yet Invoiced</option>
<option value="Client Invoiced">Client Invoiced</option>
</select>
</div>
<div class="form-group">
<label for="invoice_number">Invoice Number</label>
<input type="text" name="invoice_number" class="form-control" id="invoice_number">
</div>
<input type="submit" id="btn_create" name="btn_create" class="btn btn-primary" value="Create Job Card">
</form>
My Form Action Page:
<?php
require_once "connection.php";
if(isset($_REQUEST['btn_create']))
{
$job_number = $_REQUEST['job_number'];
$date = $_REQUEST['date'];
$client_full_name = $_REQUEST['client_full_name'];
$client_email = $_REQUEST['client_email'];
$client_phone = $_REQUEST['client_phone'];
$item_for_repair = $_REQUEST['item_for_repair'];
$repair_description = $_REQUEST['repair_description'];
$hardware_details = $_REQUEST['hardware_details'];
$diagnostic_fee = $_REQUEST['diagnostic_fee'];
$tech_assigned = $_REQUEST['tech_assigned'];
$current_status = $_REQUEST['current_status'];
$technician_notes = $_REQUEST['technician_notes'];
$admin_notes = $_REQUEST['admin_notes'];
$invoice_status = $_REQUEST['invoice_status'];
$invoice_number = $_REQUEST['invoice_number'];
if(empty($date)){
$errorMsg="Please Enter date";
}
else if(empty($client_email)){
$errorMsg="Please Enter Email Address";
}
else
{
try
{
if(!isset($errorMsg))
{
$insert_stmt=$db->prepare('INSERT INTO repairs(job_number,date,client_full_name,client_email,client_phone,item_for_repair,repair_description,hardware_details,diagnostic_fee,tech_assigned,current_status,technician_notes,admin_notes,invoice_status,invoice_number) VALUES(:job_number,:date,:client_full_name,:client_email,:client_phone,:item_for_repair,:repair_description,:hardware_details,:diagnostic_fee,:tech_assigned,:current_status,:technician_notes,:admin_notes,:invoice_status,:invoice_number)');
$insert_stmt->bindParam(':job_number', $job_number);
$insert_stmt->bindParam(':date', $date);
$insert_stmt->bindParam(':client_full_name', $client_full_name);
$insert_stmt->bindParam(':client_email', $client_email);
$insert_stmt->bindParam(':client_phone', $client_phone);
$insert_stmt->bindParam(':item_for_repair', $item_for_repair);
$insert_stmt->bindParam(':repair_description',$repair_description);
$insert_stmt->bindParam(':hardware_details', $hardware_details);
$insert_stmt->bindParam(':diagnostic_fee', $diagnostic_fee);
$insert_stmt->bindParam(':tech_assigned', $tech_assigned);
$insert_stmt->bindParam(':current_status', $current_status);
$insert_stmt->bindParam(':technician_notes', $technician_notes);
$insert_stmt->bindParam(':admin_notes', $admin_notes);
$insert_stmt->bindParam(':invoice_status', $invoice_status);
$insert_stmt->bindParam(':invoice_number', $invoice_number);
if($insert_stmt->execute())
{
$insertMsg="Created Successfully........sending email now";
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
?>
<?php
if(isset($_POST['btn_create'])){
$to = "EMAIL_ADDRESS"; // this is your Email address
$from = "EMAIL_ADDRESS"; // this is the sender's Email address
$job_number = $_POST['job_number'];
$date = $_POST['date'];
$client_full_name = $_POST['client_full_name'];
$item_for_repair = $_POST['item_for_repair'];
$subject = "JC$job_number has been added to ECEMS";
$message = "Hi Admin. A new job card has been added to ECEMS on the $date for $client_full_name. The item for repair is a $item_for_repair. Please start diagnostics immediately for this item.";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
header("refresh:1;repairs.php");
}
?>
I tried to follow this tut: Send email with PHP from html form on submit with the same script
I have also tried activating errors on this page with no results:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
I am new and have NEVER done a code like this where the AUTO INCREMENT number needs to be sent in an email. Please can someone assist me. I can edit my question if more clarification is needed.
EDIT: Ive done some research and found i can use the lastInsertID (https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_last-insert-id function. Some help implementing this would be so appreciated.
$insertId = false;
if($insert_stmt->execute())
{
$insertId = $insert_stmt->insert_id;
$insertMsg="Created Successfully........sending email now";
}
if($insertId){
// do stuff with the insert id
}
Ok so i used the MAX method to solve this issue. i added the following to the top of my createnewrepairs.php page:
$stmt = $db->prepare("SELECT MAX(job_number) AS max_id FROM repairs"); $stmt -> execute(); $job_number = $stmt -> fetch(PDO::FETCH_ASSOC); $max_id = $job_number['max_id'];
Then on the same page, i added the following form field
<div class="form-group">
<label for="job_number">Job Number</label>
<input type="job_number" name="job_number" id="job_number" class="form-control" value="<?php echo $max_id+1;?>" readonly>
</div>
Then on the form processing page (processnewrepair.php) my code in my original post worked and generated the AUTO INCREMENT NUMBER to send in an email.
I am a novice at PHP. I have a simple contact form. I got the code online, copy/pasted/tweaked. It will send the email fine, but 2 of the fields (email and state) are blank in the email. All the other fields are filled in. I have looked and I don't see any reason why. What am I missing? Thanks in advance for any help. Here is my code:
HTML
<form id="contactusForm" method="post" action="connect.php">
<div><blockquote>Please fill out this short form and we will respond as soon as possible. Nothing is required except your reason for contact and your message. Thank you for your time.</blockquote>
<br><br><br>
</div>
<div class="row">
<div class="col-25" id="help-with">
<label for="reason">Reason</label>
</div><div class="col-75">
<select name="reason" id="reason" type="select" tabindex="1">
<option value="Prayer">Request For Prayer</option>
<option value="Information">More Information</option>
</select></div> </div> <br>
<br>
<div class="row">
<div class="col-25">
<label for="name">Name</label>
</div>
<div class="col-75">
<input name="name" type="text" id="name" placeholder="Your name.." tabindex="2" title="Name" size="50" maxlength="50">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="phone">Phone</label>
</div>
<div class="col-75">
<input name="phone" type="tel" id="phone" placeholder="Your phone number.." tabindex="3" title="Phone" size="30" maxlength="30">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="email">Email</label>
</div>
<div class="col-75">
<input name="email" type="email" id="email" placeholder="Your email..." tabindex="4" title="Email" size="50" maxlength="50" >
</div>
</div>
<div class="row">
<div class="col-25">
<label for="state">State</label>
</div>
<div class="col-75">
<select name="state" id="state" type="select" tabindex="5">
<option value="pick-a-state">Select your state...</option>
<option value="NA">N/A</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="country">Country</label>
</div>
<div class="col-75">
<select name="country" id="country" type="select" tabindex="6">
<option value="">Select your country...</option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan">Afghanistan</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="message">Your Message:</label>
</div>
<div class="col-75">
<textarea name="message" type="text" maxlength="800" required="required" id="message" style="height:180px" placeholder="Type your message here..." tabindex="7"></textarea>
</div>
</div><br>
<br>
<input type="checkbox" name="contact_me_by_fax_only" value="1" style="display:none !important" tabindex="-1" autocomplete="off">
<div class="row">
<input type="submit" tabindex="10" value="Submit">
</div>
</form>
PHP
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHP/PHPMailer/vendor/autoload.php';
$reason = $_POST['reason'];
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING);
$mailFrom = $_POST['email'];
$state = $_POST['state'];
$country = $_POST['country'];
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
//validation
if(empty($message)){
header("location: connect.html?nomessage");
}
$honeypot = FALSE;
if (!empty($_REQUEST['contact_me_by_fax_only']) && (bool) $_REQUEST['contact_me_by_fax_only'] == TRUE) {
$honeypot = TRUE;
log_spambot($_REQUEST);
# treat as spambot
} else {
# process as normal
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.dotster.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'test#missionlighthouse.org'; // SMTP username
$mail->Password = '1234567'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('test#missionlighthouse.org', 'MLC Website');
$mail->addAddress('myemail80#myhost.net', 'John Doe'); // Add a recipient
//Body Content
$body = "<p><strong>Hello</strong>, you have received a message submitted from the MLC Website.<br><br>
<br><strong>Message Topic:</strong><br>" . $reason.
"<br><br><strong>Name:</strong><br>" . $name.
"<br><br><strong>Phone:</strong><br>" . $phone.
"<br><br><strong>Email:</strong><br>" . $email.
"<br><br><strong>State:</strong><br>" . $state.
"<br><br><strong>Country:</strong><br>" . $country.
"<br><br><strong>Message:</strong><br>". $message."</p>";
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Email from MLC Website';
$mail->Body = $body;
$mail->AltBody = strip_tags ($body);
$mail->send();
header("Location: thankyou.html?sent");
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
If you change the variable $mailFrom to $email, I believe your email field will show up as you expect. As for the state field, I'm not sure... Try changing both the locations of the variable $state to some other name such as $stateField
I have a questionnaire form on my website that emails me answers submitted by visitors. One of the questions asks users for the best contact time (morning, afternoon, evening) The name of that select class is contact-time.
Currently in the body of the email, it's displayed as Contact-time just like I named it in the html form. I want it to display as Contact Time.
How can I build the body of the email so that it displays contact-time as Contact Time while still being able to fetch the value from select class named contact-time? I've looked through pretty much all questions regarding this and couldn't find any relevant information.
PHP code that builds the email and then sends it
<?php
function constructEmailBody () {
$fields = array("name" => true, "email" => true, "address" => true, "phone" => true, "contact-time" => true);
$message_body = "";
foreach ($fields as $name => $required) {
$postedValue = $_POST[$name];
if ($required && empty($postedValue)) {
errorResponse("$name is empty.");
} else {
$message_body .= ucfirst($name) . ": " . $postedValue . "\n";
}
}
return $message_body;
}
//attempt to send email
$emailBody = constructEmailBody();
require './vender/php_mailer/PHPMailerAutoload.php';
$email = new PHPMailer;
$email->CharSet = 'UTF-8';
$email->isSMTP();
$email->Host = 'smtp.gmail.com';
$email->SMTPAuth = true;
$email->Username = 'email#domain.com';
$email->Password = 'MyPassword';
$email->SMTPSecure = 'tls';
$email->Port = 587;
$email->setFrom($_POST['email'], $_POST['name']);
$email->addAddress('email#domain.com');
$email->Subject = 'Estimate Request Answers';
$email->Body = $emailBody;
//try to send the message
if($email->send()) {
echo json_encode(array('message' => 'Thank you! Your message was successfully submitted.'));
} else {
errorResponse('An unexpected error occured while attempting to send the email: ' . $email->ErrorInfo);
}
?>
HTML form
<form role="form" id="estimateForm" method="POST">
<div class="col-xs-12 contact-information">
<div class="form-group">
<fieldset>
<legend>Contact Information</legend>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<label class="control-label" for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter Name">
<label class="control-label" for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email">
<label class="control-label" for="address">Address</label>
<input type="text" class="form-control" id="address" name="address" placeholder="Enter Address">
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<label class="control-label" for="phone">Phone Number</label>
<input type="tel" class="form-control" id="phone" name="phone" placeholder="Enter Phone Number">
<label class="control-label" for="contact-time">Preferred Contact Time</label>
<select class="selectpicker contact-time" id="contact-time" name="contact-time" title="Preferred Contact Time">
<option value="Morning">Morning (9-11am)</option>
<option value="Afternoon">Afternoon (11-2pm)</option>
<option value="Evening">Evening (2-5pm)</option>
</select>
<label class="control-label" for="contact-method">Preferred Contact Method</label>
<select class="selectpicker contact-method" id="contact-method" name="contact-method" title="Preferred Contact Method">
<option>By Phone</option>
<option>By Email</option>
</select>
</div>
</fieldset>
</div>
</div>
</form>
Thank you for your time in advance and I appreciate any help.
nothing to do with the mail code you can use a simple str_replace() on $name
or
if($name =='whatever'){
$name='something else';
}
or about 10 other options
I don't know why it is not working.I want to send contact form to email but when I submit it shows me blank page and no email is send.Here I added the html part too for you to understandable.I hope that I will get a good solution from all experts.Thanks in advance.
<?php
if (isset($_POST['send'])) {
# code...
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$ques_type = $_POST['ques_type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Question Type: $ques_type \n Message: $message";
$recipient = "backoffice#simarketconsultants.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
}
?>
<form methos="POST" action="includes/send-form.php">
<fieldset>
<div class="input-group">
<label for="name">Full Name: <sup class="red">*</sup></label>
<input type="text" class="" name="name" placeholder="Full Name" required>
</div>
<div class="input-group">
<label for="email">E-mail Address: <sup class="red">*</sup></label>
<input type="email" class="" name="email" placeholder="example#yourdomain.com" required>
</div>
<div class="input-group">
<label for="phone">Phone Number: </label>
<input type="tel" class="" name="phone" placeholder="+445678946343">
</div>
<div class="input-group">
<label for="ques_type">Question Type: <sup class="red">*</sup></label>
<select name="ques_type" class="">
<option for="" id="" class="" selected>Please Select Question Type</option>
<option for="" name="customers" class="">Customer Sevice</option>
<option for="" name="new" class="">New Accounts</option>
<option for="" name="payments" class="">Payments</option>
<option for="" name="marketing" class="">Marketing</option>
<option for="" name="partners" class="">Partners</option>
<option for="" name="technical" class="">Technical Support</option>
</select>
</div>
<div class="input-group">
<label for="message" class="adjust">Qusetions or Comments: <sup class="red">*</sup></label>
<textarea name="message" placeholder="Your questions/comments will be written here....." required></textarea>
</div>
<div class="input-group">
<input class="btn btn-danger" name="send" value="Send" type="submit">
</div>
</fieldset>
</form>
First of all, your form should say method='post' not methos='post'.
Secondly, mail() doesn't work on localhost. Consider using PHPMailer or testing on a live server.
Thirdly (is that a word?), make sure that the file that holds the php is in the includes/send-form.php file, relative to the file that has the form in.
Last of all, the select tags hold the name attribute, not the option.
Example:
<select name='car'>
<option value='Audi'>Audi</option>
<option value='Ford'>Ford</option>
<option value='Skoda' selected>Skoda</option>
</select>
<?php
echo $_POST['car']; //Skoda
In your case, that would need to read as:
<select name="ques_type" class="">
<option value="none_selected" class="" selected>Please Select Question Type</option>
<option value="customers" class="">Customer Sevice</option>
<option value="new" class="">New Accounts</option>
<option value="payments" class="">Payments</option>
<option value="marketing" class="">Marketing</option>
<option value="partners" class="">Partners</option>
<option value="technical" class="">Technical Support</option>
</select>
You shouldn't close the <?php tag. Leave it open, there is no need to close it and e.g. when you include a file and want to send headers after the include whitespaces behind closing tag would cause an error.
Try to debug like this:
test1:
if (isset($_POST['send'])) {
echo 'test';
exit;
Does it output "test"?
Do you have a mailserver installed?
I am working on a PHP form for bootstrap my site. (http://camp.impactak.com/signup.html) This form works perfectly in every browser EXCEPT internet explorer. It comes up with and error:
"Please correct the following error:
YOUR NAME
Hit back button and try again."
I put code in the PHP that should have eliminated an error message if some of the blanks are not filled. However, it still sends an error (only in IE)
PHP:
<?php
/* Set e-mail recipient */
$myemail = "erinpavek#gmail.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$address = check_input($_POST['inputAddress'], "Street, PO Box, company");
$address2 = check_input($_POST['inputAddress2'], "Apt, Unit, Suite");
$village = check_input($_POST['inputVillage'], "Your Village");
$state = check_input($_POST['inputState'], "State, Providence, Region");
$zip = check_input($_POST['inputZip'], "Your Zip");
$tel = check_input($_POST['inputTel'], "Your Phone");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$pname = check_input($_POST['inputParent'], "Parent/Guardian Name");
$subject = check_input($_POST['inputSubject'], "Message Subject");
$message = check_input($_POST['inputMessage'], "Your Message");
$select = check_input($_POST['inputSelect'], "Certified");
$select2 = check_input($_POST['inputSelect2'], "NonCertified");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Someone has sent you a message";
$message = "
Someone has sent you a message using your contac form:
Name: $name
Address: $address
Address2: $address2
Village: $village
State: $state
Zip: $zip
Cell: $tel
Email: $email
Parent/Guardian: $pname
Certified: $select
NonCertified: $select2
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://www.camp.impactak.com');
exit();
/* Functions we used */
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
HTML:
<form name="contactform" method="post" action="mailer.php" class="form-horizontal" role="form">
<div class="panel-body">
<form name="contactform" method="post" action="http://wedding-space.net/01_admin_resources/blog/contact_form/mailer.php" class="form-horizontal" role="form">
<div class="form-group">
<label for="inputName" class="col-lg-3 control-label">Full Name</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputName" name="inputName" placeholder="First and Last Name">
</div>
</div>
<div class="form-group">
<label for="inputAddress" class="col-lg-3 control-label">Address1</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputAddress" name="inputAddress" placeholder="Street">
</div>
</div>
<div class="form-group">
<label for="inputAddress2" class="col-lg-3 control-label">Address2</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputAddress2" name="inputAddress2" placeholder="Apt, Unit, Building">
</div>
</div>
<div class="form-group">
<label for="inputVillage" class="col-lg-4 control-label">Village</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="inputVillage" name="inputVillage" placeholder="Village">
</div>
</div>
<div class="form-group">
<label for="inputState" class="col-lg-4 control-label">State</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="inputState" name="inputState" placeholder="State">
</div>
</div>
<div class="form-group">
<label for="inputZip" class="col-lg-4 control-label">Zip Code</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="inputZip" name="inputZip" placeholder="Zip">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-3 control-label">Email</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputEmail" name="inputEmail" placeholder="Your Email">
</div>
</div>
<div class="form-group">
<label for="inputParent" class="col-lg-3 control-label">Parent/Guardian</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputParent" name="inputParent" placeholder="Parent/Guardian Name">
</div>
</div>
<h5>Each student much choose one class from the either the Certified or Non-Certified class list: </h5>
<select class="form-control" id="inputSelect" name="inputSelect">
<option value="none">Certified Classes</option>
<option value="DriversEd">Drivers Ed. (get license, village youth only)</option>
<option value="NSTC">NSTC- (Seniors or 2014 graduates)</option>
<option value="LifeGuard">Life Guard Training</option>
<option value="ArcticSurvival">Arctic Survival Certification</option>
</select>
<br>
<select class="form-control" id="inputSelect2" name="inputSelect2">
<option value="none">Non-Certified Classes</option>
<option value="cook">Cooking</option>
<option value="Art">Arts from the Earth/Crafts</option>
<option value="poetry">Creative Writing/Poetry</option>
<option value="guitar">Guitar Lessons</option>
<option value="engineering">Science and Engineering</option>
<option value="drama">Drama/Acting</option>
<option value="taeKwonDo">Tae Kwon Do</option>
<option value="sodHouse">Sod House Design</option>
<option value="SkinSewing">Skin Sewing</option>
<option value="DrumDance">Drum Dancing</option>
<option value="Aviation">Aviation</option>
<option value="Rap">Rap/Hip-Hop Class</option>
</select>
<br>
</form>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-default">
Sign Up
</button>
</div>
</div>
</form>
</div>
</div>
The answer was staring us in the face.
You put a form in a form.
That is not allowed.
you cant have forms submit forms.
Please readjust your markup accordingly to not have forms in Forms, they can be siblings though. Problem solved.
You have:
<form><form></form></form>
You need to either remove the inner form, or separate it out:
<form></form>
or
<form></form>
<form></form>