PHP发送邮箱激活验证
第一步:php连接数据库:dbconnection.php<?php
$server = "(local)";
$_uid = "adweb";
$_pwd = "loveyou";
$_database = "addev";
function sqlsrv_connect( $server , $uid ,$pwd,$db ){
$connect_id= mssql_connect($server, $uid, $pwd);
//echo $connect_id ;
if($connect_id){
if (mssql_select_db($db,$connect_id))
return $connect_id ;
else
echo mssql_get_last_message() ;
}
else
echo mssql_get_last_message() ;
}
function sqlsrv_query($SQL,$conn ) {
returnmssql_query( $SQL ,$conn ) ;
}
function sqlsrv_num_rows($n) {
return mssql_num_rows($n) ;
}
function sqlsrv_fetch_array($n) {
returnmssql_fetch_array($n);
}
//调用函数,连接数据库
$conn = sqlsrv_connect( $server , $_uid ,$_pwd,$_database ) ;
?>
第二步:邮箱类email.class.php
<?
class smtp
{
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
var $sock;
function smtp($relay_host = "", $smtp_port = 25,$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 HELOcommand
$this->log_file ="";
$this->sock = FALSE;
}
function sendmail($to, $from, $subject = "", $body = "", $mailtype,$cc = "", $bcc = "", $additional_headers = "")
{
$mail_from =$this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\\.)", "\\1.\\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From:$from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis",$sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",",$this->strip_comment($cc)));
}
if ($bcc != "") {
$TO = array_merge($TO, explode(",",$this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if($this->smtp_send($this->host_name,$mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to<".$rcpt_to.">\n");
} else {
$this->log_write("Error: Cannot send email to<".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remotehost\n");
}
echo "<br>";
echo $header;
return $sent;
}
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELOcommand");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN",base64_encode($this->user))) {
return $this->smtp_error("sending HELOcommand");
}
if (!$this->smtp_putcmd("",base64_encode($this->pass))) {
return $this->smtp_error("sending HELOcommand");
}
}
#
if (!$this->smtp_putcmd("MAIL","FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROMcommand");
}
if (!$this->smtp_putcmd("RCPT","TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TOcommand");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATAcommand");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending<CR><LF>.<CR><LF>[EOM]");
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUITcommand");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to".$this->relay_host.":".$this->smtp_port."\n");
$this->sock =@fsockopen($this->relay_host,$this->smtp_port, $errno, $errstr,$this->time_out);
if (!($this->sock &&$this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relayhost ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr."(".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host".$this->relay_host."\n");
return TRUE;;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\\1", $address);
if (!@getmxrr($do
补充:Web开发 , php ,
- 更多php疑问解答:
- php使用imagick将image图片转化为字符串模式
- php通过gd实现图片图片转换为字符图代码
- PHP把图片转base64代码,php把base64代码转换为图片并保存
- PHP把图片base64转换成图片并保存成文件
- wordpress问题<?php if(have_posts()) : ?>
- 建设一个搜索类网站php还是jsp,数据库那个好
- 没理由啊 php代码无法执行,貌似有语法错误。。。
- 关于PHP 和API 的一段代码不懂啊不懂,请高手指点! 这是淘宝API的
- php语言中,序列化到底在那里使用?它的优势是什么?劣势是什么?
- PHP函数等于或等于应该怎么表达
- 请教php高手,解决basename函数和mb_substr函数处理中文文件名称的解决方法,在上传文件时,总是出现乱码
- .NET,PHP,JAVA,JS优秀点分别是?
- 织梦cms 在环境监测的时候 wamp5 gd不支持 是为什么。;extension=php_gd2.dll这一句我删除了还是不显示?
- 我想学PHP。1.应安装什么编程工具? 2. 装LIUNX系统是装简易的还是?什么版本的?3.还应安装什么?
- <?php 和 <? 有什么区别