5

我有以下脚本:

<?php
    $subject = "Testmail — Special Characters";
    $msg = "Hi there,\n\nthis isn’t something easy.\n\nI haven’t thought that it’s that complicated!";

    mail($to,$subject,$msg,$from."\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n");
?>

在电子邮件中:

主题:Testmail ? Special Characters

身体:

Hi there,

this isn?t something easy.

I haven?t thought that it?s that complicated!

我尝试了很多东西,但我已经没有想法了。你能帮助我吗?你有没有得到这个工作?

谢谢!

4

3 回答 3

18

你试过iconv_set_encoding吗?

这应该工作:

<?php
 iconv_set_encoding("internal_encoding", "UTF-8");

$subject = "Testmail — Special Characters";
$msg = "Hi there,\n\nthis isn’t something easy.\n\nI haven’t thought that it’s that complicated!";

mail(utf8_decode($to), utf8_decode($subject), utf8_decode($msg), utf8_decode($from)."\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n");?>
于 2013-10-31T13:46:15.383 回答
0

虽然iconv_set_encoding对我不起作用,但以下内容确实有效:

// Force PHP to use the UTF-8 charset
header('Content-Type: text/html; charset=utf-8'); 

// Define and Base64 encode the subject line
$subject_text = 'Test email with German Umlauts öäüß';
$subject = '=?UTF-8?B?' . base64_encode($subject_text) . '?=';

// Add custom headers
$headers = 'Content-Type: text/plain; charset=utf-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: base64';

// Define and Base64 the email body text
$message = base64_encode('This email contains German Umlauts öäüß.');

// Send mail with custom headers
if (mail('recipient@domain.com', $subject, $message, $headers)) {
    echo 'Email has been sent!';
} else {
    echo 'Oops, something gone wrong!';
}

来源:https ://dev.to/lutvit/how-to-make-the-php-mail-function-awesome-3cii

于 2021-10-01T08:59:47.973 回答
-1

使用&rsquo;代替'。

例子:

The dog&rsquo;s bone.

确保将内容类型从 text/plain 更改为 text/html。

于 2013-10-31T13:47:46.277 回答