PHP Enquiry form not working? - php

I'm trying to create a website and my PHP and html just wont work!! When I input data the website doesnt send the information to my email, and in the input forms, my validation is showing instead of the placeholder!!! please help!!!!:-)
my html is as follows:
<form class="form-horizontal" role="form" method="post" action="index.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="Preferred Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="<?php echo htmlspecialchars($_POST['email']); ?>">
</div>
</div>
<div class="form-group">
<label for="number" class="col-sm-2 control-label">Contact Number</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="number" name="number" placeholder="0000000000">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
my PHP is as follows:
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\`content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

you have not closed the form tag and in contact there is no value given of post paste this code and check and while using html5 validation it will set validation error message using placeholder like please enter+your placeholder
<form class="form-horizontal" role="form" method="post" action="index.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="Preferred Name" value="<?php echo #htmlspecialchars($_POST['name']); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="<?php echo #htmlspecialchars($_POST['email']); ?>">
</div>
</div>
<div class="form-group">
<label for="number" class="col-sm-2 control-label">Contact Number</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="number" name="number" placeholder="0000000000" value="<?php echo #$_POST['your_contact_filed_name'] ?>">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars(#$_POST['message']);?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo #$result; ?>
</div>
</div>
</form>

Related

Why isn't my PHP form working? I do receive the email but there is no content in it

PHP form on my website isn't responding well. It would be appreciated if someone could help me.
This is the HTML Code of the form
<form action="contactform.php" method="post" name="form" class="p-5 bg-white">
<div class="row form-group">
<div class="col-md-6 mb-3 mb-md-0">
<label class="text-black" for="fname">First Name</label>
<input type="text" id="fname" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="lname">Last Name</label>
<input type="text" id="lname" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Email</label>
<input type="email" id="email" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="subject">Subject</label>
<input type="subject" id="subject" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="mssg">Message</label>
<textarea name="mssg" id="mssg" cols="30" rows="7" class="form-control" placeholder="Write your notes or questions here..."></textarea>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<input type="submit" value="Send Message" class="btn btn-primary py-2 px-4 text-white">
</div>
</div>
</form>
This is the PHP Code
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "alyyashar#gmail.com";
$subject = "New email from your site!";
$fname = $_POST['fname'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$title = '<h3>Hello! You have received a new mail from your website!</h3>';
$body = "$title
<br/>
<b>From:</b> $fname
<br/>
<b>E-Mail:</b> $email
<br/>
<b>Message:</b>\n$message
<br/>
<br/>";
if (mail($to, $subject, $body, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$fname.", We will contact you shortly!</h1>";
} else {
echo "Something went wrong!";
}
}
?>
<br>
Back to Homepage
This is the email I receive
Screenshot of the email
When I enter information into the form and click send message, I do receive the email but there is no content in it.
The form elements have no name attributes, which is what the browser uses to send their name/value pairs to the server. So while it's posting the form, none of the values are being included.
For example, this:
<input type="text" id="fname" class="form-control">
Should be this:
<input type="text" id="fname" class="form-control" name="fname">
The same fix would need to be repeated for the remaining form elements.

Attachment saved in variable with wp_mail() not being sent

After having read the documentation for wp_mail several times and looking around for solutions, i still haven't been able to figure out how to get a file attached with wp_mail();
First of all, i'm of the understanding that the file path is needed, but how do i know where it is saved on my wordpress site? And when it is is saved, is it temporary or permanently?
Currently i'm just using $attachments = array(WP_PLUGIN_DIR . '/uploads/file_to_attach.zip');
because i saw it in another post on stackoverflow. But this means that i'm not using my $_POST['file']
in which the path should be stored.
HTML
<form method="post" role="form" action=''>
<div class="col-xs-12 col-sm-6 form-group">
<label>Navn</label>
<input class="form-control" name="name" type="text" value="<?php echo $_POST['name']; ?>" required/>
</div>
<div class="col-xs-12 col-sm-6 form-group">
<label>E-mail</label>
<input class="form-control" name="email" type="email" value="<?php echo $_POST['email']; ?>" required/>
</div>
<div class="col-xs-12 col-sm-6 form-group">
<label>Tlf.</label>
<input class="form-control" name="phone" type="tel" value="<?php echo $_POST['phone']; ?>" required/>
</div>
<div class="col-xs-12 col-sm-6 form-group">
<label>Firma</label>
<input class="form-control" name="company" type="text" value="<?php echo $_POST['company']; ?>" />
</div>
<div class="col-xs-12 form-group">
<label>Besked</label>
<textarea class="form-control" name="message" type="text" rows="6" required><?php echo $_POST['message']; ?></textarea>
</div>
<div class="col-xs-12 form-group">
<div class="input-group">
<label class="input-group-btn">
<span class="btn btn-primary">
Vedhæft billeder… <input type="file" name="file" style="display: none;" multiple>
</span>
</label>
<input type="text" class="form-control" readonly>
</div>
</div>
<div class="col-xs-12" id="checkrow">
<label>
<input type="checkbox" name="check" required> Jeg er et menneske
</label>
</div>
<div class="col-xs-4 form-group" style="padding-top:1rem;">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary" style="min-width:5rem">
</div>
<?php echo $result; ?>
</form>
PHP
$to = "ch#ap-pe.dk";
$msg = "Navn: ".$_POST['name']."
Email: ".$_POST['email']."
Tlf: ".$_POST['phone']."
Firma: ".$_POST['company']."
Besked: ".$_POST['message'];
$msg = wordwrap($msg, 70);
$headers = 'From: ';
$attachments = array(WP_PLUGIN_DIR . '/uploads/file_to_attach.zip');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!$_POST['name']){
$errorMsg="Indtast navn";
}
if (!$_POST['email']){
$errorMsg.="Indtast email";
}
if (!$_POST['message']){
$errorMsg.="Indtast besked";
}
if (!$_POST['check']){
$errorMsg.="Bekræft at du er menneske";
}
$result = "Ret følgende fejl: $errorMsg";
wp_mail($to, "Kontakt Besked",$msg, $headers, $attachments);
}
?>

How can I send mail of complete form in php?

i am having a problem in sending mail to my server. i dont know why the problem is occurring? everything is done perfect but it is not working maybe the fields are not filling properly and alert message is also not shown
if(isset($_POST['uname']) && isset($_POST['fname']) && isset($_POST['nic']) && isset($_POST['pecno'])&& isset($_POST['quality[25]'])&& isset($_POST['bday'])&& isset($_POST['quality[26]'])&& isset($_POST['postal'])&& isset($_POST['cell'])&& isset($_POST['houseno'])&& isset($_POST['mail'])&& isset($_POST['city'])&& isset($_POST['province'])&& isset($_POST['country']) )
{
$_Name = $_POST['uname'];
$_Fname = $_POST['fname'];
$_NIC = $_POST['nic'];
$_Pecno = $_POST['pecno'];
$_Gender = $_POST['quality[25]'];
$_Bday = $_POST['bday'];
$_Qualification = $_POST['quality[26]'];
$_Postal = $_POST['postal'];
$_Cell = $_POST['cell'];
$_Houseno = $_POST['houseno'];
$_Email = $_POST['mail'];
$_City = $_POST['city'];
$_Province = $_POST['province'];
$_Country = $_POST['country'];
if(!empty($_Name) && !empty($_Fname) && !empty($_NIC) && !empty($_Pecno)&& !empty($_Gender)&& !empty($_Bday)&& !empty($_Qualification)&& !empty($_Postal)&& !empty($_Cell)&& !empty($_Houseno)&& !empty($_Email)&& !empty($_City)&& !empty($_Province)&& !empty($_Country))
{
$to = 'info#mymail.com';
$subject = 'Join us mail';
$body = 'Sender Name : '.$_Name."\n".'Sender Father Name : '.$_Fname."\n".'Sender NIC : '.$_NIC."\n".'Sender PEC Number : '.$_Pecno."\n".'Sender Gender : '.$_Gender."\n".'Sender Birthday : '.$_Bday."\n".'Sender Qualification : '.$_Qualification."\n".'Sender Postal Address : '.$_Postal."\n".'Sender Cell Number : '.$_Cell."\n".'Sender House Number : '.$_Houseno."\n".'Sender Email : '.$_Email."\n".'Sender City : '.$_City."\n".'Sender Province : '.$_Province."\n".'Sender Country : '.$_Country;
$header = 'From : '.$_Email;
if(#mail($to, $subject, $body, $header))
{
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
}else
{
echo 'Please Try again in a few mints !';
}
}
}
html code
<form method="POST" action="index.php">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="uname" name="uname" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="fname" name="fname" placeholder="Father Name" type="text" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="nic" name="nic" placeholder="CNIC/Passport Number" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="pecno" name="pecno" placeholder="PEC Number" type="text">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="designation" name="designation" placeholder="Designation" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="organization" name="organization" placeholder="Organization" type="text">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
Gender: <div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" id="quality[25]" name="quality[25]" value="1" /> Male
</label>
<label class="btn btn-default">
<input type="radio" id="quality[25]" name="quality[25]" value="2" /> Female
</label>
</div>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" type="text" onfocus="(this.type='date')" id="bday" name="bday" placeholder="Date of Birth" ><br>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
Qualification: <div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="1" /> Bachelors In Engineering
</label>
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="2" /> Masters
</label>
<label class="btn btn-default">
<input type="radio" id="quality[26]" name="quality[26]" value="3" /> PhD
</label>
</div>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="postal" name="postal" placeholder="Postal Address" type="text" >
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control slideanim" id="cell" name="cell" placeholder="Cell Number" type="tel" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="houseno" name="houseno" placeholder="House Number" type="tel" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control slideanim" id="mail" name="mail" placeholder="Email Address" type="email" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="city" name="city" placeholder="City" type="text" required>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="province" name="province" placeholder="Province/State" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="country" name="country" placeholder="Country" type="text" required>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right " type="submit">Send</button>
</div>
</div>
</div>
replace #mail with mail
if(#mail($to, $subject, $body, $header))
enable error reporting
error_reporting(E_ALL);
Show last error with:
print_r(error_get_last());
and check php_error.log for a problem
phpinfo();
for checking if mail module is enabled in php.
If all pass, check /var/log/mail about the messages, here could be 1001 issues with network, server, firewall etc...
hope it helps.
As you mentioned that same code is working perfectly on other page so please check it by removing "#" from mail as adding this will hide all notices and it will display error as well. Also try to print mail body text before mail function.

PHP in bootstrap contact form does not work correctly, someone can figure out what I did wrong?

I've made a contact form for my website, included the html and the php, it does send an email which does show "name: email: message:" but after that it's empty, so it doesn't show what you type in the form, please help!
Here is the html:
<form action="thankyou.php" method="post">
<div class="col-md-5" style="margin-top:15px;">
<div class="form-group">
<label for="contact-name" class="col-sm-2 control-label">Naam</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="contact-name" placeholder="First & Last name" />
</div>
</div>
<div class="form-group">
<label for="contact-email" class="col-sm-2 control-label" style="margin-top:15px;">Email</label>
<div class="col-sm-10" style="margin-top:15px;">
<input type="text" class="form-control" id="contact-name" placeholder="example#domain.com" />
</div>
</div>
<div class="form-group">
<label for="contact-message" class="col-sm-2 control-label" style="margin-top:15px;">Message</label>
<div class="col-sm-10" style="margin-top:15px;">
<textarea class="form-control" rows="4"></textarea>
</div>
</div>
<button style="btn-align:center; margin-left:88px; margin-top:15px;" type="submit" class="btn btn-primary">Verstuur</button>
</div>
</div>
</div>
</form>
Here is the php:
<?
$name = $_POST['contact-name'];
$email = $_POST['contact-email'];
$message = $_POST['contact-message'];
$email_message = "
Name:".$name."
Email:".$email."
Message:".$message."
";
mail ( "email#example.com" , "New inquiry", $email_message);
?>
Your form fields are all missing the name attribute. Without it that data is not sent.
<input type="text" class="form-control" name="contact-name" id="contact-name" placeholder="First & Last name" />
^^^^
This is missing for all form fields

php form not sending submission data. sending email and processing form still however

I Have two forms on my site. One works fine and the other sends email with email_from: etc but doesn't capture any of the form data.
Wondering what it may be. I can post the form that is working along with it's html too if that would help debug. Very much a novice and built form using stack overflow/other sites.
Coffee
<div class="form-group">
<label class="col-sm-3 control-label">Quantity</label>
<div class="col-sm-4">
<input type="text" name="quantity" class="form-control" placeholder="Quantity : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Name</label>
<div class="col-sm-6">
<input type="text" name="name" class="form-control" placeholder="Name : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email address</label>
<div class="col-sm-6">
<input type="email" name="email" class="form-control" placeholder="Email address : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Shipping Address</label>
<div class="col-sm-6">
<textarea class="form-control" name="shipping_address" rows="8" placeholder="Shipping Address : " required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Payment Method</label>
<div class="col-sm-6">
<select class="form-control" required>
<option value="Paypal">Paypal</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Notes</label>
<div class="col-sm-6">
<textarea class="form-control" name="notes" rows="8" placeholder="Notes : "></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-10">
<button type="submit" class="btn btn-black">Order Now</button></a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
And here is the php
<?php
if(isset($_POST ['submit']))
{
$coffee = ($_POST['coffee']));
$quantity = ($_POST['quantity']));
$name = ($_POST['name']));
$email = ($_POST['email']));
$shipping_address = ($_POST['shipping_address']));
$notes = ($_POST['notes']));
}
$email_from ='paradigmcoffee#gmail.com';
$email_subject="New Order Submission";
$email_body ="You have received a new message from user $name.\n".
"Email_address:$email\n".
"Coffee: $coffee\n".
"Quantity: $quantity\n".
"Shipping_Address: $shipping_address\n".
"Notes: $notes\n".
$to ="paradigmcoffee#gmail.com";
$headers = "From: $email \r\n";
mail($to,$email_from,$email_subject,$email_body,$headers);
header("Location: http://www.paradigmcoffee.co/order_thanks.html");
?>
From what you have supplied, likely the reason you can not get data is because you are not sending anything called submit. Try naming your button:
<!-- name="submit" added -->
<button name="submit" type="submit" class="btn btn-black">Order Now</button>
You can do this or make a hidden field:
<input type="hidden" name="submit" value="1" />

Categories