I have a problem. Today I made contact form but it is not sending any emails and I don't know why. I downloaded an free example and I tried to add it to my own site but it's not working, any ideas? Here is the code:
<form id="contact-form" class="wniosek" action="wyslijWniosek.php" method="POST">
<div class="col-sm-4">
<label class="firma rel col-sm-12"><span class="inp"><input name="firma" type="text" placeholder="Nazwa Firmy" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="name rel col-sm-12"><span class="inp"><input name="name" type="text" placeholder="Imie i nazwisko" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="phone rel col-sm-12"><span class="inp"><input name="phone" type="text" placeholder="Telefon" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="email rel col-sm-12"><span class="inp"><input name="email" type="text" placeholder="E-mail" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="kwota rel col-sm-12"><span class="inp"><input name="kwota" type="text" placeholder="Prognozowana Kwota" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="wnio col-sm-12">
<select name="wnio" style="width:100%;">
<option value="kfirm">Kredyt Firmowy</option>
<option value="kgot">Kredyt Gotówkowy</option>
<option value="kobro">Kredyt Obrotowy</option>
<option value="phipo">Pozyczka Hipoteczna</option>
<option value="khipo">Kredyt Hipoteczny</option>
<option value="kkonso">Kredyt Konsolidacyjny</option>
<option value="kinwest">Kredyt Inwestycyjny</option>
<option value="ksamocho">Kredyt Samochodowy</option>
<option value="leasing">Leasing</option>
</select>
</label>
</div>
<div class="col-sm-12">
<label class="message rel col-sm-12"><span class="text_a"><textarea name="message" class="col-sm-12" placeholder="Wiadomosc" style="height:300px;"></textarea></span></label>
</div>
<div class="col-sm-4">
<div class="buttons-wrapper">
<input class="button2 btn btn-white" type="submit" value="Send">
<input class="button2 btn btn-white" type="reset" value="Clear">
</div>
</div>
</form>
and php:
<?php
$firma = $_POST['firma'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$wnio = $_POST['wnio'];
$kwota = $_POST['kwota'];
$message = $_POST['message'];
$formcontent=" Nazwa Firmy: $firma \n Imie i Nazwisko: $name \n Email: $email \n Telefon: $phone \n Wniosek: $wnio \n Prognozowana Kwota: $kwota \n Wiadomość: $message";
$recipient = "<mail here>";
$subject = "Formularz Kontaktowy";
$mailheader = "Wiadomość ze strony internetowej";
mail($recipient, $subject, $formcontent, $mailheader) or die("Błąd!");
echo "Dziękujemy!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
where is mail here i put my own email
Please replace mail($recipient, $subject, $formcontent, $mailheader) or die("Błąd!"); with below code.
$suc = mail($recipient, $subject, $formcontent, $mailheader);
if($suc){//If success
print_r("No error");
}
else{//If error on mail send
print_r(error_get_last());
}
exit();//Remove this after debugging done
If mail() not delivered successfully this code will print error into array format, else it would print 'No error'.
Let us know if you face any further query regarding the same.
You have to set the sender e-mail in your header.
$mailheader = "From: sender#mail.com";
Related
I'm trying to display the "Message sent successful" after someone fills in the form.
here is my code
<form action="contact.php" id="footer-form" method="post" role="form">
<div class="form-group has-feedback"><label class="sr-only" for="name2">Name</label> <input class="form-control" id="name2" name="name2" placeholder="Name" required="" type="text" /></div>
<div class="form-group has-feedback"><label class="sr-only" for="email2">Email address</label> <input class="form-control" id="email2" name="email2" placeholder="Enter email" required="" type="email" /></div>
<input class="btn btn-default" type="submit" value="Send" /></form>
<?php
$name = $_POST['name2'];
$email = $_POST['email2'];
$formcontent="From: $name \nEmail: $email";
$recipient = "email#domain.com";
$subject = "Website Under Construction";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
Just put your PHP Code above your HTML Code and define a message.
Then, just echo it in your HTML Code:
<?php
if(isset($_POST) {
$name = $_POST['name2'];
$email = $_POST['email2'];
$formcontent="From: $name \nEmail: $email";
$recipient = "email#domain.com";
$subject = "Website Under Construction";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
// Set the message here:
$message = "Message sent!";
}
?>
<form action="contact.php" id="footer-form" method="post" role="form">
<div class="form-group has-feedback"><label class="sr-only" for="name2">Name</label> <input class="form-control" id="name2" name="name2" placeholder="Name" required="" type="text" /></div>
<div class="form-group has-feedback"><label class="sr-only" for="email2">Email address</label> <input class="form-control" id="email2" name="email2" placeholder="Enter email" required="" type="email" /></div>
<input class="btn btn-default" type="submit" value="Send" /></form>
<?php
// Put this wherever you want
if(isset($message)) echo $message;
?>
Explanation
By default, the variable $message is unset. When the form submission is completed, you assign the variable $message the string "Message sent!".
Now, anywhere in your code, you can check if the variable $message is defined and print it out.
index.php file
<form action="contact.php" id="footer-form" method="post" role="form">
<div class="form-group has-feedback"><label class="sr-only"for="name2">Name</label>
<input class="form-control" id="name2" name="name2" placeholder="Name" required="" type="text" /></div>
<div class="form-group has-feedback"><label class="sr-only" for="email2">Email address</label> <input class="form-control" id="email2" name="email2" placeholder="Enter email" required="" type="email" /></div>
<input class="btn btn-default" type="submit" name="send_mail" value="Send" />
</form>
contact.php file
if (isset($_POST['send_mail'])) {
$name = $_POST['name2'];
$email = $_POST['email2'];
$formcontent="From: $name \nEmail: $email";
$recipient = "email#domain.com";
$subject = "Website Under Construction";
$mailheader = "From: $email \r\n";
$send_email = mail($recipient, $subject, $formcontent, $mailheader);
if ($send_email) {
echo 'Your success message';
} else {
die("Error!");
}
}
Explanation
First look index.php file, <form action="contact.php" id="footer-form" method="post" role="form"> here used action attribute on form tag and used action path like contact.php
And also check <input class="btn btn-default" type="submit" name="send_mail" value="Send" /> here I used name attribute name="send_mail"
When a user click on this button, this page will redirect to contact.php page and this page will check user click or not on button and process the mail function. After process, finally show the message.
Trying to add recaptcha to my contact form. I cannot get the contact form to redirect to a thank you page. The form does send the email correctly.
<?php
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "my key";
$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 'You are spammer';
} else {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$formcontent="From: $name \n Message: $message \n Email:$email \n Phone:$phone";
$recipient = "example#example.com";
$subject = "Website Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location:https://www.example.com/thank-you.html');
exit();
}
?>
Form Code: Adding site form code as requested
<div class="col-md-4">
<form id="quote-form" action="inc/sendmail.php" method="post">
<div class="sec-title text-center">
<h1>Request for Quote</h1>
<span class="border center"></span>
</div>
<div class="row">
<div class="col-md-12">
<input type="text" name="name" value="" placeholder="Your Name*" required="">
<input type="email" name="email" value="" placeholder="Your Mail*" required="">
<input type="text" name="phone" value="" placeholder="Your Phone*" required="">
<select class="selectmenu" name=message>
<option selected="selected">Select Service</option>
<option value="Need Quote on a prod 1</option>
<option value="Need Quote on a prod 2</option>
<option>Other</option>
</select>
<div class="g-recaptcha" data-sitekey="sitekeygoeshere-removed-forposting"></div>
<button class="thm-btn bg-clr1" name="submit" type="submit">Get a Quote</button>
</div>
</div>
</form>
</div>
I've removed the site key in the code.
I have a contact form in my website and it doesn't work properly. I get the email but the email it's empty, I don't get the information from the form.
the part of the html in my index.html
<form role="form" form name="contactform" method="post" action="send_form_email.php">
<div class="form-group">
<label>Nombre</label> <input type="text" name="nombre" class="form-control" placeholder="Introduce tu nombre" >
</div>
<div class="form-group">
<label>Apellidos</label> <input type="text" name="apellidos" class="form-control" placeholder="Introduce tus apellidos" >
</div>
<div class="form-group">
<label>Email</label> <input type="emal" name="email" class="form-control" placeholder="Introduce tu email" >
</div>
<div class="form-group">
<label>Telefono</label> <input type="text" name="telefono" class="form-control" placeholder="Introduce tu telefono" >
</div>
<div class="form-group">
<label>Mensaje</label> <textarea name="mensaje" class="form-control" rows="7"></textarea>
</div>
<button type="submit" class="btn btn-default" value="Submit"> Enviar
</form>
</div>
the part of the php file called "send_form_email.php"
<?php
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$telefono = $_POST['telefono'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
$formcontent=" $nombre $apellidos $email $telefono $mensaje";
$recipient = "deniz946#gmail.com";
$subject = "Subject from $nombre";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will get back to you as soon as possible!" . " -" . "<a href='./index.php'> Back to site</a>";
?>
<input type="emal" name="email" class="form-control" placeholder="Introduce tu email" > change to
<input type="email" name="email" class="form-control" placeholder="Introduce tu email" >
you have typo in type attribute.
Try this
<?php
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$telefono = $_POST['telefono'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
$formcontent = "{$nombre} {$apellidos} {$email} {$telefono} {$mensaje}";
$recipient = "deniz946#gmail.com";
$subject = "Subject from $nombre";
if(PHP_OS == "Linux" || PHP_OS == "Darwin") $new_line = "\n"; /* if Linux or Mac */
elseif(PHP_OS == "WINNT") $new_line = "\r\n"; /* if Windows */
$mailheader = "MIME-Version: 1.1" . $new_line;
$mailheader .= "Content-type: text/html; charset=utf-8" . $new_line;
$mailheader .= "From: ".$recipient.$new_line;
$mailheader .= "Return-Path: " . $recipient . $new_line;
$mailheader .= "Reply-To: " . $recipient . $new_line;
mail($recipient, $subject, $formcontent, $mailheader, "-r" . $recipient) or die("Error!");
echo "Thank You! We will get back to you as soon as possible!" . " -" . "<a href='./index.php'> Back to site</a>";
?>
Perhaps I can help you with an example I used myself:
The HTML contact Form:
<div class="row">
<!-- Content -->
<div id="content" class="8u skel-cell-mainContent">
<section class="12u">
<header>
<h2>Contact</h2>
</header>
<form method="post" action="mail.php">
<div class="row half">
<div class="6u">
<input name="subject" placeholder="Name" type="text" class="text" />
</div>
<div class="6u">
<input name='email' placeholder="Email" type="text" class="text" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row half">
<div class="12u">
<!--a href="mail.php" class="button">Submit</a-->
<input type="submit" class="button" value="Submit">
</div>
</div>
</form>
</section>
</div>
The PHP processing of the form:
<?php
//mail(to,subject,message,headers,parameters)
// Check if the "from" input field is filled out
//if (isset($_POST['from']))
//{}
$to = 'mail#xxxxxx.com'; // my email address
$subject = $_POST['subject']; //name client
$feedback = 'thank you, we will reply soon.';
$header = $_POST['email']; //Email client
$message = $_POST['message'];
$message = wordwrap($message, 70);
$message = <<<EMAIL
Dear (YOUR WEBSITE NAME HERE),
My name is: $subject
$message
Email Client: $header
EMAIL;
// send mail
if($_POST){
mail($to, $subject, $message, $header);
echo $feedback;
}
?>
Remember very carefully, the part from Dear... to EMAIL has to be against the left side of the screen, without any tabs or spaces. Else it won't work!
Hopefully you can use this to your success :)
I am attempting to send an email by filling out a contact form. Both my html form and php file are included below. Once I fill out the form, it notifies me that the email has been sent. However, I never receive an email; I cannot figure out what i am doing wrong.
This is my html form:
<div class="row" style="padding-top:27px">
<div class="large-6 column">
<form action="mail.php" method="POST" data-abide>
<div class="name-field">
<label>Your name*</label>
<input type="text" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
</div>
<div class="large-6 column">
<!-- <label> Message </label>
<textarea class="error" placeholder="Message..." id="info" class="message" name="message" cols="70" rows="60" size="90" requi></textarea><br>-->
<label> Message </label>
<textarea class="error" placeholder="Message..." ></textarea>
<small class="error">Invalid entry</small>
<div>
<input style="float:right;" type="submit" value="Submit">
<img style="visibility: hidden;">
</div>
</form>
This is my php file:
<?php
$to = "education#arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
UPDATED FILES:
HTML:
<div class="name-field">
<label>Your name*</label>
<input type="text" name="name" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" name="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" name="subject" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
<!-- End Contact Form -->
</div>
PHP:
<?php
$to = "education#arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
None of your input fields have a name associated with them, so you're likely getting empty data in your POST. The 'email' value within $_POST['email'] refers to an input field's name.
Specifically, you're not getting an email address from your form, so the email is not sending to anyone.
For instance, you'll need:
<input type="email" name="email" required>
The fourth parameter of mail() is additional headers. Which is where your "FROM" information should go.
Refer here:
http://php.net/manual/en/function.mail.php
for what should go there.
here's one example
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
i'm getting blank field returns in my inbox on only a portion on my form fields
like so:
From: whatevername
Email: fgsdfg#fakeysite.com
Message:
phone:
here is my code its probably something really dumb but its bugging me, so here we go.
HTML
<div class="row-item col-1_4">
<h3>Contact Form</h3>
<h4>Please fill out the form to get your free CD Replacement Kit</h4>
<!-- Success Message -->
<div class="form-message"></div>
<!-- Form -->
<form class="b-form b-contact-form" action="blast.php">
<div class="input-wrap m-full-width">
<i class="icon-user"></i>
Name
<input class="field-name" type="text" placeholder="Name (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-phone"></i>
Phone
<input class="field-phone" type="text" placeholder="Phone">
</div>
<div class="input-wrap m-full-width">
<i class="icon-envelope"></i>
Email
<input class="field-email" type="text" placeholder="E-mail (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-pencil"></i>
Message
<input class="field-comments" type="text" placeholder="Message">
</div>
<input class="btn-submit btn colored" type="submit" value="Send">
</form>
PHP
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient = "csmith#legacybrokerage.com";
$subject = "UNLIMITED ANNUITY LEADS CD BLAST";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
try this, define name= 'something' to the input field
<input class="field-name" type="text" placeholder="Name (required)" name="name">
<input class="field-phone" type="text" placeholder="Phone" name="phone">
<input class="field-email" type="text" placeholder="E-mail (required)" name="email">
your input's dose not name attribute!
<input class="field-name" type="text" placeholder="Name (required)">
correct :
<input name="from" class="field-name" type="text" placeholder="Name (required)">