php fsockopen邮箱发送实例代码

 更新时间:2016年11月25日 17:01  点击:2289

php教程 fsockopen邮箱发送实例代码

<?
//ok的邮箱发送。
include "smtp.class.php";
//$smtps教程erver = "smtp.163.com"; //您的smtp服务器的地址
$smtpserver="smtp.163.com";
$port =25; //smtp服务器的端口,一般是 25
$smtpuser = "你的邮箱@163.com"; //您登录smtp服务器的用户名
$smtppwd = "你邮箱的密码"; //您登录smtp服务器的密码
$mailtype = "txt"; //邮件的类型,可选值是 txt 或 html ,txt 表示是纯文本的邮件,html 表示是 html格式的邮件
$sender = "你的邮箱@163.com";
//发件人,一般要与您登录smtp服务器的用户名($smtpuser)相同,否则可能会因为smtp服务器的设置导致发送失败
$smtp = new smtp($smtpserver,$port,true,$smtpuser,$smtppwd,$sender);
$smtp->debug = true; //是否开启调试,只在测试程序时使用,正式使用时请将此行注释
$to = "你要发给的那个人的邮箱地址"; //收件人
$subject = "你好";
$body = "你发送的内容 ";
$send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype);

if($send==1){
echo "邮件发送成功";
}else{
echo "邮件发送失败<br/>";
//echo "原因:".$this->smtp->logs;
}
?>

邮箱发送类smtp.class.php

