<?php // Plug-in 38: Send Email
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
$message = "Hello Fred, I hadn't heard from you recently and " .
"thought I'd send you a quick note to see how you " .
"are keeping. - Rick";
$subject = "How are you?";
echo "Sending <i>'$message'</i>: ";
if (PIPHP_SendEmail($message, $subject, '', 'me@myserver.com',
'', 'rick@otherserver.net', NULL, NULL, ''))
echo "Mail successful";
else echo "Mail failed";
function PIPHP_SendEmail($message, $subject, $priority, $from,
$replyto, $to, $cc, $bcc, $type)
{
// Plug-in 38: Send Email
//
// This plug-in sends an email to one or more recipients.
// It returns TRUE on success, otherwise FALSE. The
// arguments required are:
//
// $message: The message to send - required
// $subject: The message's subject - required
// $priority: The message's priority: 1 (high) - 5 (low),
// or leave blank for none
// $from: The sender's email address - required
// $replyto: The address for replies. This can be set
// to NULL or "" if replies should be returned
// to the sender.
// $to: The recipient's email address - required
// $cc: An array of email addresses to send copies
// to. Can be set to NULL.
// $bcc: An array of email addresses to send hidden
// copies to. Can be set to NULL.
// $type: If set to HTML then the message is sent as
// HTML.
$headers = "From: $from\r\n";
if (strtolower($type) == "html")
{
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
}
if ($priority > 0) $headers .= "X-Priority: $priority\r\n";
if ($replyto != "") $headers .= "Reply-To: $replyto\r\n";
if (count($cc))
{
$headers .= "Cc: ";
for ($j = 0 ; $j < count($cc) ; ++$j)
$headers .= $cc[$j] . ",";
$headers = substr($headers, 0, -1) . "\r\n";
}
if (count($bcc))
{
$headers .= "Bcc: ";
for ($j = 0 ; $j < count($bcc) ; ++$j)
$headers .= $bcc[$j] . ",";
$headers = substr($headers, 0, -1) . "\r\n";
}
return mail($to, $subject, $message, $headers);
}
?>
插件说明:插件接受一个电子邮件内容的字符串和一个表示主题的字符创,以及与邮件接受者有关的其他参数。具体参数如下:
$message 电子邮件内容
$subject 电子邮件的主题
$priority 电子邮件的优先级别,级别1最高,级别5最低,空表示没有优先级别。
$from 电子邮件发送者的地址
$replyto 电子邮件的回复地址
$to 电子邮件接受者的地址
$cc 数组,表示电子邮件抄送的地址列表
$bcc 数组,表示电子邮件密送的地址列表(任何电子邮件接受者无法从电子邮件信息中看到电子邮件密送的地址)
$type 电子邮件类型,它的值为“HTML"表示电子邮件通过HTML格式发送,否则按文本发送