Rumah > pembangunan bahagian belakang > tutorial php > PHP发送邮件类库PHPMailer的简单使用_PHP教程

PHP发送邮件类库PHPMailer的简单使用_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-07-13 10:34:11
asal
1272 orang telah melayarinya

最近需要用到发送邮件的功能,原本是用PHP自带的mail()函数发送的。php mail()这个方法非常简单、方便、易用,但是除了网易邮箱、QQ邮箱、GMAIL邮箱等常用的邮箱可以收到之外,经测试HOTMAIL、TOM、LIVE等邮箱是收不到此类邮件的。所以就转而使用PHPMailer这个强大的邮件发送类。

使用官方自带的一些例子,有些会报 Mailer Error: Could not instantiate mail function. 这个错误。参考了一些资料之后,还是自己写了一个方法。代码很简单,就不多解释了。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

function mailto($nickname, $address, $id, $activation_code)

{

    date_default_timezone_set('PRC');

    include_once("class.phpmailer.php");

     

    $mail = new PHPMailer(); // defaults to using php "mail()"

    $mail->IsSMTP();

    $mail->Host = "smtp.163.com";            // SMTP 服务器 

    $mail->SMTPAuth = true;                  // 打开SMTP 认证 

    $mail->Username = "bkjia@163.com";   // 用户名

    $mail->Password = "yourpassword";          // 密码 

     

    //$body = file_get_contents('application/views/nmra/register.html');

    //$body = preg_replace('/\\\\/','', $body); //Strip backslashes

    $body = '<p><body style="margin: 10px;"></p>';

    $body .= '<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 14px; ">';

    $body .= '<div align="center"><img  src="/static/imghw/default1.png"  data-src="images/phpmailer.gif"  class="lazy"   style="max-width:90%" alt="PHP发送邮件类库PHPMailer的简单使用_PHP教程" ></div>';

    $body .= '<p>'.$nickname.',您好。</p>';

    $body .= '<p>恭喜你成为帮客之家研究协会的第'.$id.'名会员。</p>';

    $body .= '<p>帮客之家社区(bangke Research Association)是一个程序猿、攻城狮、设计狮和开发者们技术交流、话题讨论的社区。希望在这里你能找到感兴趣的话题与志同道合的朋友。</p>';

    $body .= '请点击以下链接验证您的邮箱,请注意域名为bkjia.com:<a href="http://www.bkjia.com/librarys/accounts/activation/?code="'.$activation_code.'" target="_blank">http://www.bkjia.com/librarys/accounts/activation/?code='.$activation_code.'</a>';

    $body .= '<p>顺祝工作学习愉快,生活舒心。</p>';

    $body .= '</div></body>';

    //echo $body;

 

    $mail->AddReplyTo("bkjia@163.com","Gonn");

    $mail->SetFrom('bkjia@163.com', 'Gonn');

    $mail->AddReplyTo("bkjia@163.com","Gonn");

    $address = "252211974@qq.com";

    //$address = "bkjia@gmail.com";

    $mail->AddAddress($address, $nickname);

     

    $subject = "收到来自帮客之家的邮件";

    $mail->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";

    // optional, comment out and test

    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";

    $mail->MsgHTML($body);

     

    //$mail->AddAttachment("images/phpmailer.gif");      // attachment

    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

     

    if(!$mail->Send()) {

        //echo "Mailer Error: " . $mail->ErrorInfo;

    }

    else {

        //echo "Message sent!";

    }

}

Salin selepas log masuk

使用的时候只要引入两个PHP类,然后自己写个方法就OK了,两个类很小,发送邮件速度也很快。

PHPMailer 是一个功能强大的邮件类,其主要功能特点:

  1. 支持邮件 s/mime加密的数字签名
  2. 支持邮件多个 TOs, CCs, BCCs and REPLY-TOs
  3. 可以工作在任何服务器平台,所以不用担心WIN平台无法发送邮件的问题的
  4. 支持文本/HTML格式邮件
  5. 可以嵌入image图像
  6. 对于邮件客户端不支持HTML阅读的进行支持
  7. 功能强大的发送邮件调试功能debug
  8. 自定义邮件header
  9. 冗余SMTP服务器支持
  10. 支持8bit, base64, binary, and quoted-printable 编码
  11. 文字自动换行
  12. 支持多附件发送功能
  13. 支持SMTP服务器验证功能
  14. 在Sendmail, qmail, Postfix, Gmail, Imail, Exchange 等平台测试成功
  15. 提供的下载文件中,包括内容详细的说明文档及示例说明,所以不用担心难于上手的问题!
  16. PHPMailer 非常小巧、简单、方便、快捷

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/752342.htmlTechArticle最近需要用到发送邮件的功能,原本是用PHP自带的mail()函数发送的。php mail()这个方法非常简单、方便、易用,但是除了网易邮箱、QQ邮箱、...
Label berkaitan:
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Isu terkini
Saya tidak berjaya menulis dengan guru
daripada 1970-01-01 08:00:00
0
0
0
Tetapan rujukan laluan PHP
daripada 1970-01-01 08:00:00
0
0
0
Tukar fail html kepada perkataan
daripada 1970-01-01 08:00:00
0
0
0
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan