Отправка электронной почты через php mailer - PullRequest
0 голосов
/ 27 октября 2019

Я хочу отправлять электронную почту с учетной записи Yahoo, используя phpmailor динамически, с помощью заданного пользователем адреса электронной почты и пароля.

, но 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

Неустранимая ошибка: Uncaught 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 \ srcPHPMailer.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.p(60): PHPMailer \ PHPMailer \ PHPMailer-> send () # 4 {main} добавляется в D: \ xampp \ htdocs \ Social \ Social-Platform \ Social_Platform \ vendor \ phpmailer \ phpmailer \ src \ PHPMailer.php в строке 2033

...