Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 15:02 Der er 17 kommentarer

Problemer med æøå i mail

// 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>';
        }
Viser ikke æøå
Hvad gør jeg forkert?
Avatar billede repox Seniormester
03. juni 2014 - 15:08 #1
Er du sikker på dit indhold er UTF-8 encodet?
Avatar billede jakobdo Ekspert
03. juni 2014 - 15:14 #2
Som repox siger, når du gemmer filen, så skal du sørge for at vælge: GEM SOM UTF-8. Man gør den fejl de stadig gemmer filen som ascii. :o)
Avatar billede repox Seniormester
03. juni 2014 - 15:16 #3
Alternativt kan man utf8_enode() indholdet i den mail man sender.
Jeg tænker specifikt på situationer hvor man sender og modtager data via HTTP i to forskellige tegnsæt.
Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 15:19 #4
den er gemt i utf-8.. 100%
Hvordan enode det kan du give et eksempelt Repox?
Avatar billede repox Seniormester
03. juni 2014 - 15:21 #5
Hvis du f.eks. fra den side du sender, sender med ISO-8859-1 i stedet for UTF-8, så har du en uoverensstemmelse.
Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 15:28 #6
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&aelig;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&aelig;r sikker p&aring; du har udfyldt alt og pr&oslash;v igen:</h3><ul>';
   
    for ($i = 0; $i < count($errors); $i++) {
        $message .= '<li>' . $errors[$i] . '</li>';
    }
   
    return $message.'</ul><p>Der er fejl v&aelig;r sikker p&aring; du har udfyldt alt og pr&oslash;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;
}

?>
Avatar billede repox Seniormester
03. juni 2014 - 15:31 #7
Ligger det online? Har du et link? Det kan også være din webserver der driller.
Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 15:33 #8
Avatar billede jakobdo Ekspert
03. juni 2014 - 15:33 #9
Du kan også teste denne:

$message_mail = wordwrap(utf8_encode($message_mail), 70); //Should not be longer than 70 characters
    $subject = html_entity_decode(utf8_encode($subject), ENT_QUOTES);
Avatar billede repox Seniormester
03. juni 2014 - 15:36 #10
Det er ikke webserveren der er problemet, så jakobdos forslag burde virke.
Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 15:43 #11
Emne:    tæst tæst
Besked:    æøå æøå

virker ikke :(
Avatar billede repox Seniormester
03. juni 2014 - 15:45 #12
Prøv med utf8_decode() i stedet, så.
Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 15:49 #13
heller ikke :/

min kontakt side ser sådan her ud

<div id="indhold">
               
         
              <?php
$form_receivers = 'henrikettrup@gmail.com'; // Set receiver e-mails comma separated here

error_reporting(0); // Turn off error reporting
session_start(); // Session is used for challenge image (must come before any html output)
require_once('mailer.php'); // Include mail functions

$responseToUser = checkContentAndSendMailTo($form_receivers); // Check if the form has been submitted and process data

$name = isset($_POST["name"])?stripslashes($_POST["name"]):''; // Following four is for postback of user data
$email = isset($_POST["email"])?stripslashes($_POST["email"]):''; // E.g. when reloading the verification image
$subject = isset($_POST["subject"])?stripslashes($_POST["subject"]):''; // or if there is errors in the user data the
$message = isset($_POST["message"])?stripslashes($_POST["message"]):''; // already entered data is reshown to the user
?>


    <?php echo $responseToUser; //Display submit info to users ?>
   
    <form action="#mailInfo" method="post" id="contactForm">
        <h1>Kontakt Anne Toxværd</h1><br />
        <label for="name">Dit Navn:</label>
        <input type="text" class="inputs" id="name" name="name" onkeypress="return event.keyCode!=13" value="<?php echo $name; ?>" />
        <br />
        <label for="email">Din E-mail:</label>
        <input type="text" class="inputs" id="email" name="email" onkeypress="return event.keyCode!=13" value="<?php echo $email; ?>" />
        <br />
        <label for="subject">Emne:</label>
        <input type="text"  class="inputs" id="subject" name="subject" onkeypress="return event.keyCode!=13" value="<?php echo $subject; ?>" />
        <br />
        <label for="message">Besked:</label>
        <textarea id="message" class="inputs" name="message" cols="45" rows="10"><?php echo $message; ?></textarea>
        <br />
       
        <label for="copy">Kopi til dig:</label>
        <input type="checkbox" id="copy" name="copy" value="1" onkeypress="return event.keyCode!=13"
            <?php echo ($_POST["copy"]?'checked="checked "':''); ?>/>
        <br />
       
        <label for="challengeAnswer">Bekræftelse:</label>
        <img src="challenge-image.php?width=153&amp;height=22" alt="Verification image" title="Verification image"
            style="border:1px solid silver;" />
            <input type="image" src="reload.png" alt="Try another text" style="cursor:pointer;"
                onclick="document.forms['contactForm'].submit" title="Try another image" />
        <br />
        <label for="challengeAnswer">Indtast bekræftelse:</label>
        <input type="text" class="inputs" id="challengeAnswer" name="challengeAnswer" onkeypress="return event.keyCode!=13" />
        <div class="subNote"><small>Indtast bekræftelse teksten her</small></div>

        <br />
        <label for="submit">&nbsp;</label>
        <input type="submit" class="button" id="submit" name="submit" value="Send"
            onclick="return checkFormContent(document.forms['contactForm']);" />
        <input type="submit" class="button" id="reset" name="reset" value="Reset" /><br><br>
Kan det være der fejlen ligger?
Avatar billede repox Seniormester
03. juni 2014 - 15:53 #14
Jeg tror du bliver nødt til at var_dump() det postdata du har for at se hvad indholdet er.
Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 15:58 #15
hvordan skriver jeg det?
Avatar billede repox Seniormester
03. juni 2014 - 16:01 #16
exit(var_dump($message)); lige inden du sender mailen
Avatar billede ettrup1987 Nybegynder
03. juni 2014 - 16:06 #17
Har jeg gjort nu tror jeg :) kan du så se noget ud fra det? eller?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester