S
S
skyfly20102021-08-05 17:22:05
PHP
skyfly2010, 2021-08-05 17:22:05

Why can't PHPmailer send a message via STMP?

Good evening, dear experts. I have already broken my head in an attempt to figure out why I have an error Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl...
I follow instructions from github and look for advice from people on the internet. But I still get an error connecting via stmp.

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


require $_SERVER["DOCUMENT_ROOT"].'/PHPMailer/src/Exception.php';
require $_SERVER["DOCUMENT_ROOT"].'/PHPMailer/src/PHPMailer.php';
require $_SERVER["DOCUMENT_ROOT"].'/PHPMailer/src/SMTP.php';



//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
  
    //Server settings
    // $mail->SMTPDebug = SMTP::DEBUG_SERVER;                     //Enable verbose debug output
    $mail->isSMTP();                                              //Send using SMTP
    $mail->Host       = 'smtp.yandex.ru';                         //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                     //Enable SMTP authentication
    $mail->Username   = '[email protected]';                     //SMTP username
    $mail->Password   = 'password';                       //SMTP password           
  $mail->SMTPSecure   = 'TLS';                                  //Enable implicit TLS encryption
    $mail->Port       = 587;                                      //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
  
    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     //Add a recipient

    //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 = '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}";
}

As password already tried to use both the password from the account and the password for the application.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SagePtr, 2021-08-05
@SagePtr

The simplest option - outgoing mail is prohibited on the hosting in order to combat spam

G
galaxy, 2021-08-05
@galaxy

In fact, Yandex writes that the SMTP port is 465

D
Dimonchik, 2021-08-05
@dimonchik2013

yandeh to work - the first letter must be sent from the web of the muzzle yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question