Home > Article > Backend Development > PHP怎么发邮件
PHP如何发邮件?
sendMail.php中代码如下:
<?php include_once './lib/class.phpmailer.php'; class ToolKit { //发送邮件 public static function mail($to,$subject,$content){ $mail = new PHPMailer();//实例化phpmailer $address = $to;//接收邮件的邮箱 $mail->IsSMTP(); // 设置发送邮件的协议:SMTP $mail->Host = "email.163.com"; // 发送邮件的服务器 $mail->SMTPAuth = true; // 打开SMTP $mail->Username = "[email protected]"; // SMTP账户 /*在这里填上发信的账户和密码*/ $mail->Password = "xxxx"; // SMTP密码 $mail->From = ""; $mail->FromName = ""; $mail->AddAddress("$address", ""); $mail->CharSet = "UTF-8";//设置字符集编码 $mail->Subject = $subject; $mail->Body = $content;//邮件内容(可以是HTML邮件) $mail->AltBody = $content; return $mail->Send(); } //产生随机字符串(长度为$len,字母为小写) public static function random($len){ $baseStr = "abcdefghijklmnopqrstuvwxyz1234567890"; //mt_srand(); $strs=""; for($i=0;$i
ToolKit::mail([email protected]','test','test');<div class="clear"> </div>