zoukankan      html  css  js  c++  java
  • PHP 发送邮件

    1.QQ 邮箱开通 SMTP 服务

    开通方法

    2.PHP开启 openssl 扩展

    3.安装 Github PHPMailer

    composer require phpmailer/phpmailer
    

    4.代码

    <?php
    
    use PHPMailerPHPMailerPHPMailer;
    use PHPMailerPHPMailerSMTP;
    
    require_once __DIR__ ."/vendor/autoload.php";
    
    $mail = new PHPMailer(true);
    
    try {
        //Server settings
        $mail->SMTPDebug = SMTP::DEBUG_CLIENT;                      // Enable verbose debug output
        $mail->isSMTP();                                            // Send using SMTP
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Host       = 'smtp.qq.com';                         // Set the SMTP server to send through
        $mail->Port       =  465;                                   // TCP port to connect to  , 465
        $mail->CharSet    = "UTF-8";
        $mail->FromName   = "lvpeilin";
        $mail->Username   = '422615924@qq.com';                     // SMTP username
        $mail->Password   = '*************************';                     // SMTP password, 授权码
        $mail->setFrom('422615924@qq.com', 'Dyspace');
        $mail->addAddress('lvpeilin@dyspace.net', 'lvpeilin');     // Add a recipient
    
        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
    

    原文

    使用PHPMAILER实现PHP发邮件功能

  • 相关阅读:
    python基础4
    python的基础数据类型和编码
    python的if语句和while循环
    java特殊运算符
    深入理解java集合
    python常用模块
    python函数的参数问题
    集合关系之间的运算
    集合
    可变类型与不可变类型
  • 原文地址:https://www.cnblogs.com/jingjingdidunhe/p/12119459.html
Copyright © 2011-2022 走看看