-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
27 lines (20 loc) · 888 Bytes
/
server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
require './vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
//参数说明:($host, $port, $user, $password, $vhost, $insist, $login_method, $login_response, $locale, $connection_timeout)
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
//初始化channel
$channel = $connection->channel();
//参数:$queue, $passive, $durable, $exclusive, $auto_delete, $nowait, $arguments, $ticket
$channel->queue_declare('sendEmail', false, false, false, false);
$emails = ['yourname@qq.com', 'yourname@163.com', 'yourname@163.com'];
foreach ($emails as $email) {
$msg = new AMQPMessage($email . '|' . '内容:这是一个测试邮件。');
$channel->basic_publish($msg, '', 'sendEmail');
echo " [x] Sent email OK.\n";
//sleep(1);
}
//关闭
$channel->close();
$connection->close();