php连接smtp发送邮件代码
代码语言:php
所属分类:通讯
代码描述:php连接smtp发送邮件代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php
/**
* email smtp (support php7)
*
*/
class Smtp
{
/* Public Variables */
public $smtp_port;
public $time_out;
public $host_name;
public $log_file;
public $relay_host;
public $debug;
public $auth;
public $user;
public $pass;
/* Private Variables */
private $sock;
/* Constractor */
function __construct($relay_host = "", $smtp_port = 80,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject, $body, $mailtype, $cc, $bcc, $additional_headers, $fromUser, $replyToAddress)
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = preg_replace("/(^|(\r\n))(\.)/", "\1.\3", $body);
$header = "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html; charset=utf-8\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $fromUser<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= "Reply-To: ".$replyToAddress."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Maile.........完整代码请登录后点击上方下载按钮下载查看















网友评论0