📅  最后修改于: 2023-12-03 15:21:13.002000             🧑  作者: Mango
PHPMailer 是一个流行的 PHP 库,用于发送电子邮件。它使用 SMTP 协议来发送电子邮件,因此在使用它之前需要进行配置。在 WordPress 中,可以通过配置 PHPMailer 来发送电子邮件。
要使用 PHPMailer,请按照以下步骤操作:
下载最新版本的 PHPMailer(可以从 https://github.com/PHPMailer/PHPMailer 获取)。
在 WordPress 中创建一个新的 PHP 文件,并将以下代码复制到该文件中:
<?php
// Include PHPMailer library
require_once '/path/to/phpmailer/PHPMailerAutoload.php';
// Create a new PHPMailer instance
$mail = new PHPMailer;
// Set the default sender
$mail->setFrom('sender@example.com', 'Sender Name');
// Set the recipient(s)
$mail->addAddress('recipient@example.com');
// Set the email subject
$mail->Subject = 'PHPMailer Test';
// Set the email body
$mail->Body = 'This is a test email sent using PHPMailer';
// Send the email
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
请注意,您需要将“/path/to/phpmailer/”替换为您下载的 PHPMailer 的实际路径。
修改设置以适应您的需求。例如,您可以更改发件人的电子邮件地址,设置多个收件人,添加附件等。
保存并运行文件,在浏览器中打开该文件。如果一切正常,您应该会看到“Message has been sent.”输出。
PHPMailer 是一个功能强大的库,可用于发送各种类型的电子邮件。以下是一些常用的 PHPMailer 配置选项:
// Set the SMTP host
$mail->Host = 'smtp.example.com';
// Set SMTP authentication parameters
$mail->SMTPAuth = true;
$mail->Username = 'username@example.com';
$mail->Password = 'password';
// Set SMTP encryption
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Set the email body as HTML
$mail->isHTML(true);
// Set the email body
$mail->Body = '<h1>Hello World!</h1>';
// Add attachment file(s)
$mail->addAttachment('/path/to/file1.pdf');
$mail->addAttachment('/path/to/file2.zip');
PHPMailer 是一个流行的 PHP 库,可用于发送电子邮件。在 WordPress 中,可以使用 PHPMailer 来发送电子邮件,并进行各种配置以满足您的需求。希望这篇文章对您有所帮助,祝您好运!