Php str_replace不替换邮件发送时的字符串

Php str_replace不替换邮件发送时的字符串,php,str-replace,Php,Str Replace,我正在尝试使用str_replace()在发送电子邮件时插入用户名。它不起作用了,我错过什么了吗?电子邮件已处理,但未替换为$en['user']变量 $text_content = file_get_contents('emails/welcome_txt.tpl'); $html_content = file_get_contents('emails/welcome.tpl'); $body = "--$mime_boundary\n";

我正在尝试使用
str_replace()
在发送电子邮件时插入用户名。它不起作用了,我错过什么了吗?电子邮件已处理,但
未替换为
$en['user']
变量

        $text_content = file_get_contents('emails/welcome_txt.tpl');
        $html_content = file_get_contents('emails/welcome.tpl');

        $body = "--$mime_boundary\n";
        $body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n";
        $body.= "Content-Transfer-Encoding: 7bit\n\n";
        $body.= str_replace("<!--{Username}-->",$en['user'],$text_content);
        $body.= "\n\n";

        $body.= "--$mime_boundary\n";
        $body.= "Content-Type: text/html; charset=\"UTF-8\"\n";
        $body.= "Content-Transfer-Encoding: 7bit\n\n";    
        $body.= str_replace("<!--{Username}-->",$en['user'],$html_content);
        $body.= "\n\n";
        $body.= "--$mime_boundary--\n";
$text\u content=file\u get\u contents('email/welcome\u txt.tpl');
$html_content=file_get_contents('email/welcome.tpl');
$body=“--$mime\U边界\n”;
$body.=“内容类型:文本/普通;字符集=\”字符集=美国ascii \“\n”;
$body.=“内容传输编码:7bit\n\n”;
$body.=str_replace(“,$en['user'],$text_content);
$body.=“\n\n”;
$body.=“--$mime\U边界\n”;
$body.=“内容类型:text/html;字符集=\“UTF-8\”\n”;
$body.=“内容传输编码:7bit\n\n”;
$body.=str_replace(“,$en['user'],$html_content);
$body.=“\n\n”;
$body.=“--$mime\U边界--\n”;

我建议进行一点printf调试。打印出该行前后的变量,看看是什么。这意味着电子邮件仍然包含
,或者替换者将用户名留空?请注意,如果设置了
str_replace()
,并且文本包含placeholders@hek2mgl
remained@acctman这是您评论中的一个打字错误还是您缺少了
}
?@hek2mgl打字错误。当我执行
printf