Adding Unicode UTF8 to email - php

Can anyone help me please how to add a utf-8 Unicode for these characters?
žýáťčšľľzŽŘ
Now the email looks like this
Dostali ste novú správu. Tu sú podrobnosti: Jméno: tár
Tel.Äíslo: 4996611
<?php
$EmailFrom = "...";
$EmailTo = "mail#mail";
$Subject = "Zpráva s ";
$name = Trim(stripslashes($_POST['name']));
$phone = Trim(stripslashes($_POST['phone']));
$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 .= $phone;
$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\">";
}
?>
Thanks

You've got two ambiguous parts of your script where character-sets aren't being considered. It's possible your form isn't sending UTF-8 or it's possible you're sending UTF-8 in your email but the client is expecting a different encoding.
I assume you're using a form to post data. Ensure it's set to send UTF-8 from the browser. The strings will now be UTF-8 encoded.
<form action="myform" accept-charset="UTF-8">
You need to add character set and transfer encoding headers to the email header:
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 8bit");
BTW, a faster way to redirect the user is to set the Location header in the response. Use:
header('Location: contactthanks.php')

Related

contact form sending blank emails

Can anyone think of a logical reason to why a contact form which works perfectly well on my 123 reg account, will not work on my clients account? when I test it on my side, I get the email and the form contents through to my inbox perfectly but when the same codes are used on my clients account, with his email address, he receives an email with no data..
<?php
$EmailFrom = "webmaster#pb.co.uk";
$EmailTo = "loans#website.co.uk";
$Subject = "Testing";
$Name = Trim(stripslashes($_POST['Name']));
$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 .= "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=http://website/thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
change
"From: $EmailFrom"
to
"From: $EmailFrom" . "\r\n"
Add header.
$Body = 'MIME-Version: 1.0' . "\r\n";
$Body .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$Body .= 'From: '. $EmailFrom . "\r\n" . 'X-Mailer: PHP/' . phpversion();

access denied. PHP script

I have a contact form, when submitting on my page says 'Access denied.' There is nothing else, so I can't seem to figure out how to debug.
Here is the code :
<?php
$EmailFrom = "username#email.com";
$EmailTo = "username#email.com, username2#email.com";
$Subject = "Subject";
$Name = Trim(stripslashes($_POST['Name']));
$Company = Trim(stripslashes($_POST['Company']));
$Email = Trim(stripslashes($_POST['Email']));
$Tel = Trim(stripslashes($_POST['Tel']));
$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 .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Further comments: ";
$Body .= $Message;
$Body .= "\n";
// Send Email
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");
// Redirect To Success Page
if ($success)
{
echo '<script>alert("Thanks for your message, somebody will get in touch with your shortly.");</script>';
echo "<meta http-equiv=\"refresh\" content=\"0;URL=../contact\">";
}
else
{
echo '<script>alert("There has been an error, please try again later.");</script>';
echo '<script>history.back(1);</script>';
exit;
}
?>
I'm not sure why it's not working, could someone shed some light on this?
The headers of the page you're submitting the form to are actually returning a HTTP 403 Forbidden error.
I'd suggest checking the file permissions & ownership of the contactengine.php file are correct as a first step.

PHP Contact Form not working with Outlook email addresses

I have a contact form on a html page. The form data is sent to a PHP page which sends the info to an email address. It works for addresses *#gmail, *#hotmail.com but the person who needs to receive it has Outlook set-up for their website.com address and it doesn't work. Is there another setting I need somewhere?
Here is PHP code:
<?php
$EmailFrom = "myname#website.com";
$EmailTo = "receiver#website.com";
$Subject = "Website Contact Form";
$Name = Trim(stripslashes($_POST['name']));
$Location = Trim(stripslashes($_POST['location']));
$Phone = Trim(stripslashes($_POST['phone']));
$Email = Trim(stripslashes($_POST['email']));
$Comments = Trim(stripslashes($_POST['comments']));
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $Location;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
?>
This question comes up quite a bit.
There is a strong possibility that the mail client (in this case outlook) is configured to filter messages that lack proper headers. This could be at the client point or at the server connection at smtp time. The main thrust of the issue is that the basic php mail() core function is almost universally mistrusted due to its potential for abuse by spammers.
You should try using a library like PHPMailer to help guide you to setting the reply-to and other headers properly.

What's wrong with my simple captcha php script?

I also have session_start(); at the top of my index page, its not working!
<?php
if(isset($_REQUEST['Submit'])){
$key=substr($_SESSION['key'],0,5);
$captcha = $_REQUEST['captcha'];
if($captcha=!$key){
exit();
}
$EmailFrom = "****";
$EmailTo = "****";
$Subject = "****";
$contactname = Trim(stripslashes($_POST['contactname']));
$companyname = Trim(stripslashes($_POST['companyname']));
$username = Trim(stripslashes($_POST['username']));
$phone = Trim(stripslashes($_POST['phone']));
$email = Trim(stripslashes($_POST['email']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=../404.php/\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Contact Name: ";
$Body .= $contactname;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $companyname;
$Body .= "\n";
$Body .= "Preferred Username: ";
$Body .= $username;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print '<script type="text/javascript">';
print 'alert("Your Submission will be reviewed by an Admin and you will receive an email shortly")';
print '</script>';
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://****.com/****/\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=../404.php/\">";
}
?>
You are missing a } at the end (before ?>)
Be sure to indent your code correctly to easily catch these errors.
Add another curly bracket at the end and it should be ok i think
You are not closing the curly bracket for your top level if statement if(isset($_REQUEST['Submit'])){
OR based on how you want your flow you can remove the curly bracket from
if($captcha=!$key){
exit();
So that it becomes
if($captcha!=$key)
exit();
Notice that i changed =! to != as well

SMTP problem with PHP form in Godaddy hosting!

I was testing this (nice) simple form from CSS Tricks. In a website hosted in Godaddy.
And I got the following warning:
Warning: mail() [function.mail]: SMTP server response: 451 See
http://pobox.com/~djb/docs/smtplf.html
in
D:\Hosting\4923367\html\test\contactengine
on line 32.
(I checked the page but i didn't see anything useful)
contactengine.php
<?php
$EmailFrom = "chriscoyier#gmail.com";
$EmailTo = "janoochen#gmail.com";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$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\">";
}
?>
Any suggestions?
This link provides a solution. Try replacing your newlines with \r\n
In mail message headers and content, new lines are supposed to be denoted by both a carriage return (CR) and a line feed (LF)

Categories