problems with php script in the contact form
Copy link to clipboard
Copied
Hello, I am from the Czech Republic and I am not a coder. I have 2 problems with my php sript. I am using a simple php script from Paul Trani, see below.
Firstly the email adress - when someone inserts an email adress in this form paul@paultrani.com it is OK, but when someone writes an address for example paul.trani@paultrani.cz (this type of adress is very common in our country) the answer is "That is not a valid email address. Please return to the previous page and try again." I think the problem is the dot before the @.
Secondly diacritical marks - Since I am from the Czech Republic we use diacritical marks (for example š,č,ř,ž,á,í,é,ě) so instead of this letters a get ? or Å™ or Å¡ to my email.
I really do not know how to fix these problems.
Thank you for any help. Sorry for my English. Peter
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
$name=addslashes($_POST['name']);
$email=addslashes($_POST['email']);
$comments=addslashes($_POST['message']);
// you can specify which email you want your contact form to be emailed to here
$toemail = "paul@paultrani.com";
$subject = "From EcoStyleStudio.com";
$headers = "MIME-Version: 1.0\n"
."From: \"".$name."\" <".$email.">\n"
."Content-type: text/html; charset=iso-8859-1\n";
$body = "Name: ".$name."<br>\n"
."Email: ".$email."<br>\n"
."Comments:<br>\n"
.$comments;
if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
{
echo "That is not a valid email address. Please return to the"
." previous page and try again.";
exit;
}
mail($toemail, $subject, $body, $headers);
echo "Thanks for submitting your comments";
?>
</body>
</html>

Copy link to clipboard
Copied
ereg() has been deprecated, it is recommended that you dont use it.
You want to look at this
http://www.php.net/manual/en/function.preg-match.php
Within this page I found this:
If you need to check for .com.br and .com.au and .uk and all the other crazy domain endings i found the following expression works well if you want to validate an email address. Its quite generous in what it will allow <?php $email_address = "phil.taylor@a_domain.tv"; if (preg_match("/^[^@]*@[^@]*\.[^@]*$/", $email_address)) { return "E-mail address"; } ?>

Copy link to clipboard
Copied
<META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
$headers = "MIME-Version: 1.0\n"
."From: \"".$name."\" <".$email.">\n"
."Content-type: text/html; charset=iso-8859-1\n";
I want to understand that code... Please
Copy link to clipboard
Copied
$headers = "MIME-Version: 1.0\n"
."From: \"".$name."\" <".$email.">\n"
."Content-type: text/html; charset=iso-8859-1\n";
That code is setting the content of the $headers variable which is used in sending the form's results by email -
mail($toemail, $subject, $body, $headers);
It specifies the "From:" email address so that you can reply to it if needed, and it specifies that the email sent is to be sent as an HTML email not just as a text email. It really should be this, I believe.
$headers = "MIME-Version: 1.0\r\n"
."From: \"".$name."\" <".$email.">\r\n"
."Content-type: text/html; charset=iso-8859-1\r\n";

Copy link to clipboard
Copied
thank u very much

