首页 > 语言 > PHP > 正文

利用php中mail函数发送HTML邮件实例

2024-09-04 11:48:47
字体:大 中 小
来源:转载
供稿:网友

在php中自带了邮箱发送函数mail()我们可以直接使用此函数进行邮件发送,下面我来介绍一些常用的邮箱发送实例,最简单的就是mail函数了.

例,代码如下:

  1. <?php 
  2. function send_mail($from, $to, $subject, $message) 
  3. { 
  4.     if ($from == "") 
  5.     { 
  6.         $from = '回忆未来 <webmaster@s135.com>';//发件人地址 
  7.     }//开源软件:Vevb.com 
  8.     $headers = 'MIME-Version: 1.0' . "rn"; 
  9.     $headers .= 'Content-type: text/html; charset=gb2312' . "rn"; 
  10.     $headers .= 'From: ' . $from . "rn"; 
  11.     mail($to, $subject, $message, $headers); 
  12. } 
  13. ?> 

提示:要使用的程序是由 php.ini 文件中的配置设置定义的,邮件函数的行为受 php.ini 的影响,我们必须先配置才行.

名称          默认             描述      可更改

SMTP          "localhost"      Windows 专用:SMTP 服务器的 DNS 名称或 IP 地址。         PHP_INI_ALL

smtp_port     "25"            Windows 专用:SMTP 段口号。自 PHP 4.3 起可用。           PHP_INI_ALL

sendmail_from NULL             Windows 专用:规定从 PHP 发送的邮件中使用的 "from" 地址。PHP_INI_ALL

sendmail_path NULL             Unix 系统专用:规定sendmail 程序的路径(通常 /usr/sbin/sendmail 或 /usr/lib/sendmail) PHP_INI_SYSTEM

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表