目录
一、安装环境二、下载
三、 邮箱设置
四、php发送邮件
五、php框架中使用
一、安装环境
PHPMailer>
另外登录 QQ 邮箱 SMTP 服务器则必须通过 SSL 加密的, PHP 还得包含 openssl 的支持

二、下载
地址: https://github.com/PHPMailer/PHPMailer/

三、>
所有的主流邮箱都支持 SMTP 协议,但并非所有邮箱都默认开启
您可以在邮箱的设置里面手动开启
第三方服务在提供了账号和密码之后就可以登录 SMTP 服务器
通过它来控制邮件的中转方式
SMTP 服务器认证密码,需要妥善保管




四、php发送邮件
<?php >五、php框架中使用
先使用composer进行安装:composer>
使用
<?php use PHPMailerPHPMailerPHPMailer; use PHPMailerPHPMailerSMTP; use PHPMailerPHPMailerException; class mail { public function send() { //Create an instance; passing `true` enables exceptions $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_SERVER;WaQnwnL //Enable verbose debug output $mail->isSMTP(); //Send using SMTP $mail->Host = 'smtp.example.com'; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->Username = 'user@example.com'; //SMTP username $mail->Password = 'secret'; //SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` //Recipients $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('joe@example.net', 'Joe User'); //Add a rhttp://www.easck.comecipient $mail->addAddress('ellen@example.com'); //Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); //Attachments $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name //Content $mail->isHTML(true); //Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body in bold!'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } } }以上就是基于PHP实现邮件实时通知功能的详细内容,更多关于PHP邮件实时通知的www.easck.com资料请关注我们其它相关文章!







