函数名:imap_mail() 适用版本:PHP 4、PHP 5、PHP 7 用法:该函数用于发送一封电子邮件。它使用指定的邮件服务器和配置信息来发送邮件。 语法: bool imap_mail ( ...
函数名:imap_mail()
适用版本:PHP 4、PHP 5、PHP 7
用法:该函数用于发送一封电子邮件。它使用指定的邮件服务器和配置信息来发送邮件。
语法:
bool imap_mail ( string $to , string $subject , string $message [, string $additional_headers = NULL [, string $cc = NULL [, string $bcc = NULL [, string $rpath = NULL ]]]] )
参数:
返回值:成功发送邮件返回true,发送失败返回false。
示例:
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: reply@example.com\r\n";
$headers .= "Cc: cc@example.com\r\n";
$headers .= "Bcc: bcc@example.com\r\n";
if (imap_mail($to, $subject, $message, $headers)) {
echo "Email sent successfully.";
} else {
echo "Failed to send email.";
}
以上示例中,我们定义了收件人的地址($to),邮件的主题($subject),邮件的内容($message),以及附加的邮件头部信息($headers)。然后调用imap_mail()函数来发送邮件。如果邮件发送成功,输出"Email sent successfully.",否则输出"Failed to send email."。