zoukankan      html  css  js  c++  java
  • PHPmailer关于Extension missing: openssl报错的解决

       最近在写一个网页的时候,需要用到PHPmailer来发送邮件,按照官网上给出的demo写出一个例子,却报错Extension missing: openssl

       最后发现需要修改php.ini中的配置:

       将其中的

          extension=php_openssl.dll

       打开即可。

       

       demo代码添加如下:

     1 <?php
     2 require 'PHPMailerAutoload.php';
     3 
     4 $mail = new PHPMailer;
     5 
     6 //$mail->SMTPDebug = 3;                               // Enable verbose debug output
     7 
     8 $mail->isSMTP();                                      // Set mailer to use SMTP
     9 $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    10 $mail->SMTPAuth = true;                               // Enable SMTP authentication
    11 $mail->Username = 'user@example.com';                 // SMTP username
    12 $mail->Password = 'secret';                           // SMTP password
    13 $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    14 $mail->Port = 587;                                    // TCP port to connect to
    15 
    16 $mail->setFrom('from@example.com', 'Mailer');
    17 $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    18 $mail->addAddress('ellen@example.com');               // Name is optional
    19 $mail->addReplyTo('info@example.com', 'Information');
    20 $mail->addCC('cc@example.com');
    21 $mail->addBCC('bcc@example.com');
    22 
    23 $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    24 $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    25 $mail->isHTML(true);                                  // Set email format to HTML
    26 
    27 $mail->Subject = 'Here is the subject';
    28 $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    29 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    30 
    31 if(!$mail->send()) {
    32     echo 'Message could not be sent.';
    33     echo 'Mailer Error: ' . $mail->ErrorInfo;
    34 } else {
    35     echo 'Message has been sent';
    36 }

       

  • 相关阅读:
    JQuery源码解读 JQ框架简化( 妙味讲堂
    Mia Fringe官网会员须知
    require.js
    :before与::before的区别
    css----苹果移动端以及小程序滚动模块卡顿的处理
    Vue使用国密SM4加密
    vue + echarts + echarts-gl 实现3D 环状图
    React Hook 初学
    常用阻止默认行为的两种方式
    理解事件触发,事件捕获,事件冒泡
  • 原文地址:https://www.cnblogs.com/duolk/p/5917020.html
Copyright © 2011-2022 走看看