Sådan ser min mailer kode ud
og begge mine sider er encode utf-8 hvis tjekker det i mit webprogram
<?php
function checkContentAndSendMailTo($receiver_emails)
{
// Check if a reset of entered data was requested
if (isset($_POST['reset'])) {
unset($_POST['name'],$_POST['email'],$_POST['subject'],$_POST['message']);
header('Location: .'); // Enables user to reload (F5) without being warned to resend data
return '';
}
// Check if user has clicked the submit button and not just reloaded the verification image
if (!isset($_POST['submit'])) {
return '';
}
// Get submitted data and pre-process it
$name = isset($_POST['name'])?$_POST['name']:'';
$name = htmlentities(stripslashes($name), ENT_QUOTES);
$name = trim(preg_replace("/\r|\n/", ' ', $name));
$email = isset($_POST['email'])?$_POST['email']:'';
$email = htmlentities(stripslashes($email), ENT_QUOTES);
$email = trim(preg_replace("/\r|\n/", ' ', $email));
$subject = isset($_POST['subject'])?$_POST['subject']:'';
$subject = htmlentities(stripslashes($subject), ENT_QUOTES);
$subject = trim(preg_replace("/\r|\n/", ' ', $subject));
$message = isset($_POST['message'])?$_POST['message']:'';
$message = htmlentities(stripslashes($message), ENT_QUOTES);
$message = trim(preg_replace("/\r\n/","<br/>\n", $message));
$copy = isset($_POST['copy'])?true:false;
$challengeAnswer = isset($_POST['challengeAnswer'])?trim($_POST['challengeAnswer']):'';
$challengeSolution = trim($_SESSION['challengeSolution']);
// Check for errors in submitted data
$errors = array();
if (!preg_match("/[A-z]/", $name)) {
$errors[] = 'Dit navn.';
}
if (!checkEmail($email)) {
$errors[] = 'En korrekt e-mail addresse.';
}
if (!preg_match("/[A-z]/", $subject)) {
$errors[] = 'Husk et emne.';
}
if (!preg_match("/[A-z]/", $message)) {
$errors[] = 'En besked til Anne.';
}
if (unwantedWords($name) || unwantedWords($subject) || unwantedWords($message)) {
$errors[] = 'A name, subject, and/or message without inappropriate words.';
}
if (strcmp(strtolower($challengeAnswer),strtolower($challengeSolution)) != 0) {
$errors[] = 'The correct verification text (only letters A-Z and case insensitive).';
}
// Any errors are explained to the user else the mail is sent and a status message shown
if (count($errors) > 0) {
return showErrorMessages($errors);
}
else {
return sendMail($name,$email,$subject,$message,$copy,$receiver_emails);
}
}
/**
* Send mail as HTML to a list of receivers.
* @param $name Name of the sender.
* @param $email E-mail address of the sender.
* @param $subject Subject of the mail.
* @param $message Body of the mail.
* @param $copy True or false for sending a self-copy to $email.
* @param $receiver_emails Comma separated list of receiver e-mail addresses.
* @return HTML string with success or error message.
*/
function sendMail($name, $email, $subject, $message, $copy, $receiver_emails)
{
// Build HTML table with submitted data
$message = '<table cellspacing="0" class="messageTable">
<tr>
<td class="leftCol" valign="top"><strong>Navn:</strong></td>
<td class="rightCol">'.$name.'</td>
</tr>
<tr>
<td class="leftCol" valign="top"><strong>E-mail:</strong></td>
<td class="rightCol">'.$email.'</td>
</tr>
<tr>
<td class="leftCol" valign="top"><strong>Emne:</strong></td>
<td class="rightCol">'.$subject.'</td>
</tr>
<tr>
<td class="leftCol" valign="top"><strong>Besked:</strong></td>
<td class="rightCol">'.$message.'</td>
</tr>
<tr>
<td class="leftCol" valign="top"><strong>Tid:</strong></td>
<td class="rightCol">'.strftime("%Y-%m-%d %H:%M:%S").'</td>
</tr>
</table>';
// Build HTML document for sending by e-mail
$message_mail ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//DA"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<title>'.$subject.'</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style type="text/css">
body, h3, td {font-family:arial,sans-serif; font-size:12px;}
h3 {font-size:13px;}
table, td {border:1px solid #cccccc;}
td {vertical-align:top; text-align:left; padding:5px;}
td.leftCol {width:70px;}
td.rightCol {width:330px;}
</style>
</head>
<body>
<h3>Besked fra '.$_SERVER['HTTP_HOST'].'</h3>
'.$message.'
</body></html>';
// Prepare to send e-mail
$message_mail = wordwrap($message_mail, 70); //Should not be longer than 70 characters
$subject = html_entity_decode($subject, ENT_QUOTES);
$info = '';
$headers .= 'Fra: '.$name.' <'.$email.'>'. "\r\n".
'MIME-Version: 1.0'. "\r\n".
'Content-type: text/html; charset=utf-8'. "\r\n".
'Content-Transfer-Encoding: 8bit'.
'X-Mailer: PHP/'.phpversion();
// Send to all comma separated e-mails in $receiver_emails. Must comply with RFC 2822
if (mail($receiver_emails, $subject, $message_mail, $headers)) {
if ($copy) {// If the user requested a copy
mail($email, $subject, $message_mail, $headers);
$info = '<p>En kopi er sendt til: <strong>'.$email.'.</strong></p>';
}
unset($_POST['name'],$_POST['email'],$_POST['subject'],$_POST['message']);
return '<div id="mailInfo">'.
'<h3 class="successText">Din besked er sendt med success til Anne Toxværd:</h3>'.
$message . $info.'</div>';
}
else {
return '<div id="mailInfo">'.
'<h3 class="errorText">A small error occurred while sending</h3>'.
'<p>Please try again in 5 minuttes or contact the administrator if the error '.
'continues.</p></div>';
}
}
/**
* Error message handler. Write out content of array $errors in an unordered list.
* @param $errors Array with error descriptions.
* @return HTML string with unordered list with all errors.
*/
function showErrorMessages($errors)
{
$message = '<div id="mailInfo"><h3 class="errorText">Der er fejl vær sikker på du har udfyldt alt og prøv igen:</h3><ul>';
for ($i = 0; $i < count($errors); $i++) {
$message .= '<li>' . $errors[$i] . '</li>';
}
return $message.'</ul><p>Der er fejl vær sikker på du har udfyldt alt og prøv igen.</p></div>';
}
/**
* Checks the given string for banned words found in file banned_words.txt where
* the banned words or sentences are stored one for each new line. A line can contain
* spaces but should not have either leading or trailing spaces.
* The function searches the input string and returns true if any match is found.
* If the file banned_words.txt could not be found, the function allows to continue and
* returns false. Thereby banned words can be disabled simply by deleting banned_words.txt.
* @param $str String to check.
* @return boolean
*/
function unwantedWords($str)
{
$bannedWordsURL = 'banned_words.txt';
$bannedWordsArray = file($bannedWordsURL, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($bannedWordsArray != false) {
$bannedWords = implode('|', $bannedWordsArray);
$remove = array("\n", "\r", "\t");
$bannedWords = str_replace($remove, "", $bannedWords);
}
else {
return false; // File not found: Allow to continue if banned words are not required
}
if (preg_match('/\b('.$bannedWords.')\b/i', $str) !== 0) {
return true;
}
else {
return false;
}
}
/**
* Check an e-mail address to be on the form x@x.xx or x@x.xxx and check for a DNS
* record of type MX, A, or CNAME for given Internet host name (only works on Windows
* as of PHP 5.3.0).
* @param $email String to check.
* @return boolean
*/
function checkEmail($email)
{
if ((preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/',$email)) ||
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)))
{
$host = explode('@', $email);
if (function_exists('checkdnsrr')) {
if (checkdnsrr($host[1], 'MX') ||
checkdnsrr($host[1], 'A') ||
checkdnsrr($host[1], 'CNAME')) {
return true;
}
}
else {
return true; // Do not block prior to PHP 5.3.0 on Windows
}
}
return false;
}
?>