Ollie
Ollie

Reputation: 562

Phpmailer having problems with Umlaut

I have a feedback form set up but it's unstable when it comes to umlaute (vowel mutation). E.g. sometimes it showes an 'ö' as 'ö' (correct), but then sometimes i get something weird like 'Hร¼ttenkäse' instead of 'Hüttenkäse'.

Page Coding (in Dreamweaver) is set to Unicode (UTF-8), in phpmailer i changed it as well:

/**
 * The character set of the message.
 * @type string
 */
public $CharSet = 'UTF-8';

I tried the following at the beginning of my send.php:

header('charset=utf-8'); 

but I got an error message from the server, although the mail was sent, but without the correct umlaute in the subject, so this didn't seem to work.

the send.php is triggered by this form:

<form method="post" action="send.php">

and the send.php looks like this:

<?php

require_once("includes/phpMailer/class.phpmailer.php");
require_once("includes/phpMailer/class.smtp.php");
require_once("includes/phpMailer/language/phpmailer.lang-de.php");

$dl = $_GET['dienstleistung'];

$vorn = $_POST['vorname']; // für Vorname falls keine Anrede

$anredeGross = ucfirst($_POST[anrede]);

	if ($anredeGross === "Herr") {
		$anredeGross = $anredeGross . "n";
	} elseif ($anredeGross === "Leer") {
		$anredeGross = $vorn;
	} else {
		$anredeGross = $anredeGross;	
	}

$firma = $_POST['firma'];

	if ($firma !=='') {
		$firma = ' von der Firma '.$firma;	
	} else {
		$firma = '';
	}

$to_name = "Service Provicer";
$to = "[email protected]";
$subject = "Anfrage von ".$anredeGross." ".$_POST['name'].$firma;
$message = $_POST['nachricht']."\n \n"."Ich interessiere mich für die folgenden Dienstleistungen: "."\n \n"; 
$message .= implode(', ', $_POST['dienstleistungen']);
$message = wordwrap($message, 70);
$from_name = $_POST['vorname'] . " " . $_POST['name'];
$from = $_POST['email'];

$mail = new PHPMailer();

$mail->Host = "www.myhost.host";
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail ->Username = "username";
$mail ->Password = "password";
$mail->FromName = $from_name;
$mail->From = $from;
$mail->addAddress($to, $to_name);
$mail->Subject = $subject;
$mail->Body = $message;

$result = $mail->send();
echo $result ? 'Sent' : 'Error';

?>

And now I really don't know what else I could do! Thanks a lot for your help - I'm looking forward to your suggestions!

Upvotes: 14

Views: 5947

Answers (1)

Ollie
Ollie

Reputation: 562

thanks adlag for your input, this is the solution:

$mail->CharSet ="UTF-8";

Upvotes: 28

Related Questions