PHP mail() '(单引号)在被转义的主题中

PHP mail() ' (single quote) in subject being escaped

我正在尝试使用 php mail() 功能发送电子邮件。我的代码如下。

$subject = "Let's Connect";
$to = $_POST['to'];
$message = $_POST['message'];

mail( $to, $subject, $message, array('Content-Type: text/html; charset=UTF-8'));  

问题是主题行中的 ' 在 Gmail 和 Yahoo 等电子邮件客户端中变为 \'Let's Connect 变为 Let\'s Connect。我在这里尝试了几种解决方案,比如

$sub = '=?UTF-8?B?'.base64_encode($subject).'?=';
$decoded_str = html_entity_decode ( $value_to_decode, ENT_QUOTES, 'UTF-8' );

None 其中似乎有效。我应该怎么做才能解决它?

萨克斯

要么像这样使用双引号:

$subject = "Let's Connect";

或者您可以使用斜杠跳过它

$subject = 'Let\'s Connect';

你可以通过stripslashes($subject)

我会使用 stripslashes()html_entity_decode()

mail( $to, stripslashes(html_entity_decode($subject, ENT_QUOTES, 'UTF-8' )), $message, array('Content-Type: text/html; charset=UTF-8'));