PHP Contact form in website not sending Japanese characters - php

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 -->

Related

PHP Post email Sending email multiple times

I have a script that sends an email with information stored in sessions - the info is collected from a form a user fills out. (the form 'action' is pointed to the code below)
However, when the submit button is clicked twice on the form for example, 2 emails are sent and when clicked 3 times, 3 emails are sent.
I want to make sure that only 1 email is sent and if any session is empty no email is to be sent:
<?php
session_start();
if(isset($_POST['email'])) {
$email_to = "recipient#emailaddress.com";
$email_subject = "My Subject";
$machine = implode(",", $_SESSION['machinesesh']); //required
$machine_type = implode(" ", $_SESSION['typesesh']);; // required
$address = $_SESSION['addresssesh']; //required
$county = $_SESSION['countysesh']; //required
$postcode = $_SESSION['postcodesesh']; //required
$workplace = implode(', ', $_SESSION['worksesh']); //required
$serving = implode(', ', $_SESSION['peoplesesh']);
$company_name = $_SESSION['namesesh']; // required
$visitorname = $_POST['yourname']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$email_message = "New email alert .\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($visitorname)."\n";
$email_message .= "Company: ".clean_string($company_name)."\n";
$email_message .= "Address Line 1: ".clean_string($address)."\n";
$email_message .= "County: ".clean_string($county)."\n";
$email_message .= "Postcode: ".clean_string($postcode)."\n";
$email_message .= "Machine(s) Wanted: ".clean_string($machine)."\n";
$email_message .= "Environment: ".clean_string($workplace)."\n";
$email_message .= "Serving: ".clean_string($serving)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
// create email headers
$headers = 'From: sendaddress#email.com' . "\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
header("Location: http://www.example.com?tag=$machine");
?>
How about settings an $_SESSION["emailsent"] = 1; ? Before you send the email, check if the variable exists AND if it is set to 1! In this case you know, that in this session the email is only sent once!
You can try to erase the session after sending the email. The next time the form is submitted, it should check if session value is set or not. If not set, then it should not send email again.

PHP Contact Form for Bootstrap [duplicate]

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 :)

Cannot get page to redirect using PHP

Everything on the form works but it will not redirect to another page. It continues to give a text message. I've added a header('Location: http://mywebsite.com/'); but no luck. I'm new at PHP and would really appreciate help in fixing this code.
Current code:
<?php
if(isset($_POST['email'])) {
$email_to = "me#email.com";
$email_subject = "Contact Request";
function died($error) {
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();
}
if( !isset($_POST['full_name']) ||
!isset($_POST['agency']) ||
!isset($_POST['title']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$full_name = $_POST['full_name']; // required
$agency = $_POST['agency']; // required
$title = $_POST['title']; // required
$email = $_POST['email']; // required
$phone = $_POST['phone']; // 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 .= "Name: ".clean_string($full_name)."\n";
$email_message .= "Agency: ".clean_string($agency)."\n";
$email_message .= "Title: ".clean_string($title)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "phone: ".clean_string($phone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
header('Location: http://mywebsite.com/');
?>
<?php } ?>
Is the last line of code a typo in your question or part of your code?
<?php } ?>
If it's really part of your code, php is going to try and execute '}' and most likely screw up.
You don't say what the text message is that you receive.
Just remove ?> after this line
header('Location: http://mywebsite.com/');

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

add a second email address to a script

i have a script that i have modified to meet my requirements however i now need to send the email to more than one person, could someone point me in the right direction as to how i could modify the script to send to more than one person.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "emailremoved#sample.com";
$email_subject = "Kro Catering Website 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['your_name']) ||
!isset($_POST['type']) ||
!isset($_POST['guests']) ||
!isset($_POST['date']) ||
!isset($_POST['phone']) ||
!isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$your_name = $_POST['your_name']; // required
$type = $_POST['type']; // required
$guests = $_POST['guests']; // required
$date = $_POST['date']; // not required
$phone = $_POST['phone']; // required
$email_from = $_POST['email']; // 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 .= "Your Name: ".clean_string($your_name)."\n";
$email_message .= "Type: ".clean_string($type)."\n";
$email_message .= "Guests: ".clean_string($guests)."\n";
$email_message .= "Date: ".clean_string($date)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Email: ".clean_string($email_from)."\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 -->
<?php
header( 'Location: /thanks.aspx' ) ;
?>
<?php
}
?>
Search for the line:
$email_to = "emailremoved#sample.com";
And keep adding e-mails with a comma separating them:
$email_to = "emailremoved#sample.com,emailremoved#sample.com,emailremoved#sample.com";
PHP's mail() function is quite versatile when it comes to the "to" field. See the documentation here. Any one of the listed examples would be fine:
user#example.com
user#example.com, anotheruser#example.com
User <user#example.com>
User <user#example.com>, Another User <anotheruser#example.com>
So since your $email_to variable is not cleaned or otherwise modified after you set it on line 5, you should be able to just put 2 there separated by a comma (as in the examples above that I copied from the documentation I linked to.)
Try this!
It was the only code that worked for me.
$header .= 'Bcc: someaddress#email.com';

Categories