PHP使用smtp发送邮件
1.下载需要文件
https://github.com/renyi666/sendMail.git
需要的文件是 class.smtp.php class.phpmailer.php
2.邮箱开启STMP服务
3.发送邮件相关程序配置
date_default_timezone_set('Asia/Shanghai');//设定时区东八区 require_once('class.phpmailer.php'); require_once('class.smtp.php'); $mail = new PHPMailer; $mail->SMTPDebug = 1; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = ' smtp.163.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'aaaaa'; // SMTP 发送者的邮箱 不需要带@ $mail->Password = 'bbbb'; // SMTP 以网易为例,这个密码是开启smtp之后的授权密码 $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; echo $mail->Host; // TCP port to connect to $mail->setFrom('aaaaa@163.com', 'Mailer'); //发送者的邮箱 // $mail->addAddress('714080794@qq.com', 'Joe User'); // Add a recipient $mail->addAddress('ccccc@qq.com'); // 接收者的邮箱 $mail->addReplyTo('aaaaa@163.com','Information'); //发送者的邮箱 $mail->isHTML(false); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = "思想得改正啊 得改正"; //发送的内容 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo ucwords('Message has been sent');}