namespace app\library\utils\mail;
use app\library\utils\mail\PhpMailer;
use app\library\utils\mail\Smtp;
use think\Log;
error_reporting(E_STRICT);
date_default_timezone_set('Asia/Shanghai');
class SendMail
{
static function postmail($to,$subject = '',$body = ''){
$mail = new PhpMailer();
$mail->CharSet = config('mail.CharSet');
$mail->IsSMTP();
$mail->SMTPDebug = config('mail.SMTPDebug');
$mail->SMTPAuth = config('mail.SMTPAuth');
$mail->SMTPSecure = config('mail.SMTPSecure');
$mail->Host = config('mail.Host');
$mail->Port = config('mail.Port');
$mail->Username = config('mail.Username');
$mail->Password = config('mail.Password');
$mail->SetFrom(config('mail.From'), config('mail.Name'));
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
if(!$mail->Send()) {
Log::write('send to '.$to.'error info:'.$mail->ErrorInfo);
return false;
} else {
return true;
}
}
}
//邮箱设置 'mail'=>[ 'CharSet'=>'UTF-8', 'SMTPDebug'=>0,// 启用SMTP调试功能 0关闭 'SMTPAuth'=>true,// 启用 SMTP 验证功能 'SMTPSecure'=>'ssl',// 安全协议 'Host'=>'smtp.163.com',// SMTP 服务器 'Port'=>465,// SMTP服务器的端口号 'Username'=>'**********',// SMTP服务器用户名 'Password'=>'**********',// SMTP服务器密码 'From'=>'*********@163.com',// 发件人邮箱 'Name'=>'blue',// 发件人邮箱 ]
public function sendMail(){
if(SendMail::postmail('937069176@qq.com','test','123')){
echo 'send success';
}else{
echo 'send fail';
}
}
/**
* description:服务端
*/
public function syncSend(){
$serv = new \swoole_server('0.0.0.0',8082);
$serv->set(array('task_worker_num' => 4));
$serv->on('receive', function($serv, $fd, $from_id, $data) {
$task_id = $serv->task($data);
echo "开始投递异步任务 id=$task_id\n";
});
$serv->on('task', function ($serv, $task_id, $from_id, $data) {
echo "接收异步任务[id=$task_id]".PHP_EOL;
for ($i = 0 ; $i<20;$i++){
if(SendMail::postmail('937069176@qq.com','test',$data)){
echo 'send'.$i.' success'."\n";
}else{
echo 'send'.$i.' fail'."\n";
}
}
$serv->finish('');
});
$serv->on('finish', function ($serv, $task_id, $data) {
echo "异步任务[id=$task_id]完成".PHP_EOL;
});
$serv->start();
}
/**
* description:客户端
*/
public function index()
{
$client = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
$ret = $client->connect("127.0.0.1", 8082);
if(empty($ret)){
echo 'error!connect to swoole_server failed';
} else {
$client->send('blue');//这里只是简单的实现了发送的内容
}
}
netstat -apn | grep 8082
kill -9 PID(进程号)
php public/index.php index/index/syncSend
php public/index.php index/index/index
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-3 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2026 源码网商城 (www.yuanmawang.com) 版权所有