<?php
class smtp
{
/* public variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* private variables */
var $sock;
/* constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = false;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
#
$this->host_name = "localhost"; //is used in helo command
$this->log_file = "";
$this->sock = false;
}
/* main function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(rn))(.)", "1.3", $body);
$header .= "mime-version:1.0rn";
if($mailtype=="html"){
$header .= "content-type:text/htmlrn";
}
$header .= "to: ".$to."rn";
if ($cc != "") {
$header .= "cc: ".$cc."rn";
}
$header .= "from: $from<".$from.">;rn";
$header .= "subject: ".$subject."rn";
$header .= $additional_headers;
$header .= "date: ".date("r")."rn";
$header .= "x-mailer:by redhat (php/".phpversion().")rn";
list($msec, $sec) = explode(" ", microtime());
$header .= "message-id: <".date("ymdhis", $sec).".".($msec*1000000).".".$mail_from.">;rn";
$to = explode(",", $this->strip_comment($to));
if ($cc != "") {
$to = array_merge($to, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "") {
$to = array_merge($to, explode(",", $this->strip_comment($bcc)));
}
$sent = true;
foreach ($to as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("error: cannot send email to ".$rcpt_to."n");
$sent = false;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("e-mail has been sent to <".$rcpt_to.">;n");
} else {
$this->log_write("error: cannot send email to <".$rcpt_to.">;n");
$sent = false;
}
fclose($this->sock);
$this->log_write("disconnected from remote hostn");
}
return $sent;
}
/* private functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("helo", $helo)) {
return $this->smtp_error("sending helo command");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("auth login", base64_encode($this->user))) {
return $this->smtp_error("sending helo command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending helo command");
}
}
#
if (!$this->smtp_putcmd("mail", "from:<".$from.">;")) {
return $this->smtp_error("sending mail from command");
}
if (!$this->smtp_putcmd("rcpt", "to:<".$to.">;")) {
return $this->smtp_error("sending rcpt to command");
}
if (!$this->smtp_putcmd("data")) {
return $this->smtp_error("sending data command");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending <cr>;<lf>;.<cr>;<lf>; [eom]");
}
if (!$this->smtp_putcmd("quit")) {
return $this->smtp_error("sending quit command");
}
return true;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("trying to ".$this->relay_host.":".$this->smtp_port."n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("error: cannot connenct to relay host ".$this->relay_host."n");
$this->log_write("error: ".$errstr." (".$errno.")n");
return false;
}
$this->log_write("connected to relay host ".$this->relay_host."n");
return true;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "1", $address);
if (!@getmxrr($domain, $mxhosts)) {
$this->log_write("error: cannot resolve mx "".$domain.""n");
return false;
}
foreach ($mxhosts as $host) {
$this->log_write("trying to ".$host.":".$this->smtp_port."n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("warning: cannot connect to mx host ".$host."n");
$this->log_write("error: ".$errstr." (".$errno.")n");
continue;
}
$this->log_write("connected to mx host ".$host."n");
return true;
}
$this->log_write("error: cannot connect to any mx hosts (".implode(", ", $mxhosts).")n");
return false;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."rn".$body);
$this->smtp_debug(">; ".str_replace("rn", "n".">; ", $header."n>; ".$body."n>; "));
return true;
}
function smtp_eom()
{
fputs($this->sock, "rn.rn");
$this->smtp_debug(". [eom]n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("rn", "", fgets($this->sock, 512));
$this->smtp_debug($response."n");
if (!ereg("^[23]", $response)) {
fputs($this->sock, "quitrn");
fgets($this->sock, 512);
$this->log_write("error: remote host returned "".$response.""n");
return false;
}
return true;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."rn");
$this->smtp_debug(">; ".$cmd."n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("error: error occurred while ".$string.".n");
return false;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "") {
return true;
}
$message = date("m d h:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("warning: cannot open log file "".$this->log_file.""n");
return false;
}
flock($fp, lock_ex);
fputs($fp, $message);
fclose($fp);
return true;
}
function strip_comment($address)
{
$comment = "([^()]*)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ trn])+", "", $address);
$address = ereg_replace("^.*<(.+)>;.*$", "1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug) {
echo $message;
}
}
}
function sendmail($smtpserver,$smtpuser,$smtppass,$smtpemailto,$smtpusermail, $mailsubject, $mailbody){
$smtp = new smtp($smtpserver,25,true,$smtpuser,$smtppass);
//$smtp->debug = true;
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, "html");
}
//such as
//sendmail("smtp.126.com","test@126.com","password","1034555083@qq.com","test@126.com","title","body");
?>

更多关于fsockopen函数请查看

http://www.111cn.net/phper/php-function/33796.htm

下面是一款婚恋网站的邮箱发送实例代码,有需要的朋友可以下载

<?php教程
//if ($err) {echo "发送邮件失败,原因:<br>";foreach($err as $a){echo $a."<br>";}}

class wrzc_netmail {
/*  var $localhost;
 var $smtp_accname;
 var $smtp_password;
 var $smtp_host;
 var $from;
 var $fromname;
 */ function send($to, $subject = 'no subject', $body) {
 $localhost = $this->localhost;
 $smtp_accname = $this->smtp_accname;
 $smtp_password = $this->smtp_password;
 $smtp_host = $this->smtp_host;
 $from = $this->from;
 $fromname = $this->fromname;
 $lb = "rn";
 $headers = "content-type: text/html;charset="gbk"";
 $headers.= $lb;
 $headers.= "content-transfer-encoding: base64";
 $hdr = explode($lb, $headers);
 if ($body) {
 $bdy = preg_replace("/^./", "..", explode($lb, $body));}
 $smtp[] = array("ehlo ".$localhost.$lb, "220,250", "ehlo error: ");
 $smtp[] = array("auth login".$lb, "334", "auth error: ");
 $smtp[] = array(base64_encode($smtp_accname).$lb, "334", "authentification error: ");
 $smtp[] = array(base64_encode($smtp_password).$lb, "235", "authentification error: ");
 $smtp[] = array("mail from: <".$from.">".$lb, "250", "mail from error: ");
 $smtp[] = array("rcpt to: <".$to.">".$lb, "250", "rcpt to error: ");
 $smtp[] = array("data".$lb, "354", "data error: ");
 $smtp[] = array("from: ".$fromname." <".$from.">".$lb, "", "");
 $smtp[] = array("subject: ".$subject.$lb, "", "");
 $smtp[] = array("to: ".$to.$lb, "", "");
 foreach ($hdr as $h) {
 $smtp[] = array($h.$lb, "", "");}
 $smtp[] = array($lb, "", "");
 if ($bdy) {
 foreach ($bdy as $b) {
 $smtp[] = array(base64_encode($b.$lb).$lb, "", "");}}
 $smtp[] = array(".".$lb, "250", "data(end)error: ");
 $smtp[] = array("quit".$lb, "221", "quit error: ");
 $fp = @fsockopen($smtp_host, 25);
 if (!$fp)
 return "error: cannot conect to '".$smtp_host."' by port 25";
 while ($result = @fgets($fp, 1024)) {
 if (substr($result, 3, 1) == " ") {
 break;}}
 $result_str;
 foreach ($smtp as $req) {
 @fputs($fp, $req[0]);
 if ($req[1]) {
 while ($result = @fgets($fp, 1024)) {
 if (substr($result, 3, 1) == " ") {
 break;}};
 if (!strstr($req[1], substr($result, 0, 3))) {
 $result_str[] = $req[2].$result;}}}
 @fclose($fp);
 return $result_str;}
 function setlocalhost($localhost) {$this->localhost = $localhost;}
 function setsmtp_accname($smtp_accname) {$this->smtp_accname = $smtp_accname;}
 function setsmtp_password($smtp_password) {$this->smtp_password = $smtp_password;}
 function setsmtp_host($smtp_host) {$this->smtp_host = $smtp_host;}
 function setfrom($from) {$this->from = $from;}
 function setfromname($fromname) {$this->fromname = $fromname;}
}
//unset
?>

