通过php mailer发送电子邮件

时间:2019-10-27 17:57:35

标签: php smtp phpmailer yahoo

我想使用用户指定的电子邮件和密码通过phpmail从yahoo帐户动态发送电子邮件

但是php mailer抛出错误 SMTP错误:无法通过身份验证

我尽我所能,但一无所获

<?php


 use PHPMailer\PHPMailer\PHPMailer;
 use PHPMailer\PHPMailer\Exception;

 if (isset($_POST['btn_send'])){
 $subject = $_POST['subject'];
 $caption = $_POST['caption'];
 $senderemail = $_POST['sendingemail'];
 $senderpassword = $_POST['sending_email_pass'];
 $receiveremail = $_POST['receiver_email'];
 // Load Composer's autoloader
    require 'vendor/autoload.php';

    // Instantiation and passing `true` enables exceptions
    $mail = new PHPMailer(true);


        //Server settings
        //$mail->SMTPDebug = 2;                                       // 
         Enable verbose debug output

         $mail->isSMTP();
         $mail->CharSet = 'UTF-8';                                            
         // Set mailer to use SMTP
         $mail->Host       = "smtp.mail.yahoo.com";  // Specify main and 
         backup SMTP servers
         $mail->SMTPAuth  = true;
         $mail->SMTPSecure = 'ssl';                                     
         //Enable SMTP authentication
         $mail->Port       = 465;
         $mail->username   =  $senderemail;                                  
         // SMTP username
        $mail->Password   =  $senderpassword;                               
       // SMTP password
         // Enable TLS encryption, `ssl` also accepted
                                            // TCP port to connect to
        $mail->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );
        //Recipients
        $mail->setFrom($senderemail , $subject);
        $mail->addAddress ($receiveremail);     // Add a recipient
        //$mail->addAddress('ellen@example.com');               // Name is optional
        //$mail->addReplyTo('info@example.com', 'Information');
        //$mail->addCC('cc@example.com');
        //$mail->addBCC('bcc@example.com');

        // Attachments
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $subject;
        $mail->Body    = $caption;
        //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';



        if($mail->send())
        {
            echo json_encode(['status' => 'success']);
        }


    }

         // Import PHPMailer classes into the global namespace
         // These must be at the top of your script, not inside a function

致命错误:未捕获PHPMailer \ PHPMailer \ Exception:SMTP错误:无法验证。在D:\ xampp \ htdocs \ Social \ Social-Platform \ Social_Platform \ vendor \ phpmailer \ phpmailer \ src \ PHPMailer.php:2033堆栈跟踪:#0 D:\ xampp \ htdocs \ Social \ Social-Platform \ Social_Platform \ vendor \ phpmailer \ phpmailer \ src \ PHPMailer.php(1847):PHPMailer \ PHPMailer \ PHPMailer-> smtpConnect(Array)#1 D:\ xampp \ htdocs \ Social \ Social-Platform \ Social_Platform \ vendor \ phpmailer \ phpmailer \ src \ PHPMailer.php(1589):PHPMailer \ PHPMailer \ PHPMailer-> smtpSend('Date:Sun,27 O ...','Hello My Name i ...')#2 D:\ xampp \ htdocs \ Social \ Social -Platform \ Social_Platform \ vendor \ phpmailer \ phpmailer \ src \ PHPMailer.php(1423):PHPMailer \ PHPMailer \ PHPMailer-> postSend()#3 D:\ xampp \ htdocs \ Social \ Social-Platform \ Social_Platform \ send_email.php (60):PHPMailer \ PHPMailer \ PHPMailer-> send()#4 {main}丢在2033行的D:\ xampp \ htdocs \ Social \ Social \ Social-Platform \ Social_Platform \ vendor \ phpmailer \ phpmailer \ src \ PHPMailer.php

0 个答案:

没有答案
相关问题