-
StackOverflow 文档
-
PHP 教程
-
发送电子邮件
-
使用 PHPMailer 发送纯文本电子邮件
基本文字电邮
<?php
$mail = new PHPMailer();
$mail->From = "from@example.com";
$mail->FromName = "Full Name";
$mail->addReplyTo("reply@example.com", "Reply Address");
$mail->Subject = "Subject Text";
$mail->Body = "This is a sample basic text email using PHPMailer.";
if($mail->send()) {
// Success! Redirect to a thank you page. Use the
// POST/REDIRECT/GET pattern to prevent form resubmissions
// when a user refreshes the page.
header('Location: http://example.com/path/to/thank-you.php', true, 303);
exit;
}
else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
添加附加收件人,CC 收件人,BCC 收件人
<?php
$mail = new PHPMailer();
$mail->From = "from@example.com";
$mail->FromName = "Full Name";
$mail->addReplyTo("reply@example.com", "Reply Address");
$mail->addAddress("recepient1@example.com", "Recepient Name");
$mail->addAddress("recepient2@example.com");
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");
$mail->Subject = "Subject Text";
$mail->Body = "This is a sample basic text email using PHPMailer.";
if($mail->send()) {
// Success! Redirect to a thank you page. Use the
// POST/REDIRECT/GET pattern to prevent form resubmissions
// when a user refreshes the page.
header('Location: http://example.com/path/to/thank-you.php', true, 303);
exit;
}
else {
echo "Error: " . $mail->ErrorInfo;
}