/*邮件发送类
*功能:php教程 socket 使用smtp服务器发送邮件
*作者:longlong
*时间:2007-11-26
*转帖请加本贴引用地址:showpost.asp教程?threadid=1345 
*/
class smtp
{
/* 全局变量 */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;

/* private variables */ 
var $sock;

/* 构造函数 */

function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
  $this->debug = false;
  $this->smtp_port = $smtp_port;
  $this->relay_host = $relay_host;
  $this->time_out = 30; //is used in fsockopen() 
   
  #

  $this->auth = $auth;//auth
  $this->user = $user;
  $this->pass = $pass;
   
  #

  $this->host_name = "localhost"; //is used in helo command 
  $this->log_file = "";


  $this->sock = false;
}

/* 主函数,发送邮件 */

function sendmail($flag, $boundary, $to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
  $mail_from = $this->get_address($this->strip_comment($from));
  $body = ereg_replace("(^|(rn))(.)", "1.3", $body);
  $header = "mime-version:1.0rn";
   
  //*
  if($mailtype=="html"){
  //echo $boundary;exit;
if($flag==2)
{
  $header .= "content-type:multipart/mixed; boundary= $boundaryrn";
  //$header .= "content-type:text/htmlrn";
}
else

  $header .= "content-type:text/htmlrn";
}
  }
  //*/

  $header .= "to: ".$to."rn";

  if ($cc != "") {
  $header .= "cc: ".$cc."rn";
  }

  $header .= "from: $from<".$from.">rn";
  $header .= "subject: ".$subject."rn";
  $header .= $additional_headers;
  $header .= "date: ".date("r")."rn";
  $header .= "x-mailer:by redhat (php/".phpversion().")rn";

  //$header.=$body;//edit by shaolong
  
  list($msec, $sec) = explode(" ", microtime());

  $header .= "message-id: <".date("ymdhis", $sec).".".($msec*1000000).".".$mail_from.">rn";

  $to = explode(",", $this->strip_comment($to));

  if ($cc != "") {
  $to = array_merge($to, explode(",", $this->strip_comment($cc)));
  }


  if ($bcc != "") {
  $to = array_merge($to, explode(",", $this->strip_comment($bcc)));
  }

  $sent = true;

  foreach ($to as $rcpt_to) {
  $rcpt_to = $this->get_address($rcpt_to);
   
  if (!$this->smtp_sockopen($rcpt_to)) {
  $this->log_write("error: cannot send email to ".$rcpt_to."n");
  $sent = false;
  continue;
  }

  if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
  $this->log_write("e-mail has been sent to <".$rcpt_to.">n");
  } else {
  $this->log_write("error: cannot send email to <".$rcpt_to.">n");
  $sent = false;
  }

  fclose($this->sock);

  $this->log_write("disconnected from remote hostn");
  }
  return $sent;
}

/* 私有函数 */

