0

Is there any way to make a PHP form UTF-8 friendly without HTML-Email-Content? My current script is not working. I think the "Content-type" in the header is for HTML-Content only, right?

<?php

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        // Get the form fields and remove whitespace.
        $anrede = $_POST['anrede'];
        $vorname = $_POST['vorname'];
        $nachname = $_POST['name'];
        $email = $_POST['email'];
        $nachricht = $_POST['nachricht'];

        if ( empty($firma) OR empty($vorname) OR empty($nachname) OR empty($email) OR empty($nachricht) ) {
            // Set a 400 (bad request) response code and exit.
            header("HTTP/1.0 404 Not Found");
            echo "Error!";
            exit;
        }

        $recipient_edc = "my@email.de";

        $subject = "edc-daten.de | $vorname $nachname";

        $email_content = "Name: $anrede $vorname $nachname\n";
        $email_content .= "E-Mail: $email\n\n";
        $email_content .= "Nachricht:\n$nachricht\n";

        $email_headers = "From: $vorname $nachname <$email>";
        $email_headers .= "Content-type: text/plain; charset=UTF-8" . 'rn';

        if (mail($recipient_edc, $subject, $email_content, $email_headers)) {

            header("HTTP/1.1 200 Ok");
            echo "Erfolg!";
        } else {
            header("HTTP/1.1 500 No Record Found");
            echo "Error!";
        }

    } else {
        header('HTTP/1.0 403 Forbidden');
        echo "Error!";
    }

?>
susanloek
  • 411
  • 1
  • 5
  • 19
  • have a look at this Q&A http://stackoverflow.com/questions/12830546/accept-charset-utf-8-parameter-doesnt-do-anything-when-used-in-form – Funk Forty Niner Nov 19 '15 at 14:03
  • `$email_headers .= "Content-type: text/plain; charset=UTF-8" . 'rn';` ? Technically you've just set the charset to `UTF-8rn` you probably want `$email_headers .= "Content-type: text/plain; charset=UTF-8\r\n";` ... though if you're using Postfix as the mailserver it should probably be `$email_headers .= "Content-type: text/plain; charset=UTF-8" . PHP_EOL`; – CD001 Nov 19 '15 at 14:36

0 Answers0