str_ireplace 对于 file_put_content 不工作
str_ireplace for file_put_content not working
我尝试用客户电子邮件替换##email##。这适用于电子邮件正文,但不适用于附件。
$attachfile = file_get_contents("attachment/test.txt");
$attachfile = str_ireplace("##email##", $customeremail, $attachfile);
$tempattach = tempnam("/tmp", 'prefix');
file_put_contents($tempattach.".txt", $attachfile);
$mail->addAttachment($tempattach.".txt", "Hello.txt"]), "base64");
unlink($tempattach.".txt");
附件在您发送之前不会被真正阅读。所以如果你添加了一个附件文件,然后在发送前删除了它(这是你正在做的),它就不会被发送。
不过从您的操作来看,您最好跳过外部文件并使用 addStringAttachment
在内存中进行替换和附加,如下所示:
$attachfile = file_get_contents("attachment/test.txt");
$attachfile = str_ireplace("##email##", $customeremail, $attachfile);
$mail->addStringAttachment($attachfile, "Hello.txt");
我尝试用客户电子邮件替换##email##。这适用于电子邮件正文,但不适用于附件。
$attachfile = file_get_contents("attachment/test.txt");
$attachfile = str_ireplace("##email##", $customeremail, $attachfile);
$tempattach = tempnam("/tmp", 'prefix');
file_put_contents($tempattach.".txt", $attachfile);
$mail->addAttachment($tempattach.".txt", "Hello.txt"]), "base64");
unlink($tempattach.".txt");
附件在您发送之前不会被真正阅读。所以如果你添加了一个附件文件,然后在发送前删除了它(这是你正在做的),它就不会被发送。
不过从您的操作来看,您最好跳过外部文件并使用 addStringAttachment
在内存中进行替换和附加,如下所示:
$attachfile = file_get_contents("attachment/test.txt");
$attachfile = str_ireplace("##email##", $customeremail, $attachfile);
$mail->addStringAttachment($attachfile, "Hello.txt");