9951 explained code solutions for 126 technologies


phpmailerHow can I use PHPMailer to send emails through Yandex?


PHPMailer is a library that can be used to send emails through Yandex. To use PHPMailer to send emails through Yandex, you need to do the following:

  1. Install the PHPMailer library:
composer require phpmailer/phpmailer
  1. Create a new instance of PHPMailer:
$mail = new PHPMailer;
  1. Configure the SMTP settings to use Yandex:
$mail->isSMTP();
$mail->Host = 'smtp.yandex.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
  1. Set the email address and name of the sender:
$mail->setFrom('[email protected]', 'John Doe');
  1. Set the email address and name of the recipient:
$mail->addAddress('[email protected]', 'Jane Doe');
  1. Set the subject and body of the message:
$mail->Subject = 'Hello';
$mail->Body = 'This is a test message.';
  1. Finally, send the email:
if ($mail->send()) {
    echo 'Message sent!';
} else {
    echo 'Message could not be sent.';
}

Output example

Message sent!

Helpful links

Edit this code on GitHub