我有以下 php 脚本,它从服务器上的 .txt 文件加载 html 模板,并在发送电子邮件之前使用 str_replace 用电子邮件内容填充模板。
起初,我尝试将服务器上的 Webmail 地址硬编码到 mailer_send 函数的“收件人”字段中,效果很好。电子邮件模板完美显示。然而,当我尝试将其发送到 Gmail 帐户时,它被标记为垃圾邮件,并且 HTML 仅显示为纯文本。有谁知道我是否需要在电子邮件中包含任何其他标头以确保 Gmail 正确处理它?
理想情况下,我想通过我的服务器上的网络邮件向自己发送一封电子邮件,然后向用户发送自动回复,感谢他们的询问,但如果该消息始终被视为垃圾邮件,则这是不可能的。
<?php
function mailer_send($mailer_recipient, $mailer_subject, $mailer_message){
$mailer_headers = 'From: webmaster@example' . '\r\n' .
'X-Mailer: PHP/' . phpversion() . '\r\n' .
'MIME-Version: 1.0\r\n' . '\r\n' .
'Content-Type: text/html; charset=ISO-8859-1\r\n';
mail($mailer_recipient, $mailer_subject, $mailer_message, $mailer_headers);
}
$name = $_POST['inputName'];
$email = $_POST['inputEmail'];
$message = strip_tags($_POST['inputMessage']);
$template = file_get_contents('email_templates/template.txt');
$template2 = $template;
$template = str_replace('[email_content]',$message, $template);
mailer_send('[email protected] /cdn-cgi/l/email-protection','Test Email',$template);
$message2 = '<h2>Thanks..</h2><br/><p>Dear' . $name . '</p><br/><p>Thanks for your enquiry. Jason will get back to you with a quote as soon as possible.</p>';
$template2 = str_replace('[email_content]', $message2, $template2);
mailer_send($email,'Thankyou for your Enquiry',$template2);
?>
提前致谢。
额外的:
当 Gmail 收到电子邮件时,它似乎忽略了“发件人”标头,只是说该电子邮件来自我的网络托管提供商服务器。