function smtp_send($helo, $from, $to, $header, $body = "")
{
  if (!$this->smtp_putcmd("helo", $helo)) {

  return $this->smtp_error("sending helo command");
  }

  #auth

  if($this->auth){
  if (!$this->smtp_putcmd("auth login", base64_encode($this->user))) {
  return $this->smtp_error("sending helo command");
  }

  if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
  return $this->smtp_error("sending helo command");
  }
  }

  #

  if (!$this->smtp_putcmd("mail", "from:<".$from.">")) {
  return $this->smtp_error("sending mail from command");
  }

  if (!$this->smtp_putcmd("rcpt", "to:<".$to.">")) {
  return $this->smtp_error("sending rcpt to command");
  }

  if (!$this->smtp_putcmd("data")) {
  return $this->smtp_error("sending data command");
  }

  if (!$this->smtp_message($header, $body)) {
  return $this->smtp_error("sending message");
  }


  if (!$this->smtp_eom()) {
  return $this->smtp_error("sending <cr><lf>.<cr><lf> [eom]");
  }


  if (!$this->smtp_putcmd("quit")) {
  return $this->smtp_error("sending quit command");
  }
  return true;
}


function smtp_sockopen($address)
{
  if ($this->relay_host == "") {

  return $this->smtp_sockopen_mx($address);

  } else {
  return $this->smtp_sockopen_relay();
  }
}


function smtp_sockopen_relay()
{
  $this->log_write("trying to ".$this->relay_host.":".$this->smtp_port."n");

  $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);

  if (!($this->sock && $this->smtp_ok())) {

  $this->log_write("error: cannot connenct to relay host ".$this->relay_host."n");

  $this->log_write("error: ".$errstr." (".$errno.")n");

  return false;
  }
  $this->log_write("connected to relay host ".$this->relay_host."n");
  return true;


function smtp_sockopen_mx($address)
{
  $domain = ereg_replace("^.+@([^@]+)$", "1", $address);
  if (!@getmxrr($domain, $mxhosts)) {
  $this->log_write("error: cannot resolve mx "".$domain.""n");
  return false;
  }

  foreach ($mxhosts as $host) {
  $this->log_write("trying to ".$host.":".$this->smtp_port."n");

  $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);

  if (!($this->sock && $this->smtp_ok())) {
  $this->log_write("warning: cannot connect to mx host ".$host."n");
  $this->log_write("error: ".$errstr." (".$errno.")n");
  continue;
  }

  $this->log_write("connected to mx host ".$host."n");
  return true;
  }

  $this->log_write("error: cannot connect to any mx hosts (".implode(", ", $mxhosts).")n");
  return false;
}


function smtp_message($header, $body)
{
  fputs($this->sock, $header."rn".$body);
  $this->smtp_debug("> ".str_replace("rn", "n"."> ", $header."n> ".$body."n> "));
  return true;
}


function smtp_eom()
{
  fputs($this->sock, "rn.rn");

  $this->smtp_debug(". [eom]n");

  return $this->smtp_ok();
}


function smtp_ok()
{
  $response = str_replace("rn", "", fgets($this->sock, 512));
  $this->smtp_debug($response."n");

  if (!ereg("^[23]", $response)) {
  fputs($this->sock, "quitrn");
  fgets($this->sock, 512); 
  $this->log_write("error: remote host returned "".$response.""n");
  return false;

  }
  return true;
}


function smtp_putcmd($cmd, $arg = "")
{
  if ($arg != "") {
  if($cmd=="") $cmd = $arg;
  else $cmd = $cmd." ".$arg;
  }

  fputs($this->sock, $cmd."rn");
  $this->smtp_debug("> ".$cmd."n");
  return $this->smtp_ok();
}


function smtp_error($string)
{
  $this->log_write("error: error occurred while ".$string.".n");
  return false;
}


function log_write($message)
{
  $this->smtp_debug($message);
  if ($this->log_file == "") {

  return true;
  }

  $message = date("m d h:i:s ").get_current_user()."[".getmypid()."]: ".$message;
  if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
  $this->smtp_debug("warning: cannot open log file "".$this->log_file.""n");
  return false;;
  }

  flock($fp, lock_ex);
  fputs($fp, $message);
  fclose($fp);
  return true;
}

function strip_comment($address)
{
  $comment = "([^()]*)";
  while (ereg($comment, $address)) {
  $address = ereg_replace($comment, "", $address);
  }
  return $address;
}

function get_address($address)
{
  $address = ereg_replace("([ trn])+", "", $address);
  $address = ereg_replace("^.*<(.+)>.*$", "1", $address);
  return $address;
}


function smtp_debug($message)
{
  if ($this->debug) {
  echo $message;
  }
}
}

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>php发送邮件</title>
</head>

