Home >Backend Development >PHP Tutorial >Recommended information for php+mysql to simulate queue sending emails
The "php+mysql simulated queue to send emails" course mainly solves the common problem of the page getting stuck when sending multiple emails during the PHP development process. If you need to send a system notification email to all users of the website, assume that the website has There are 10,000 registered users. It takes 0.1 seconds to send each email. Send it directly? NO, of course you need to use a queue. Why? You’ll know after you learn it!
Course playback address: //m.sbmmt.com/course/260.html
The teacher’s teaching style:
The teacher’s lectures are simple, clear, layer-by-layer analysis, interlocking, rigorous argumentation, rigorous structure, and use the logical power of thinking to attract students’ attention Strength, use reason to control the classroom teaching process. By listening to the teacher's lectures, students not only learn knowledge, but also receive thinking training, and are also influenced and influenced by the teacher's rigorous academic attitude
The more difficult point in this video is that phpmailer sends emails:
PHPMailer is an encapsulated PHP mail sending class that supports sending emails with HTML content and image attachments. The prerequisite is to set up the mail server to realize the mail sending function.
HTML
First we place an inbox input box and a send email button:
收件人:<input type="text" class="input_text" id="email" name="email" value="@"/> <input type="button" class="btn" id="send" value="发送"/>
jQuery
$(function() { $("#send").click(function() { var email = $("#email").val(); $("#send").addClass("loading").val("loading...").attr("disabled", "disabled"); $.post("ajax.php", { "email": email }, function(data) { if (data == 1) { $("#result").html("发送成功,请注意查收您的邮件!"); } else { $("#result").html(data); } $("#send").removeAttr("disabled").removeClass("loading").val("发送"); }); }); });
Ajax.php
require_once('class.phpmailer.php'); $address = $_POST['email']; //收件人email $mail = new PHPMailer(); //实例化 $mail->IsSMTP(); // 启用SMTP $mail->Host = "smtp.163.com"; //SMTP服务器 以163邮箱为例子 $mail->Port = 25; //邮件发送端口 $mail->SMTPAuth = true; //启用SMTP认证 $mail->CharSet = "UTF-8"; //字符集 $mail->Encoding = "base64"; //编码方式 $email_system = "qiumusua@163.com"; $mail->Username = $email_system; //你的邮箱 $mail->Password = ""; //你的密码 $mail->Subject = "你好"; //邮件标题 $mail->From = $email_system; //发件人地址(也就是你的邮箱) $mail->FromName = "素材火"; //发件人姓名 $mail->AddAddress($address, "亲"); //添加收件人(地址,昵称) $mail->AddAttachment('send.xls', '我的附件.xls'); // 添加附件,并指定名称 $mail->IsHTML(true); //支持html格式内容 $mail->AddEmbeddedImage("logo.jpg", "my-attach", "logo.jpg"); //设置邮件中的图片 $mail->Body = '你好, <b>朋友</b>! <br/>这是一封来自<a href="http://www.erdangjiade.com" target="_blank">erdangjiade.com</a>的邮件!<br/> <img alt="erdangjiade" src="cid:my-attach">'; //邮件主体内容 //发送 if (!$mail->Send()) { echo "发送失败: " . $mail->ErrorInfo; } else { echo "1"; }
The above is the detailed content of Recommended information for php+mysql to simulate queue sending emails. For more information, please follow other related articles on the PHP Chinese website!