Phpmailer与Umlaut有问题

时间:2015-08-18 16:47:03

标签: php phpmailer html-form diacritics html-form-post

我设置了一个反馈表,但是当它涉及变音符号(元音变异)时它是不稳定的。例如。有时它会将'ö'显示为'ö'(正确),但有时我会得到一些奇怪的东西,比如'Hร¼ttenkäse'而不是'Hüttenkäse'。

页面编码(在Dreamweaver中)设置为Unicode(UTF-8),在phpmailer中我也改了它:

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

我在send.php的开头尝试了以下内容:

header('charset=utf-8'); 

但是我收到了来自服务器的错误消息,虽然邮件已发送,但主题中没有正确的破坏声,所以这似乎不起作用。

send.php由此表单触发:

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

并且send.php看起来像这样:

<?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 = "service@demo.com";
$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';

?>

现在我真的不知道我还能做什么!非常感谢您的帮助 - 我期待您的建议!

1 个答案:

答案 0 :(得分:14)

感谢adlag的输入,这是解决方案:

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