<body>
<table width="611" height="200" border="1">
  <tr>
    <td width="601"><form id="form1" name="form1" method="post" action="send.php">
      <table width="600" height="240" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="102" height="28">收件人地址</td>
          <td width="213"><input name="to" type="text" id="to" /></td>
          <td width="84">发送人地址</td>
          <td width="201"><input name="from" type="text" id="from" value="cert@163.com" /></td>
        </tr>
        <tr>
          <td height="33">发送人用户名</td>
          <td><input name="name" type="text" id="username" value="cert" /></td>
          <td>邮箱密码</td>
          <td><input name="password" type="password" id="password" value="***" /></td>
        </tr>
        <tr>
          <td height="27">smtp服务器</td>
          <td><input name="smtp" type="text" id="smtp" value="smtp.163.com" /></td>
          <td colspan="2">注:163邮箱smtp为: smtp.163.com</td>
          </tr>
        <tr>
          <td height="26">标题</td>
          <td colspan="3"><input name="subject" type="text" id="subject" value="cert测试php发送邮件" size="50" /></td>
          </tr>
        <tr>
          <td height="69">内容</td>
          <td colspan="3"><textarea name="content" cols="50" rows="6" id="content">计算机紧急响应组欢迎你!
http://www.111cn.net
组织网站即将进行改版</textarea></td>
          </tr>
        <tr>
       
          <td>&nbsp;</td>
          <td align="right"><input type="submit" name="submit" value="发送" /></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
        <p>说明:我用163的邮箱发给 163 或 126 的邮箱立刻就能收到。大家试试。</p>
    </form>
    </td>
  </tr>
</table>
</body>
</html>

<?
require_once 'mail.php';

$conf['mail'] = array(
        'host'     => 'smtp.126.com',                  //smtp服务器地址
        'auth'     => true,                           //true表示smtp服务器需要验证,false不需要
        'username' => 'liangbowen',                   //用户名
        'password' => '******'                        //密码
);


//发送邮件
$headers['from']    = 'liangbowen@126.com';               //发信地址
$headers['to']      = 'liangbowen@hotmail.com';               //收信地址
$headers['subject'] = 'test mail send by php bowen.mvbb.com';   //邮件标题
$mail_object = &mail::factory('smtp', $conf['mail']);   
//邮件正文
$body = "这是一封自己发给自己的邮件。";

$mail_res = $mail_object->send($headers['to'], $headers, $body); //发送

                           
if(pear::iserror($mail_res)){      //检测错误
    die($mail_res->getmessage());
}
else{
 echo "send successful!";
}

源码下载

http://down.111cn.net/down/code/php/qitayuanma/2010/1220/22333.html

语法
mail(to,subject,message,headers,parameters)参数 描述
to 必需。规定 email 接收者。
subject 必需。规定 email 的主题。注释:该参数不能包含任何新行字符。
message 必需。定义要发送的消息。应使用 lf (n) 来分隔各行。
headers 可选。规定附加的标题,比如 from、cc 以及 bcc。

应当使用 crlf (rn) 分隔附加的标题。
 
parameters 可选。对邮件发送程序规定额外的参数。


*/
$to='nobody@example.com';        //定义邮箱地址
$subject='mail';           //定义发送邮件的主题
$message='hello,php';         //定义邮件主体内容
$headers='from:webmaster@example.com'."rn".
'reply-to:webmaster@example.com'."rn".
 'x-mailer:php/'.phpversion();        //定义附加信息
mail($to,$subject,$message,$headers);      //发送邮件
?>
<?php
//发送html格式的邮件例子
$to='test@example.com'.',';
$to.='test1@example.com';        //定义多个收件人地址
$subject='mailhtml';          //定义邮件标题
//下面是邮件的html代码
$message='
<html>
<head>
<title>birthday reminders for august</title>
</head>
<body>
<p>here are the birthdays upcoming in august!</p>
<table>
  <tr>
    <th>person</th><th>day</th><th>month</th><th>year</th>
  </tr>
  <tr>
    <td>joe</td><td>3rd</td><td>august</td><td>1970</td>
  </tr>
  <tr>
    <td>sally</td><td>17th</td><td>august</td><td>1973</td>
  </tr>
</table>
</body>
</html>
';
//发送http请求
$headers='mime-version:1.0'."rn";        //定义附加信息
$headers.='content-type:text/html;charset=iso-8856-1'."rn";
$headers.='to:mary<mary@example.com>,kelly<kelly@example.com>'."rn";
$headers.='from:birthday reminder<birthday@example.com>'."rn";
$headers.='cc:birthdayarchive@example.com'."rn";
$headers.='bcc:birthdaycheck@example.com'."rn";
mail($to,$subject,$message,$headers);       //执行发送操作

