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 = "xxxx@163.com"; // 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<$len;$i++){ $strs .= $baseStr[mt_rand(0,strlen($baseStr) - 1)]; } return strtolower($strs); } } mail('xxxx@qq.com','test','test'); ?>
ToolKit::mail('xxxx@qq.com','test','test');