Swift Mailer is an object-oriented PHP email sending package that does not rely on PHP's own mail() function, because this function takes up a lot of system resources when sending multiple emails. Swift communicates directly with the SMTP server, with very high sending speed and efficiency.
Steps:
1. Of course, download the Swift library, please give a link;
2. Confirm that the email address you want to use has enabled SMTP service;
3. The password required below is generally not the email password, but the authorization code provided by your email service provider.
Example:
<code><span>function</span> sendMail() { <span>require</span><span>'path/to/swift_required.php'</span>); $transport=\<span>Swift_SmtpTransport</span>::newInstance<span><span>(<span>"邮件服务器地址"</span>,<span>"端口号"</span>,<span>"加密方式(例如:使用腾讯qq邮箱时此处填ssl,不加密不填写此项)"</span>)</span>-></span>setUsername<span><span>(<span>"用户名"</span>)</span>-></span>setPassword(<span>"密码"</span>); $mailer =\<span>Swift_Mailer</span>::newInstance($transport); $message=\<span>Swift_Message</span>::newInstance<span><span>()</span>-></span>setSubject<span><span>(<span>"邮件主题"</span>)</span>-></span>setFrom<span><span>(array(<span>"邮件来自邮箱号"</span>=><span>"邮件来自名称"</span>))</span>-></span>setTo<span><span>(<span>"收件人邮箱"</span>)</span>)-></span>setContentType<span><span>(<span>"text/html"</span>)</span>-></span>setBody(<span>"邮件内容"</span>); $mailer->protocol=<span>'smtp'</span>; $mailer->send($message); } }</code>
The above introduces the use of the PHP Swift Mailer library, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.