使用 PHP 发送 QQ 邮件涉及以下几个基础概念:
以下是一个使用 PHPMailer 发送 QQ 邮件的示例代码:
<?php
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
// Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.qq.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'your-qq-email@qq.com'; // SMTP username
$mail->Password = 'your-qq-email-password'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
// Recipients
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('recipient@example.com', 'Joe User'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
通过以上步骤和示例代码,你应该能够成功使用 PHP 发送 QQ 邮件。如果遇到具体问题,可以根据错误信息进行进一步的排查和解决。
TVP技术闭门会
Elastic Meetup Online 第二期
云+社区技术沙龙[第6期]
开箱吧腾讯云
云+社区技术沙龙[第14期]
云+社区技术沙龙[第27期]
Elastic 实战工作坊
腾讯云“智能+互联网TechDay”
高校开发者
GAME-TECH
领取专属 10元无门槛券
手把手带您无忧上云