0

Here my php code to send email with phpmailer via YANDEX MAIL:

<?php 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
include_once "phpmailer/PHPMailer.php";
include_once "phpmailer/Exception.php";
include_once "phpmailer/SMTP.php";

Main content

if (isset($_POST['submit'])) {
    $subject = $_POST['subject'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $mail = new PHPMailer();

//if we want to send via SMTP
    $mail->Host = 'smtp.yandex.ru';
    //$mail->isSMTP();
    $mail->SMTPAuth = true;
    $mail->Username = "example@yandex.ru";//my yandex mail
    $mail->Password = "password";//my yandex password
    $mail->SMTPSecure = "ssl"; //TLS
    $mail->Port = 465; //587
    $mail->CharSet = "UTF-8";
    $mail->addAddress('example@gmail.com'); //to
    $mail->setFrom($email);
    $mail->Subject = $subject;
    $mail->isHTML(true);
    $mail->Body = $message;

    if ($mail->send())
        echo "Your email has been sent, thank you!";
    else
        echo "Please try again!".$mail->ErrorInfo;

}
?>

It shows "Your email has been sent, thank you!" but not send anything. How to solve it?

1 Answers1

0

By commenting out isSMTP(), it means you're sending through your local mail server via PHP's mail() function, and you're not using Yandex's SMTP server at all.

It is saying that you successfully delivered the message to your own local server, but it has no way of telling what happened to the message after that. You can find out by looking in your mail server's log file, usually somewhere like /var/log/mail/log.

If you do want to use Yandex's server, uncomment that line and set $mail->SMTPDebug = 2; so you can see what the server says.

Synchro
  • 35,538
  • 15
  • 81
  • 104