M
M
miniven2017-07-04 11:16:16
PHPMailer
miniven, 2017-07-04 11:16:16

Why is mail not sent via PHPMailer?

This is what the send email function looks like:

function send_message($array) {
    global $alias;
    global $settings;

    $message = "
    <p>" . $settings["mail"]["message"] . "</p>
        <br>
        <p><strong>Дата обращения: </strong>" . date('d.m.Y H:i:s') .  "</p>
  ";
    foreach($array as $field) {
        $name = $field["name"];
        $value = $field["value"];

        if ($name !== "g-recaptcha-response" && $name !== "agreement") {
            $message .= "<p><strong>" . $alias[$name] . ":</strong> " . $value . "</p>";
        }
    };
    $message .= "<br><br><p>Это письмо сгенерировано автоматически. Пожалуйста, не отвечайте на него.</p>";

    $mail = new PHPMailer;

    $mail->isSMTP();
    $mail->Host = 'smtp.yandex.ru';
    $mail->SMTPAuth = true;
    $mail->Username = $settings["mail"]["auth"]["username"];
    $mail->Password = $settings["mail"]["auth"]["password"];
    $mail->SMTPSecure = "ssl";
    $mail->Port = 465;
    $mail->CharSet = "UTF-8";

    $mail->Subject = $settings["mail"]["subject"];
    $mail->SetFrom($settings["mail"]["sender"]["address"], $settings["mail"]["sender"]["alias"]);
    $mail->MsgHTML($message);
    $mail->AddAddress($settings["mail"]["receiver"]["address"], $settings["mail"]["receiver"]["alias"]);

    $mail->Send();
};

All data is correct. This code runs on a local server and sends emails just fine. And the site does not want to work. Here's what happens: it runs all the code up to $mail->Send(); and at this point, the endless sending of a letter or something like that begins. In general, the response from the server does not come or comes after a few minutes (successful). Why is this happening and what to do about it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2017-07-04
@djQuery

Try mail_port = 587. Change SMPT from Yandex to some other one. Disable your antivirus. All these steps at different times helped me in one way or another.
By the way, do you get a send error message?

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

N
Nik Gubin, 2017-07-04
@gubin_niko

Pay attention to which mailbox you are trying to send mail from.
Wangyu that:
Let's try this:

$mail->SetFrom($settings["mail"]["auth"]["username"], $settings["mail"]["sender"]["alias"]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question