云服务器

推荐列表 站点导航

当前位置:首页 > 服务器技术 > 云服务器 >

服务器_PHP的一个完整SMTP类(解决邮件服务器需要验证时的问题),smtp.php?phpclass smtp{/*

来源:网络整理  作者:  发布时间:2020-12-20 11:50
PHP的一个完整SMTP类(解决邮件服务器需要验证时的问题),smtp.php?phpclass smtp{/* Public Variables */var $smtp_port;var $time_out;var...

/*

{

{

}

$mailsubject = "Test Subject";//邮件主题

$this->smtp_port = $smtp_port;

continue;

#auth

$smtpserverport =25;//SMTP服务器端口

list($msec, $sec) = explode(" ", microtime());

test.php

{

return TRUE;

$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);

$smtp->debug = TRUE;//是否显示发送的调试信息

var $smtp_port;

$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";

}

/* Main Function */



$this->log_write("Connected to relay host ".$this->relay_host."\n");

function get_address($address)

$this->debug = FALSE;


function smtp_putcmd($cmd, $arg = "")

var $auth;

if ($bcc != "") {

if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {

var $host_name;

function smtp_message($header, $body)

function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")

}

$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");

$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);

$sent = FALSE;

}

}

return FALSE;

##########################################

$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);

{

return $this->smtp_error("sending MAIL FROM command");

$header .= "From: $from<".$from.">\r\n";

return TRUE;

$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");

}

{

var $time_out;

return $this->smtp_error("sending HELO command");

if (!($this->sock && $this->smtp_ok())) {

/* Private Functions */

$header .= "To: ".$to."\r\n";

$this->smtp_debug($response."\n");

return $address;

}

这是一个测试程序!!!

$address = ereg_replace("([ \t\r\n])+", "", $address);

fclose($fp);

{

$this->log_write("Disconnected from remote host\n");

fgets($this->sock, 512);

{

/* Constractor */

return FALSE;;

$this->log_write("Connected to mx host ".$host."\n");

$this->host_name = "localhost"; //is used in HELO command

?>

if (!$this->smtp_sockopen($rcpt_to)) {

return $this->smtp_error("sending message");

return TRUE;

function smtp_sockopen($address)

$this->relay_host = $relay_host;

{

}

return $this->smtp_error("sending HELO command");

$this->smtp_debug(". [EOM]\n");

$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.

$smtpuser = "someone";//SMTP服务器的用户帐号

}

$smtppass = "someonepass";//SMTP服务器的用户密码

}

function smtp_ok()

function log_write($message)

}

<?php

$this->smtp_debug("> ".$cmd."\n");

$header .= "Cc: ".$cc."\r\n";

#

?>

$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));

$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));

if (!$this->smtp_eom()) {

##########################################

}

$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");

$TO = explode(",", $this->strip_comment($to));

foreach ($TO as $rcpt_to) {

if (!@getmxrr($domain, $MXHOSTS)) {

if (!$this->smtp_message($header, $body)) {

{

}

$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);

require("sm.php");

$sent = FALSE;

function smtp_send($helo, $from, $to, $header, $body = "")

}

var $pass;

return $this->smtp_error("sending DATA command");

foreach ($MXHOSTS as $host) {

}

if ($this->log_file == "") {

}

#

}

return $this->smtp_ok();

}

}

while (ereg($comment, $address)) {

}

fputs($this->sock, $header."\r\n".$body);

$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");

return $this->smtp_sockopen_mx($address);

}

function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)

$mail_from = $this->get_address($this->strip_comment($from));

}

$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;

if($cmd=="") $cmd = $arg;

/* Public Variables */

}

if (!$this->smtp_putcmd("HELO", $helo)) {

fputs($this->sock, $cmd."\r\n");

if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {

$header .= "Content-Type:text/html\r\n";

$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");

$comment = "\([^()]*\)";

$header .= "Subject: ".$subject."\r\n";

$this->user = $user;

{

if (!ereg("^[23]", $response)) {

}

}

if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {

function strip_comment($address)

if (!$this->smtp_putcmd("QUIT")) {

}

if($this->auth){

fputs($fp, $message);

$this->log_write("Error: ".$errstr." (".$errno.")\n");

}

{

return TRUE;;

return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");

fclose($this->sock);

$smtpemailto = "[email protected]";//发送给谁

$header .= "MIME-Version:1.0\r\n";

$address = ereg_replace($comment, "", $address);

$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);

}

$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");

else $cmd = $cmd." ".$arg;

$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));

return FALSE;

{

{

$sent = TRUE;

}

return $this->smtp_error("sending QUIT command");

} else {

echo $message;

var $user;

}

if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {

$mailbody = "<h1>This is a test mail</h1>";//邮件内容

}

fputs($this->sock, "\r\n.\r\n");

}

var $log_file;

