我目前正在使用一个脚本,该脚本使用 file_get_contents 来获取 php 文件的内容,然后将其通过电子邮件发送给客户列表。我想更改脚本以允许纯文本回退,以降低被标记为垃圾邮件的风险。
这是我目前的脚本:
function sendit($to,$subject,$body)
{
$headers = "To: <{$to}>\n".
"From: Test Newsletter Admin <[email protected] /cdn-cgi/l/email-protection>\n".
"Reply-To: Test Newsletter Admin <[email protected] /cdn-cgi/l/email-protection>\n".
"MIME-Version: 1.0\n".
"Content-Type: text/html; charset=ISO-8859-1\n";
$mail_sent = @mail($to, $subject, $body, $headers);
return $mail_sent;
}
$content = file_get_contents('attach/newsletter.php');
//require_once('../../func.php');
set_time_limit(0);
date_default_timezone_set('Europe/London');
$log = fopen('send'.date('dmY',time()).'.log','wb');
//$array = file('NonCustClean.txt');
$array = file('devaddresses.txt');
// Delay In Seconds between emails (must be INT)
$delay = 10;
$count = count($array);
$end = time()+ ($delay*$count);
echo "Start Time: ".date('d/m/Y H:i:s',time()).'<br />';
echo "Estimated End Time: ".date('d/m/Y H:i:s',$end).'<br />';
echo "(".dateDiff(time(),$end).")<br />";
foreach ($array as $email)
{
$status = (sendit(trim($email), 'Test Newsletter',$content))?'Sent':'failed';
fwrite($log,date('[d/m/Y H:i:s]',time()).' Email '.$status.' to '.trim($email)."\n");
echo date('[d/m/Y H:i:s]',time()).' Email '.$status.' to '.trim($email)."</br>";
flush();
sleep(10);
}
Newsletter.php 仅包含基本的 HTML/CSS 代码。
有人可以建议我如何更改此脚本以伴随纯文本后备吗?
谢谢你的帮助。
您正在寻找的内容称为多部分电子邮件。它的主体包含 HTML 和文本,由所谓的“边界”分隔。然后,电子邮件客户端将根据其功能和用户首选项自行确定是显示邮件的 HTML 版本还是文本版本。
有关如何设置此功能的示例(source http://www.tek-tips.com/faqs.cfm?fid=2681):
$notice_text = "This is a multi-part message in MIME format.";
$plain_text = "This is a plain text email.\r\nIt is very cool.";
$html_text = "<html><body>This is an <b style='color:purple'>HTML</b>" .
"text email.\r\nIt is very cool.</body></html>";
$semi_rand = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);
$to = "Me <[email protected] /cdn-cgi/l/email-protection>";
$bcc = "You <[email protected] /cdn-cgi/l/email-protection>, Them <[email protected] /cdn-cgi/l/email-protection>";
$from = "Me.com <[email protected] /cdn-cgi/l/email-protection>";
$subject = "My Email";
$body = "$notice_text
--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
$plain_text
--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
$html_text
--$mime_boundary--";
if (@mail($to, $subject, $body,
"From: " . $from . "\n" .
"bcc: " . $bcc . "\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=" . $mime_boundary_header))
echo "Email sent successfully.";
else
echo "Email NOT sent successfully!";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)