要使用PHP发送邮件,您可以使用PHP内置的mail函数。以下是使用mail函数发送邮件的示例代码:
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$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=ISO-8859-1\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "Email sent successfully.";
} else {
echo "Failed to send email.";
}
在上述代码中,您需要将recipient@example.com替换为实际的收件人电子邮件地址,sender@example.com替换为实际的发件人电子邮件地址,cc@example.com和bcc@example.com替换为实际的抄送和密送电子邮件地址。
请注意,这只是一个基本的示例,您可能需要根据您的实际需求进行更多的设置和配置,例如身份验证、附件等。
上一篇:php如何打开word
下一篇:php 数组倒叙排序
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站