phpmailer 实例

phpmailer 实例

<? header("Content-type: text/html; charset=utf-8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP邮件发送程序</title>

</head>
<body style="background:#C6E1FD;">
<?php
 
$action=$_GET["action"];
if($action==""){
?>
<form name="form1" method="POST" action="?action=send&id=<?php echo $_POST[id];?>" style="margin:0px; padding:0px;">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
  <tr>
    <td width="28%" align="center" class="border tr_out">邮件标题:
      <label></label></td>
    <td width="72%" align="left" class="border tr_out">
      <input name="subject" type="text" id="subject" style="300px;" />
      <input name="id" type="hidden" value="<?php echo $id;?>"></td>
    </tr>
  <tr>
    <td align="center" class="border tr_out">邮件内容:      </td>
    <td width="72%" align="left" class="border tr_out"><textarea name="detail" cols="50" rows="20"  ></textarea></td>
  </tr>
    <tr>
    <td colspan="2" align="center" class="border tr_out"><input type="submit" name="Submit22" class="lostfocus" onFocus='this.className="getfocus";' onMouseOver='this.className="getfocus";' onBlur='this.className="lostfocus";' onMouseOut='this.className="lostfocus";'
value="确定发送"></td>
    </tr>
</table>
</form>
<?php
}elseif($action=='send'){
require_once('class.phpmailer.php');
function SmtpMail($send_to_mail,$subject,$body,$extra_hdrs,$username){
    $mail=new PHPMailer();
    $mail->IsSMTP();                              //邮件发送方式
    $mail->Host="smtp.163.com";        //SMTP服务器主机地址
    $mail->SMTPAuth=true;                 //是否为可信任的SMTP
    $mail->Username="laverder_169@163.com";          //SMTP 用户名 注意:普通邮件认证不需要加 @域名
    $mail->Password="*******";              //SMTP 用户密码
    $mail->From="laverder_169@163.com";       //发件人邮件地址
    $mail->FromName="测试";            //发件人
    $mail->CharSet="utf-8";           //指定字符集
    $mail->AddAddress($send_to_mail,$username);        //添加发送目标地址
    //$mail->AddReplyTo("name@hotmail.com","name");       //添加回复地址
    $mail->IsHTML(true);                     //邮件类型为HTML格式
    $mail->Subject=$subject;               //邮件主题
    #邮件内容
    $mail->Body=$body;
    $mail->AltBody="text/html";       //内容文本格式    
    if (@ !$mail->Send()) {
        $results=array("result"=>false,"message"=>$mail->ErrorInfo);
        return $results;
    }else{
        $results = array("result"=>true,"message"=>"邮件已经发送到{$send_to_mail},请查收。");
        return $results;
    }
}
 
   
      //执行发送email
      $send_mail=SmtpMail('laverder_169@126.com',$_POST["subject"],$_POST["detail"],"附加信息",'QQ.COM');
 
          if($send_mail["result"]){
            echo $send_mail["message"];
         }else{
            echo $send_mail["message"];
         }


}
?>
</body>
</html>

原文地址:https://www.cnblogs.com/fengju/p/6173853.html