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

php发送邮件

PHP 水墨上仙 2191次浏览 0个评论

php发送邮件

function sendEmail($to, $from, $subject, $message, $html_message=null) {
		$eol = "\n";
 
		$mime_boundary = md5(time());   
 
		$mime_boundary_header = chr(34) . $mime_boundary . chr(34);
 
		if (empty($html_message)) {
			$html_message = nl2br($message);
		}
 
		$headers = "From: $from" . $eol;
		$headers .= "Message-ID: <" . time() . " domain>" . $eol;
		$headers .= "X-Mailer: PHP v" . phpversion() . $eol;          // These two to help avoid spam-filters
		$headers .= 'MIME-Version: 1.0' . $eol;
 
		// Setup for text OR html
		$headers .= "Content-Type: multipart/alternative; boundary=" . 
			$mime_boundary_header . $eol . $eol;
		$msg = "This is a multi-part message in MIME format to $to." . 
			$eol . $eol;
 
		// Text Version
		$msg .= "--" . $mime_boundary . $eol;
		$msg .= "Content-Type: text/plain;" .$eol . $eol;
 
		//$msg .= "Content-Transfer-Encoding: base64".$eol;
		//$msg .= base64_encode($txt_body).$eol.$eol;
		$msg .= $message . $eol . $eol;
 
		// HTML Version
		$msg .= "--".$mime_boundary . $eol;
		$msg .= "Content-Type: text/html;{$eol}Content-Transfer-Encoding: 7bit" . 
			$eol . $eol;
 
		//$msg .= "Content-Transfer-Encoding: base64".$eol;
		//$msg .= base64_encode($html_body).$eol.$eol;
		$msg .= $html_message . $eol . $eol;
 
		// finish with two eol's for better security. see Injection.
		$msg .= "--" . $mime_boundary . "--" . $eol . $eol;
 
		if (isset($_SERVER) && isset($_SERVER['HTTP_HOST']) && !preg_match('/\.com$/', $_SERVER['HTTP_HOST'])) {
			// DEV
			preg_match('/[\w|\d|\ |\-]+/', $subject, $subject_label);
			if (defined('DOCUMENT_ROOT')) {
				$logfile = DOCUMENT_ROOT .'/scripts/logs/sendEmail/mail_'. microtime(true);
 
			} else {
				$logfile = '../../scripts/logs/sendEmail/mail_'. microtime(true);
			}
 
			if (isset($subject_label[0])) {
				$logfile .= ' - '. $subject_label[0];
			}
			$fh = fopen($logfile . '.log', 'w+');
 
			if (!$fh) {
				$fh = fopen(preg_replace('/^\.\.\//', '', $logfile) . '.log', 'w+');
			}
 
			if ($fh) {
				$filelog_content = date('Y-m-d H:i:s')."\n\n";
				$filelog_content .= print_r($to, true)."\n";
				$filelog_content .= print_r($subject, true)."\n\n";
				$filelog_content .= print_r($msg, true);
 
				fwrite($fh, $filelog_content);
				fclose($fh);
			}
 
		} else {
			mail($to, $subject, $msg, $headers, "-fdonotreply@domain.com");
		}
	}


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

您必须 登录 才能发表评论!

加载中……