/*

注释:php 需要一个已安装且正在运行的邮件系统,以便使邮件函数可用。所用的程序通过在 php.ini 文件中的配置设置进行定义

*/

[!--infotagslink--]

相关文章

  • NodeJS实现阿里大鱼短信通知发送

    本文给大家介绍的是nodejs实现使用阿里大鱼短信API发送消息的方法和代码,有需要的小伙伴可以参考下。...2016-01-20
  • PHP测试成功的邮件发送案例

    mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
  • php邮件发送的两种方式

    这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<&#63;php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
  • c# 实现发送邮件的功能

    这篇文章主要介绍了c# 如何实现发送邮件的功能,文中示例代码非常详细,帮助大家更好的理解和学习,感兴趣的朋友可以了解下...2020-07-07
  • php邮件发送的两种方式

    这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<&#63;php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
  • python实现企业微信定时发送文本消息的实例代码

    这篇文章主要介绍了python实现企业微信定时发送文本消息的实例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-25
  • PHP测试成功的邮件发送案例

    mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
  • 比较正宗的验证邮箱的正则表达式js代码详解

    邮箱正则最正宗的一条正则语句是^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$ 下面我们来讲解一下...2021-05-07
  • PHP用户注册邮箱验证正则表达式方法

    邮箱验证使用正则是非常的简单了,我们这里整理了两种PHP用户注册邮箱验证正则表达式方法例子,希望此文章能够让各位有帮助. 这里可以使用到2种方法,一种是用preg_matc...2016-11-25
  • php中利用curl smtp发送邮件实例

    本文章来介绍人一下关于与我们不同的发送邮件的方法我们来利用php curl stmp来实现邮件的发送程序。 $ telnet 邮箱SMTP服务地址 25 Trying 邮箱服务IP地址......2016-11-25
  • Python基于httpx模块实现发送请求

    这篇文章主要介绍了Python基于httpx模块实现发送请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-08
  • node.js 基于 STMP 协议和 EWS 协议发送邮件

    这篇文章主要介绍了node.js 基于 STMP 协议和 EWS 协议发送邮件的示例,帮助大家更好的理解和使用node.js,感兴趣的朋友可以了解下...2021-02-15
  • php定时发送邮件

    <?php // 请求 PHPmailer类 文件 require_once("class.phpmailer.php"); //发送Email函数 function smtp_mail ( $sendto_email, $subject, $body, $extra_hd...2016-11-25
  • Yii框架实现邮箱激活的方法【数字签名】

    这篇文章主要介绍了Yii框架实现邮箱激活的方法,基于邮箱发送邮件实现数字签名的激活功能,需要的朋友可以参考下...2016-10-20
  • php天翼开放平台短信发送接口实现

    临时性需求,研究了一下天翼开发平台的东西,用来发送验证码还是不错的,但是每日限额不多,所以很鸡肋,但是保证100%到达 买的话还是蛮贵的,代码没有做任何优化处理,只是测试是...2016-11-25
  • C#实现异步发送邮件的方法

    这篇文章主要介绍了C#实现异步发送邮件的方法,涉及C#异步操作与邮件发送的技巧,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • jQuery实现订单提交页发送短信功能前端处理方法

    这篇文章主要介绍了jQuery实现订单提交页发送短信功能前端处理方法,涉及jQuery响应鼠标事件及针对页面元素的样式与字符串正则操作相关技巧,需要的朋友可以参考下...2016-07-06
  • Qt实现UDP多线程数据处理及发送的简单实例

    本文主要介绍了Qt实现UDP多线程数据处理及发送的简单实例,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-10-21
  • C++实现含附件的邮件发送功能

    这篇文章主要为大家详细介绍了C++实现含附件的邮件发送功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25
  • phpmailer邮件发送实例(163邮箱 126邮箱 yahoo邮箱)

    phpmailer是一个非常优秀的php邮箱发送插件了,他可以几乎实现任何邮箱登录发送,下面我介绍163邮箱 126邮箱 yahoo邮箱的发送方法。 准备工作: 我们必须注册一个邮...2016-11-25