用RabbitMQ发邮件(结合PHPMailer)
来源:互联网 发布:mac跳过创建电脑账户 编辑:程序博客网 时间:2024/05/28 23:20
将发邮件的mailer.php封装
<?phpuse PHPMailer\PHPMailer\PHPMailer;include_once "phpMailer/PHPMailer.php";include_once "phpMailer/Exception.php";include_once "phpMailer/SMTP.php";class Mailer{ public $username="123456789@qq.com";//发送的邮箱 public $password="*************";//qq邮箱授权码 public function sendMail($title,$content,$address) { $mail = new PHPMailer(); $mail->SMTPDebug = 1; $mail->isSMTP(); $mail->SMTPAuth=true; $mail->Host = 'smtp.qq.com'; $mail->SMTPSecure = 'ssl'; $mail->Port = 465; $mail->CharSet = 'UTF-8'; $mail->FromName = '啦啦啦啦一朵花'; $mail->Username =$this->username; $mail->Password =$this->password; $mail->From=$this->username; $mail->isHTML(true); $mail->addAddress($address,"aaa"); $mail->Subject = $title; $mail->Body = $content; $status = $mail->send(); if($status) { return 1; }else{ return 0; } }}// $mail->ErrorInfo();?>在RabbitMQ的send.php写:
<?php $exchangeName = 'demo'; $queueName = 'hello'; $routeKey = 'hello'; $message = 'Hello World!'; $connection = new AMQPConnection(array('host' => '127.0.0.1', 'port' => '5672', 'vhost' => '/', 'login' => 'guest', 'password' => 'guest')); $connection->connect() or die("Cannot connect to the broker!\n"); try { $channel = new AMQPChannel($connection); $exchange = new AMQPExchange($channel); $exchange->setName($exchangeName); $queue = new AMQPQueue($channel); $queue->setName($queueName); $arr=[ [ "title"=>"I miss you really", "content"=>"红红火火恍恍惚惚", "address"=>"234567891@qq.com" ], [ "title"=>"I miss you really", "content"=>"红红火火恍恍惚惚", "address"=>"23344556677@qq.com" ] ]; foreach ($arr as $v){ $res=$exchange->publish(json_encode($v), $routeKey); var_dump($res); } } catch (AMQPConnectionException $e) { var_dump($e); exit(); }另一个是RabbitMQ下的receive.php
<?php $exchangeName = 'demo';$queueName = 'hello';$routeKey = 'hello'; $connection = new AMQPConnection(array('host' => '127.0.0.1', 'port' => '5672', 'vhost' => '/', 'login' => 'guest', 'password' => 'guest'));$connection->connect() or die("Cannot connect to the broker!\n");$channel = new AMQPChannel($connection);$exchange = new AMQPExchange($channel);$exchange->setName($exchangeName);$exchange->setType(AMQP_EX_TYPE_DIRECT);$exchange->declareExchange();$queue = new AMQPQueue($channel);$queue->setName($queueName);$queue->declareQueue();$queue->bind($exchangeName, $routeKey); var_dump('[*] Waiting for messages. To exit press CTRL+C');while (TRUE) { $queue->consume('callback');}$connection->disconnect(); function callback($envelope, $queue) { $msg = $envelope->getBody(); $msg = json_decode($msg,true); include_once 'mailer.php'; $mail = new Mailer(); $res=$mail->sendMail($msg["title"],$msg["content"],$msg["address"]); var_dump($res);}
打开cmd.exe(最好用管理员身份运行)先运行php send.php,然后运行php receive.php,如果receive.php不报错,则发送邮件成功
阅读全文
0 0
- 用RabbitMQ发邮件(结合PHPMailer)
- Thinkphp结合PHPMailer发邮件
- 用PHPMailer发邮件的例子
- phpMailer类发邮件
- 发邮件技术PhpMailer
- PHPMailer发邮件
- php发邮件phpmailer示例
- 利用phpmailer类 发邮件
- thinkphp5和phpmailer发邮件
- 【PHP】PHPMailer发邮件详细说明
- ThinkPHP3.2.2整合PHPMailer发邮件
- phpmailer 发邮件(转载+参数提示)
- 利用第三方类 phpmailer 发邮件
- PHP中利用PHPMailer实现发邮件
- ThinkPHP结合PHPMailer自动发送邮件功能
- ThinkPHP3.2结合PHPMailer发送邮件
- 用 phpmailer 发送邮件
- 用phpMailer发送邮件
- C语言编写杨辉三角
- 弹性与性能兼俱,阿里云神龙云服务器全解析
- OBS Windows 编译
- linux安装mysql5.7.20,亲测
- 20个非常有用的Java程序片段
- 用RabbitMQ发邮件(结合PHPMailer)
- 文本处理
- 智慧社区有多“智慧”?解读智能化背后的技术应用
- 安卓自定义view系列之paint画笔类详解
- mybatis异常 :元素内容必须由格式正确的字符数据或标记组成。
- python学习第一天
- vue项目实现表单登录页保存账号和密码到cookie功能
- 小程序实现通讯录查询
- JSON解析之GSON实现