PHP头条
热点:

PHP自动发邮件


自动发邮件 使用了这个类http://bbs.php100.com/read-htm-tid-121431.html

因他用的php版本较老,用到了函数ereg_replace() 和 ereg()


 

解决方法

1ereg_replace() 函数,替换为 strtr() 函数

语法不同点如下

 

详情http://www.php.net/manual/zh/function.ereg-replace.php

 

详情http://www.w3school.com.cn/php/func_string_strtr.asp

 

2ereg()  函数,替换为 preg_match() 函数

 

 链接http://blog.163.com/yanli_xu/blog/static/1363672912011420101820393/

preg_match() 函数语法http://www.php.net/manual/zh/function.preg-match.php

 

修改完毕后,完整代码如下

【邮件类】sm.class.php

<? smtp( = "", = 25, = ,, ->debug = ->smtp_port = ->relay_host = ->time_out = 30; ->auth = ; ->user = ->pass = ->host_name = "localhost"; ->log_file = "" ->sock = sendmail(, , = "", = "", , = "", = "", = "" = ->get_address(->strip_comment( = (, "(^|(\r\n))(\.)", "\1.\3" .= "MIME-Version:1.0\r\n" (=="HTML" .= "Content-Type:text/html\r\n" .= "To: ".."\r\n" ( != "" .= "Cc: ".."\r\n" .= "From: <"..">\r\n" .= "Subject: ".."\r\n" .= .= "Date: ".("r")."\r\n" .= "X-Mailer:By Redhat (PHP/".().")\r\n" (, ) = (" ", .= "Message-ID: <".("YmdHis", ).".".(*1000000)."."..">\r\n" = (",", ->strip_comment( ( != "" = (, (",", ->strip_comment( ( != "" = (, (",", ->strip_comment( = ( = ->get_address( (!->smtp_sockopen( ->log_write("Error: Cannot send email to ".."\n" = (->smtp_send(->host_name, , , , ->log_write("E-mail has been sent to <"..">\n" } ->log_write("Error: Cannot send email to <"..">\n" = (-> ->log_write("Disconnected from remote host\n" smtp_send(, , , , = "" (!->smtp_putcmd("HELO", ->smtp_error("sending HELO command" (-> (!->smtp_putcmd("AUTH LOGIN", (-> ->smtp_error("sending HELO command" (!->smtp_putcmd("", (-> ->smtp_error("sending HELO command" (!->smtp_putcmd("MAIL", "FROM:<"..">" ->smtp_error("sending MAIL FROM command" (!->smtp_putcmd("RCPT", "TO:<"..">" ->smtp_error("sending RCPT TO command" (!->smtp_putcmd("DATA" ->smtp_error("sending DATA command" (!->smtp_message(, ->smtp_error("sending message" (!-> ->smtp_error("sending <CR><LF>.<CR><LF> [EOM]" (!->smtp_putcmd("QUIT" ->smtp_error("sending QUIT command" smtp_sockopen( (->relay_host == "" ->smtp_sockopen_mx( } -> ->log_write("Trying to ".->relay_host.":".->smtp_port."\n" ->sock = @(->relay_host, ->smtp_port, , , -> (!(->sock && -> ->log_write("Error: Cannot connenct to relay host ".->relay_host."\n" ->log_write("Error: ".." ("..")\n" ->log_write("Connected to relay host ".->relay_host."\n" smtp_sockopen_mx( = (, "^.+@([^@]+)$", "\1" (!@getmxrr(, ->log_write("Error: Cannot resolve MX \"".."\"\n" ( ->log_write("Trying to "..":".->smtp_port."\n" ->sock = @(, ->smtp_port, , , -> (!(->sock && -> ->log_write("Warning: Cannot connect to mx host ".."\n" ->log_write("Error: ".." ("..")\n" ->log_write("Connected to mx host ".."\n" ->log_write("Error: Cannot connect to any mx hosts (".(", ", ).")\n" smtp_message(, (->sock, ."\r\n". ->smtp_debug("> ".("\r\n", "\n"."> ", ."\n> ".."\n> " (->sock, "\r\n.\r\n" ->smtp_debug(". [EOM]\n" -> = ("\r\n", "", (->sock, 512 ->smtp_debug(."\n" (!("/^[23]/", (->sock, "QUIT\r\n" (->sock, 512 ->log_write("Error: Remote host returned \"".."\"\n" smtp_putcmd(, = "" ( != "" (=="") = = ." ". (->sock, ."\r\n" ->smtp_debug("> ".."\n" -> smtp_error( ->log_write("Error: Error occurred while "..".\n" log_write( ->smtp_debug( (->log_file == "" = ("M d H:i:s ").()."[".()."]: ". (!@(->log_file) || !( = @(->log_file, "a" ->smtp_debug("Warning: Cannot open log file \"".->log_file."\"\n" (, (, ( strip_comment( = "/\([^()]*\)/" ((, = (, , "" get_address( = (, "([ \t\r\n])+", "" = (, "^.*<(.+)>.*$", "\1" smtp_debug( (-> ?> sm.class.php

 

【发邮件】sm.php

<? ("sm.class.php" = "smtp.qq.com"; =25; = "你的邮箱"; = "1477299439@qq.com"; = "你的账号"; = "你的密码"; = "项目提醒"; = "<h1>有新项目了</h1>"; = "HTML"; = smtp(,,,,); ->sendmail(, , , , ?> sm.php

 

www.phpzy.comtrue/php/5486.htmlTechArticlePHP自动发邮件 自动发邮件使用了这个类 http://bbs.php100.com/read-htm-tid-121431.html 因他用的php版本较老,用到了函数 ereg_replace () 和 ereg() 解决方法 1 ereg_replace()函数,替换为strtr()函数 语法不...

相关文章

相关频道:

PHP之友评论

今天推荐