插件38:发送电子邮件

<?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格式发送,否则按文本发送

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值