使用phpmailer发送email

简介:
InBlock.gif
http: //phpmailer.codeworxtech.com/
这里下载phpmailer

InBlock.gif<html>
InBlock.gif<head>
InBlock.gif<title>使用PHPMailer发邮件</title>
InBlock.gif</head>
InBlock.gif<body>
InBlock.gif<?php
InBlock.gif  if (!array_key_exists('Submitted',$_POST))
InBlock.gif {
InBlock.gif?>
InBlock.gif    <form method= "post" action= "mail2.php">
InBlock.gif    <input type= "hidden" name= "Submitted" value= "true"/><br/>
InBlock.gif    邮件服务器: <input type= "text" name= "Host" size= "25"/><br/>
InBlock.gif    如果要求验证:<br/>
InBlock.gif    用户名: <input type= "text" name= "Username" size= "25"/><br/>
InBlock.gif    密    码: <input type= "password" name= "Password" size= "10"/>
InBlock.gif    <hr/>
InBlock.gif    发给: <input type= "text" name= "To" size= "25"/><br/>
InBlock.gif    来自 Email: <input type= "text" name= "From" size= "25"/><br/>
InBlock.gif    来自 姓名: <input type= "text" name= "FromName" size= "25"/><br/>
InBlock.gif    主题: <input type= "text" name= "Subject" size= "25"/><br/>
InBlock.gif    <textarea name= "Message" cols= "50" rows= "10"></textarea><br/>
InBlock.gif    使用HTML: <input type= "checkbox" name= "HTML"/>
InBlock.gif    <input type= "submit" value= "发送Email"/>
InBlock.gif    </form>
InBlock.gif<?php
InBlock.gif }
InBlock.gif  else
InBlock.gif {
InBlock.gif    require( "class.phpmailer.php");
InBlock.gif    $To = $_POST['To'];
InBlock.gif    $From = $_POST['From'];
InBlock.gif    $FromName = $_POST['FromName'];
InBlock.gif    $Subject = $_POST['Subject'];
InBlock.gif    $Message = $_POST['Message'];
InBlock.gif    $Host = $_POST['Host'];
InBlock.gif    
InBlock.gif     if (array_key_exists('HTML',$_POST))
InBlock.gif    {
InBlock.gif     $HTML =  true; //HTML格式
InBlock.gif    }
InBlock.gif     else
InBlock.gif    {
InBlock.gif     $HTML =  false; //纯文本
InBlock.gif    }
InBlock.gif    
InBlock.gif    $Mail =  new PHPMailer();
InBlock.gif         
InBlock.gif    $Mail->IsSMTP();  // 通过SMTP发送
InBlock.gif    $Mail->Host = $Host;  //SMTP服务器
InBlock.gif    
InBlock.gif     if (array_key_exists('Username',$_POST))
InBlock.gif    {
InBlock.gif     $Mail->SMTPAuth= true;
InBlock.gif     $Mail->Username=$_POST['Username'];
InBlock.gif     $Mail->Password=$_POST['Password']; //实际中这里肯定需要做安全处理     
InBlock.gif    }
InBlock.gif     else
InBlock.gif    {
InBlock.gif     $Mail->SMTPAuth= false;
InBlock.gif    } 
InBlock.gif    
InBlock.gif    $Mail->From = $From;
InBlock.gif    $Mail->FromName = $FromName;
InBlock.gif    $Mail->AddAddress($To);
InBlock.gif    $Mail->AddReplyTo($From);
InBlock.gif    
InBlock.gif    $Mail->WordWrap = 50;  //设置自动换行
InBlock.gif    $Mail->IsHTML($HTML);
InBlock.gif    
InBlock.gif    $Mail->Subject    = $Subject;
InBlock.gif    $Mail->Body = $Message;
InBlock.gif    
InBlock.gif    $Mail->CharSet =  "gbk"; //中文字符集
InBlock.gif    
InBlock.gif     if($Mail->Send())
InBlock.gif    {
InBlock.gif     echo  "消息已发送";
InBlock.gif    }
InBlock.gif     else
InBlock.gif    {
InBlock.gif        echo  "消息未发送<br/>";
InBlock.gif        echo  "Mailer错误: " . $Mail->ErrorInfo;
InBlock.gif    }
InBlock.gif }
InBlock.gif?>
InBlock.gif</body>
InBlock.gif</html>


  本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/140404 ,如需转载请自行联系原作者
相关文章
|
8天前
|
C#
C# WinForm发送Email邮件
C# WinForm发送Email邮件
C# WinForm发送Email邮件
|
8月前
|
网络安全 PHP 数据安全/隐私保护
TP5+PHPMailer 实现发送邮件功能
使用QQ邮箱或者163网易邮箱或者126邮箱,这里以qq邮箱为例来进行介绍。
78 0
|
PHP 数据安全/隐私保护
phpmailer/phpmailer 邮件发送,163SMTP设置
phpmailer/phpmailer 邮件发送,163SMTP设置
148 0
邮件(email)
邮件–发送邮件 1.准备工作 1.1.生成查长度为4的验证码
105 0
谋杀 Email
作为新来者,凭着技术的进步、企业提升效率的需求、大厂们留下的中小客户市场切口,Zoom、Slack们高歌猛进,抢夺“Email们”的市场,在“WinTel大厂”们没能涉足的市场切下一块蛋糕。但在未来,当深入到大厂腹地,深入大型客户市场,新老企服软件公司的一战似乎不可避免。面对这些老玩家,他们能成功么
223 0
JavaUtil_09_email_使用 commons-email 发送邮件
  二、参考资料 1.【commons】邮件发送工具——commons-email
1044 0
|
关系型数据库 MySQL 测试技术
email
12533 0