return FALSE;

$this->auth = $auth;//auth

}

$header .= $additional_headers;

return TRUE;

fputs($this->sock, "QUIT\r\n");

$this->log_write("Error: Error occurred while ".$string.".\n");

continue;


}

$this->pass = $pass;

}

if ($cc != "") {

return $sent;

}

$header .= "Date: ".date("r")."\r\n";

$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");

return FALSE;

} else {

$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件

function smtp_eom()

}

$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);

flock($fp, LOCK_EX);

function smtp_sockopen_mx($address)

$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";

if (!($this->sock && $this->smtp_ok())) {

if (log_file">!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {

#

if($mailtype=="HTML"){

if ($this->relay_host == "") {

function smtp_error($string)

if (!$this->smtp_putcmd("", base64_encode($this->pass))) {

}

*/

return FALSE;

请按照说明设置好以下的参数,以下是以tom.com的用户为例设置好的.

return $address;

$this->log_write("Warning: Cannot connect to mx host ".$host."\n");

{

return $this->smtp_sockopen_relay();

$response = str_replace("\r\n", "", fgets($this->sock, 512));

$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");

var $debug;

/* Private Variables */

return TRUE;

$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");

$this->log_write("Error: Remote host returned \"".$response."\"\n");

if ($cc != "") {

$this->sock = FALSE;

if ($this->debug) {

$smtpserver = "smtp.tom.com";//SMTP服务器

$this->smtp_debug($message);

}

}

$this->log_file = "";

}

$smtpusermail = "[email protected]";//SMTP服务器的用户邮箱

$rcpt_to = $this->get_address($rcpt_to);

return $this->smtp_ok();

var $relay_host;

}

return TRUE;

if (!$this->smtp_putcmd("DATA")) {

function smtp_sockopen_relay()

var $sock;

return $this->smtp_error("sending HELO command");

}

function smtp_debug($message)

}

$this->log_write("Error: ".$errstr." (".$errno.")\n");

if ($arg != "") {

$this->time_out = 30; //is used in fsockopen()

return $this->smtp_error("sending RCPT TO command");

{

相关热词: 服务器 php 解决

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/server/yun/6084.shtml

最新文章
租用云服务器后的备案问 租用云服务器后的备案问

时间:2021-01-05

百度云服务器bcc有什么优 百度云服务器bcc有什么优

时间:2021-01-05

什么是云服务器cvm?怎么 什么是云服务器cvm?怎么

时间:2021-01-05

云服务器怎么保证信息安 云服务器怎么保证信息安

时间:2021-01-05

云服务器怎么预防被攻击 云服务器怎么预防被攻击

时间:2021-01-05

阿里云ECS实例设置用户r 阿里云ECS实例设置用户r

时间:2020-12-29

阿里云ECS服务器入门使用 阿里云ECS服务器入门使用

时间:2020-12-29

怎么配置云服务器 怎么配置云服务器

时间:2020-12-28

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

服务器_PHP的一个完整SMTP类(解决邮件服务器需要验证时的问题),smtp.php?phpclass smtp{/*

2020-12-20 编辑:

/*

{

{

}

$mailsubject = "Test Subject";//邮件主题

$this->smtp_port = $smtp_port;

continue;

#auth

$smtpserverport =25;//SMTP服务器端口

list($msec, $sec) = explode(" ", microtime());

test.php

{

return TRUE;

$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);

$smtp->debug = TRUE;//是否显示发送的调试信息

var $smtp_port;

$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";

}

/* Main Function */



$this->log_write("Connected to relay host ".$this->relay_host."\n");

function get_address($address)

$this->debug = FALSE;


function smtp_putcmd($cmd, $arg = "")

var $auth;

if ($bcc != "") {

if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {

var $host_name;

function smtp_message($header, $body)

function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")

}

$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");

$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);

$sent = FALSE;

}

}

return FALSE;

##########################################

$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);

{

return $this->smtp_error("sending MAIL FROM command");

$header .= "From: $from<".$from.">\r\n";

return TRUE;

$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");

}

{

var $time_out;

return $this->smtp_error("sending HELO command");

if (!($this->sock && $this->smtp_ok())) {

/* Private Functions */

$header .= "To: ".$to."\r\n";

$this->smtp_debug($response."\n");

return $address;

}

这是一个测试程序!!!

$address = ereg_replace("([ \t\r\n])+", "", $address);

fclose($fp);

{

$this->log_write("Disconnected from remote host\n");

fgets($this->sock, 512);

{

/* Constractor */

return FALSE;;

$this->log_write("Connected to mx host ".$host."\n");

$this->host_name = "localhost"; //is used in HELO command

?>

if (!$this->smtp_sockopen($rcpt_to)) {

return $this->smtp_error("sending message");

return TRUE;

function smtp_sockopen($address)

$this->relay_host = $relay_host;

{

}

return $this->smtp_error("sending HELO command");

$this->smtp_debug(". [EOM]\n");

$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.

$smtpuser = "someone";//SMTP服务器的用户帐号

}

$smtppass = "someonepass";//SMTP服务器的用户密码

}

function smtp_ok()

function log_write($message)

}

<?php

$this->smtp_debug("> ".$cmd."\n");

$header .= "Cc: ".$cc."\r\n";

#

?>

$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));

$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));

