调用方法:<?php
$smtp = new Smtp;
$smtp->smtp('smtp.qq.com'); //邮件发送服务器
$smtp->pors(25); //邮件服务器端口
$smtp->login( '369758482@qq.com'); //邮件服务器登录用户
$smtp->pass(2013); //邮件服务器登录密码
$smtp->mails( '1140714215@qq.com'); //邮件接收人
$smtp->from( '369758482@qq.com'); //邮件发送人
$smtp->come( 'baiyi1983000@163.com'); //接收邮件回复地址
$smtp->title('这是一封邮件测试地址邮件'); //邮件主题
$smtp->body('这是一封邮件测试内容邮件'); //邮件内容
echo $smtp->send(); //发送邮件并输出发送状态
?>
也可以这样调用:
$smtp = new Smtp;
echo $smtp->smtp('smtp.qq.com')->pors(25)->login( '369758482@qq.com')->pass(13979797582)->mails('1140714215@qq.com')->from('369758482@qq.com')->come('baiyi1983000@163.com')->title('这是一封邮件测试地址邮件')->body('这是一封邮件测试内容邮件')->send();
1 <?php 2 /* 3 SMTP发送邮件类 4 作者:伤心的歌 5 QQ:369758482 6 Email:369758482@qq.com 7 */ 8 class Smtp{ 9 private $Smtp = 'smtp.qq.com'; //邮件服务器 10 private $PORS = 25; //邮件服务器端口 11 private $LoginMail = ''; //邮件登陆用户账户 12 private $LoginPass = ''; //邮件登陆用户密码 13 private $MailTo = ''; //接受邮件用户 14 private $MailFrom = ''; //邮件发送人 15 private $MailCome = ''; //接受回复邮件账户 16 private $Title = '测试邮件主题'; //邮件主题 17 private $Body = '测试邮件内容'; //邮件主体内容 18 private $Mesg = '邮件发送成功'; //邮件发送结果 19 20 21 public function smtp( $Smtp = '' ){ $this -> Smtp = $Smtp; return $this; } 22 public function pors( $pors = 25 ){ $this -> PORS = $pors; return $this; } 23 public function login( $login = '' ) { $this -> LoginMail = $login; return $this; } 24 public function pass( $pass = '' ){ $this -> LoginPass = $pass; return $this; } 25 public function mails( $mail = '' ) { $this -> MailTo = $mail; return $this; } 26 public function from( $form = '' ) { $this -> MailFrom = $form; return $this; } 27 public function come( $come = '' ) { $this -> MailCome = $come; return $this; } 28 public function title( $title = '' ) { $this -> Title = $title; return $this; } 29 public function body( $body = '' ) { $this -> Body = $body; return $this; } 30 31 32 public function send(){ 33 $fp = @fsockopen( $this->Smtp, $this->PORS); 34 @set_socket_blocking($fp, true); 35 $Server = @fgets($fp, 512); 36 $this->Mesg = !preg_match('/^220/i', $Server) ? '邮件服务器连接失败' : $this->Mesg; 37 38 @fputs($fp, 'HELO phpsetmail' . "\r\n"); 39 $Server = @fgets($fp, 2000); 40 $this->Mesg = !preg_match('/^250/i', $Server) ? '与服务器会话失败' : $this->Mesg; 41 42 @fputs($fp, 'AUTH LOGIN' . "\r\n"); 43 $Server = @fgets($fp, 2000); 44 $this->Mesg = !preg_match('/^334/i', $Server) ? '请求与服务器进行用户验证失败' : $this->Mesg; 45 46 @fputs($fp, base64_encode( $this->LoginMail ) . "\r\n"); 47 $Server = @fgets($fp, 2000); 48 $this->Mesg = !preg_match('/^334/i', $Server) ? '用户验证失败' : $this->Mesg; 49 50 @fputs($fp, base64_encode( $this->LoginPass ) . "\r\n"); 51 $Server = @fgets($fp, 2000); 52 $this->Mesg = !preg_match('/^235/i', $Server) ? '用户验证失败' : $this->Mesg; 53 54 @fputs($fp, 'MAIL FROM:' . $this->LoginMail . "\r\n"); 55 $Server = @fgets($fp, 2000); 56 $this->Mesg = !preg_match('/^250/i', $Server) ? '发送用户验证失败' : $this->Mesg; 57 58 @fputs($fp, 'RCPT TO:' . $this->MailTo . "\r\n"); 59 $Server = @fgets($fp, 2000); 60 $this->Mesg = !preg_match('/^250/i', $Server) ? '接受用户名验证失败' : $this->Mesg; 61 62 @fputs($fp, 'DATA' . "\r\n"); 63 $Server = @fgets($fp, 2000); 64 $this->Mesg = !preg_match('/^354/i', $Server) ? '请求与服务器发送邮件数据失败' : $this->Mesg; 65 66 @fputs($fp, 'From:' . $this->MailCome ."\r\n"); 67 @fputs($fp, 'Subject:' . $this->Title . "\r\n"); 68 @fputs($fp, 'To:' . $this->MailTo . "\r\n"); 69 @fputs($fp, "\r\n"); 70 @fputs($fp, $this->Body . "\r\n"); 71 @fputs($fp, '.' . "\r\n"); 72 73 $Server = @fgets($fp, 2000); 74 $this->Mesg = !preg_match('/^250/i', $Server) ? '邮件发送失败' : $this->Mesg; 75 76 @@fputs($fp, 'QUIT' . "\r\n"); 77 @fclose($fp); 78 return $this->Mesg; 79 } 80 81 }