PHP Contact Form for Bootstrap [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have trouble with php contact form on Bootstrap. I don't know where is problem. It always gives error message. I replaced my e-mail address there but it still gives error. I don't know which line to change.
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'info#balkescafequiz.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#balkescafequiz.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>

i didnt read trough your script, but try use this:
//Clean string before sending
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
//build message
$email_message .= "$l_firstname: ".clean_string($FirstName)."\n";
$email_message .= "$l_lastname: ".clean_string($LastName)."\n";
$email_message .= "$l_email: ".clean_string($Email)."\n";
$email_message .= "$l_phone: ".clean_string($Phone)."\n";
$email_message .= "$l_msg: ".clean_string($Message)."\n";
$email_subject = "New Mail From "."$FullName";
// create email headers
$headers = 'From: '."$FullName".'<'.$Email.'>'."\r\n".
'Reply-To: '.$Email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($Recipient, $email_subject, $email_message, $headers);
//return to index, show confirmation
header("Location: index.php?lang=$Language&show=success");
This is what i use :)

Related

PHP email form doesnt work correctly

I have on the web email form, when I type all the informations it sends me an email, however when I type some czech characters (the site is czech) it doesnt work. Some of the characters shows as "čřžýáí" for example. I downloaded free template from some website, which I edited with my friend who knows HTML, but not PHP. I tried to find out some advice, but it says nothing to me, because I dont know almost anything about PHP and when I tried to copy some part of the code and hoped that it will worked it havent... Can you please help me?
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'xxxx#pl.cz'; // Add your email address inbetween the ''
replacing yourname#yourdomain.com - This is where the form will send a
message to.
$email_subject = "Website Contact Form: $name";
$email_body = "Nova zprava z webu.\n\n"."Udaje:\n\nJmeno: $name\nEmail:
$email_address\n\nMessage:\n$message";
$headers = "From: noreply#plantaen.cz\n"; // We recommend using something
like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Add header to mail
Try this:
$body = '<html><head><title>Title</title></head>'."\r\n";
$body .= 'Test';
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=utf-8'."\r\n";
$headers .= 'From: YourName <"from#yoruname.com">';
mail("to#yourname.com","title",$body,$headers);
Edit :
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
echo "No arguments Provided!";
exit();
} else {
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$email_subject = "Website Contact Form: $name";
$email_body = '<html><head><title>plantaen</title></head>'."\r\n";
$email_body .= "Nova zprava z webu.\n\n"."Udaje:\n\nJmeno: $name\nEmail: $email_address\n\nMessage:\n$message";
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=utf-8'."\r\n";
$headers .= 'From: plantaen <"noreply#plantaen.cz">';
mail("noreply#plantaen.cz", $email_subject, $email_body, $headers);
echo "Done!";
exit();
}

Mail() - message body with utf-8 and html tags

Contact form on site use script below. It send 2 messages - to me and to the person filling in the form. In second mail I have problem with characters like "ąźćęś"....I would like to use utf-8. I set it in header, but it doesn't work. I need to use in message body html tags also.
What wrong in the code?
<?php
// Check for empty fields
if(empty($_POST['email']) ||
empty($_POST['phone']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$email_address = $_POST['email'];
$phone = $_POST['phone'];
// Create the email and send the message
$to = 'me#test.com';
$email_subject = "Mail to you";
$email_body = "Hello\n\n"."Test\n\nEmail: $email_address\n\nPhone: $phone";
$headers = "From: test#test.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
$to2 = "$email_address";
$email_subject2 = "=?UTF-8?B?".base64_encode("Thanks for you message")."?=";
$email_body2 = "Test mail ążźćęśó\n\nBest regards\nTester";
$headers2 .= "Content-Type: text/html; charset=UTF-8";
$headers2 = 'From: Tester <test#test.com>' . "\r\n";
mail($to2,$email_subject2,$email_body2,$headers2);
return true;
?>

PHP Contact form in website not sending Japanese characters

I am using a simple php contact form that sends to an email, but when I want it to send Japanese characters, the email I receive from the form displays those characters in strange Greek-looking code. I assume there is some way to specify in the php form that I am using UTF-8, but I am not sure where or what to put to let the characters display as Japanese. Below is the code.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "abc#abc.com";
$email_subject = "Contact Form";
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->

Date from php contact form is wrong

All of a sudden contact forms filled in on my website are coming into my inbox from the date 1/1/1970???
They are ending up at the bottom of my inbox and I have missed a few leads...
Any ideas how this can start happening all of a sudden?
The code I am using on my contact page is : -
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "my email address";
$email_subject = "Website Contact Enquiry";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['tel']) ||
!isset($_POST['message'])||
!isset($_POST['formtype'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$tel = $_POST['tel']; // required
$message = $_POST['message']; // required
$formtype = $_POST['formtype'];
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Tel: ".clean_string($tel)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
$email_message .= "formtype: ".clean_string($formtype)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion().date();
#mail($email_to, $email_subject, $email_message, $headers);
?>
Add this to your headers:
'Date: ' . date('r'),
Also, make sure to sanitize $email_from. Right now, you are allowing spammers to send E-Mail to other recipients and change the header. Read more here: http://www.securephpwiki.com/index.php/Email_Injection

Sending email two multiple recipients but different body using PHP [duplicate]

This question already has answers here:
How to do email form with multiple recipients and different body?
(3 answers)
Closed 9 years ago.
I have one contact form, when user submit all value will send(email) to admin.But now i want to do when user submit admin will receive the email and user also will receive an email but with different body.
here my previous code :
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "admin#gmail.com";
$email_subject = "Lifemailer Sales Enquiry";
$email_to_user= "Name: ".clean_string($name)."\n";
function died($error) {
// your error code can go here
$URL = "error.html";
header("Location: $URL");
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['contact']) ||
!isset($_POST['email']) ||
!isset($_POST['email_sub']) ||
!isset($_POST['remarks'])) {
died('We are sorry, but there appears to be a problem with the form your
submitted.');
}
$name = $_POST['name']; // not required
$contact = $_POST['contact']; // required
$email = $_POST['email']; // required
$email_sub = $_POST['email_sub']; // required
$remarks = $_POST['remarks']; // required
$error_message = "";
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
$string_exp = "^[0-9 .-]+$";
if(!eregi($string_exp,$contact)) {
$error_message .= 'The Contact Number you entered does not appear to be valid.
<br />';
}
$email_exp = "^[A-Z0-9._%-]+#[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.
<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Contact Number: ".clean_string($contact)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Email Subject : ".clean_string($email_sub)."\n";
$email_message .= "Remarks/Enquiry : ".clean_string($remarks)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
$URL = "thank-you.html";
header("Location: $URL");
?>
Thank you for contacting us. We will be in touch with you very soon.
<?
}
?>
In the same way you can send a second mail with different subject, email_to, email_message after sending it to admin.
just concatenate
$email_to = ' admin#gmail.com ' . ',' ;
$email_to . = ' admin#gmail.com ' ;

Categories