if (!$this->smtp_eom()) {

##########################################

}

$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");

$TO = explode(",", $this->strip_comment($to));

foreach ($TO as $rcpt_to) {

if (!@getmxrr($domain, $MXHOSTS)) {

if (!$this->smtp_message($header, $body)) {

{

}

$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);

require("sm.php");

$sent = FALSE;

function smtp_send($helo, $from, $to, $header, $body = "")

}

var $pass;

return $this->smtp_error("sending DATA command");

foreach ($MXHOSTS as $host) {

}

if ($this->log_file == "") {

}

#

}

return $this->smtp_ok();

}

}

while (ereg($comment, $address)) {

}

fputs($this->sock, $header."\r\n".$body);

$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");

return $this->smtp_sockopen_mx($address);

}

function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)

$mail_from = $this->get_address($this->strip_comment($from));

}

$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;

if($cmd=="") $cmd = $arg;

/* Public Variables */

}

if (!$this->smtp_putcmd("HELO", $helo)) {

fputs($this->sock, $cmd."\r\n");

if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {

$header .= "Content-Type:text/html\r\n";

$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");

$comment = "\([^()]*\)";

$header .= "Subject: ".$subject."\r\n";

$this->user = $user;

{

if (!ereg("^[23]", $response)) {

}

}

if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {

function strip_comment($address)

if (!$this->smtp_putcmd("QUIT")) {

}

if($this->auth){

fputs($fp, $message);

$this->log_write("Error: ".$errstr." (".$errno.")\n");

}

{

return TRUE;;

return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");

fclose($this->sock);

$smtpemailto = "[email protected]";//发送给谁

$header .= "MIME-Version:1.0\r\n";

$address = ereg_replace($comment, "", $address);

$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);

}

$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");

else $cmd = $cmd." ".$arg;

$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));

return FALSE;

{

{

$sent = TRUE;

}

return $this->smtp_error("sending QUIT command");

} else {

echo $message;

var $user;

}

if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {

$mailbody = "<h1>This is a test mail</h1>";//邮件内容

}

fputs($this->sock, "\r\n.\r\n");

}

var $log_file;

return FALSE;

$this->auth = $auth;//auth

}

$header .= $additional_headers;

return TRUE;

fputs($this->sock, "QUIT\r\n");

$this->log_write("Error: Error occurred while ".$string.".\n");

continue;


}

$this->pass = $pass;

}

if ($cc != "") {

return $sent;

}

$header .= "Date: ".date("r")."\r\n";

$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");

return FALSE;

} else {

$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件

function smtp_eom()

}

$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);

flock($fp, LOCK_EX);

function smtp_sockopen_mx($address)

$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";

if (!($this->sock && $this->smtp_ok())) {

if (log_file">!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {

#

if($mailtype=="HTML"){

if ($this->relay_host == "") {

function smtp_error($string)

if (!$this->smtp_putcmd("", base64_encode($this->pass))) {

}

*/

return FALSE;

请按照说明设置好以下的参数,以下是以tom.com的用户为例设置好的.

return $address;

$this->log_write("Warning: Cannot connect to mx host ".$host."\n");

{

return $this->smtp_sockopen_relay();

$response = str_replace("\r\n", "", fgets($this->sock, 512));

$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");

var $debug;

/* Private Variables */

return TRUE;

$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");

$this->log_write("Error: Remote host returned \"".$response."\"\n");

if ($cc != "") {

$this->sock = FALSE;

if ($this->debug) {

$smtpserver = "smtp.tom.com";//SMTP服务器

$this->smtp_debug($message);

}

}

$this->log_file = "";

}

$smtpusermail = "[email protected]";//SMTP服务器的用户邮箱

$rcpt_to = $this->get_address($rcpt_to);

return $this->smtp_ok();

var $relay_host;

}

return TRUE;

if (!$this->smtp_putcmd("DATA")) {

function smtp_sockopen_relay()

var $sock;

return $this->smtp_error("sending HELO command");

}

function smtp_debug($message)

}

$this->log_write("Error: ".$errstr." (".$errno.")\n");

if ($arg != "") {

$this->time_out = 30; //is used in fsockopen()

return $this->smtp_error("sending RCPT TO command");

{

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/server/yun/6084.shtml

相关文章

风云图片

推荐阅读

返回云服务器频道首页