Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 955
Ollie Avatar asked Aug 18 '15 16:08

Ollie


People also ask

How do I debug PHPMailer?

Enable SMTP debugging and set the debug level in your script as follows: $mail->SMTPDebug = 2; level 1 = client; will show you messages sent by the client. level 2 = client and server; will add server messages, it's the recommended setting.

What is AddReplyTo PHPMailer?

PHPMailer Script to Send Email Using SMTP Authentication From: the sender's email address. FromName: the sender's name. AddAddress: the recipient's email address and name. AddReplyTo: the reply-to email address and name.

Is PHPMailer secure?

But SPEWS can be worse than annoying: thanks to a security vulnerability in a popular web software component called PHPMailer, crooks could use your “contact us” form to take over your whole website. 24/7 threat hunting, detection, and response delivered by an expert team as a fully-managed service.


1 Answers

thanks adlag for your input, this is the solution:

$mail->CharSet ="UTF-8";
like image 144
Ollie Avatar answered Oct 05 '22 23:10

Ollie