以下是使用PHP创建邮件列表并发送电子邮件的步骤:
在PHP中,我们可以使用数组来存储我们的邮件列表。以下是一个示例数组:
$emails = array(
"email1@example.com",
"email2@example.com",
"email3@example.com"
);
我们需要设置电子邮件的主题和正文。以下是示例代码:
$subject = "这是电子邮件的主题";
$message = "这是电子邮件的正文。";
请注意,您可以在正文中使用HTML标记。
我们需要设置电子邮件头,其中包括发件人和收件人等信息。以下是示例代码:
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= "CC: cc@example.com\r\n";
$headers .= "BCC: bcc@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
请注意,我们在此示例中使用了MIME类型和HTML编码。这将允许我们在电子邮件正文中使用HTML标记。
最后,我们需要使用PHP的mail()函数发送电子邮件。以下是示例代码:
foreach ($emails as $email) {
mail($email, $subject, $message, $headers);
}
此代码将遍历我们的邮件列表,并为每个电子邮件地址发送电子邮件。
完整的PHP代码示例如下:
$emails = array(
"email1@example.com",
"email2@example.com",
"email3@example.com"
);
$subject = "这是电子邮件的主题";
$message = "这是电子邮件的正文。";
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= "CC: cc@example.com\r\n";
$headers .= "BCC: bcc@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
foreach ($emails as $email) {
mail($email, $subject, $message, $headers);
}