• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

php发送html邮件

PHP 水墨上仙 2353次浏览

这段代码演示了php中如何发送html格式的邮件

/*
EXAMPLE: htmlmail('user@domain.com', 'Look ma, HTML e-mails','You just got <a href="http://www.yougotrickrolled.com/">Rick Rolled</a>');
NOTE: $headers is optional, but can be used to set From, CC, etc. Go to http://www.htmlite.com/php029.php for info
*/
 
function htmlmail($to, $subject, $message, $headers = NULL)
{
	$mime_boundary = md5(time()); 
 
	$headers .= "\nMessage-ID: <" . time() . " TheSystem@{$_SERVER['SERVER_NAME']}>\n";
	$headers .= "X-Mailer: PHP " . phpversion() . "\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-Type: multipart/alternative;boundary={$mime_boundary}\n\n";
 
	$newmessage = "This is a multi-part message in MIME format.";
	$newmessage .= "\n\n--{$mime_boundary}\n";
	$newmessage .= "Content-type: text/plain;charset=utf-8\n\n";
	$newmessage .= strip_tags(str_replace(array('<br>', '<br />'), "\n", $message)) . "\n\n";
 
	$newmessage .= "\n\n--{$mime_boundary}\n";
	$newmessage .= "Content-type: text/html;charset=utf-8\n\n";
 
	// prepended HTML
	$newmessage .= '<body style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff" valign="top"><table width="750" border="0" cellpadding="0" cellspacing="0" align="center"><tr><td bgcolor="#ffffff" width="750">';
 
	// HTML message that was passed to this function
	$newmessage .= $message;
 
	// appended HTML
	$newmessage .= '</td></tr></table></td></tr></table></body>';
 
	return mail($to, $subject, $newmessage, $headers);
}


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明php发送html邮件
喜欢 (0)
加载中……