Подтвердить что ты не робот

"Пароль не принимается с сервера: 535 Неверные данные аутентификации" при отправке с помощью GMail и phpMailer

У меня есть тот же php script, запущенный на localhost - мой ПК с XAMPP и на размещенном сервере. Он работает с моего ПК, но не с размещенного сервера.

Когда я отправляю его с размещенного сервера, я получаю следующий вывод:

SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data  
SMTP -> ERROR: RCPT not accepted from server: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message. dev.camppage.com 550-(patchvalues.com) [205.234.141.238]:50958 is not permitted to relay through 550 this server without authentication.  
SMTP Error: The following recipients failed: [email protected] FAILED

Я подозреваю, что есть параметр конфигурации, который необходимо изменить на сервере, но я не знаю, какой из них. Любые советы будут очень признательны!

Вот код:

function send_gmail ($recipients, $subject, $message, $attachment_filenames = array()) 
{
  global $email_address, $email_password, $email_name;
  require_once ($_SERVER['DOCUMENT_ROOT']. '/php/PHPMailer/class.phpmailer.php');   

  $body  = $message;
  $body  = str_replace("\\", '', $body);
  $mail = new PHPMailer();
  $mail->CharSet = "UTF-8";
  $mail->IsSMTP();
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing) 0 - none; 1 - errors & messages; 2 - messages only
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail->Port       = 465;                   // set the SMTP port
  $mail->Username   = $email_address;  // GMAIL username
  $mail->Password   = $email_password; // GMAIL password
  $mail->SetFrom($email_address);
  $mail->FromName   = $email_name;
  $mail->AddReplyTo($email_address,$email_name);
  $mail->Subject    = $subject;
  $mail->MsgHTML($body);
  $mail->IsHTML(true); // send as HTML

  if (isset ($recipients[0]))
  {
    foreach ($recipients AS $to)
    {
        $to_pieces = explode (",", $to, 2);
        $to_email = trim ($to_pieces[0]);
        if (isset ($to_pieces[1]))
            $to_name = trim ($to_pieces[1]);
        else
            $to_name = " ";
        $mail->AddAddress($to_email, $to_name);
    }
    $mail->IsHTML(true); // send as HTML

    if ($mail->Send()){
        return TRUE;
    } else {
        return FALSE;
    }
} 
else 
{
    return FALSE;
}
}

ТИА

4b9b3361

Ответ 1

Решение заключалось в том, чтобы включить исходящий SMTP из настроек сервера.

На серверах под управлением cPanel WHM это расположено в разделе WHM "Настройки настройки".

Опция - включить/отключить - выбрать отключить.

Предостережение: внесение этого изменения приведет к перенаправлению исходящих SMTP-подключений, позволяя учетным записям делать прямые подключения, что может увеличить ваши шансы на то, что ваш сервер будет включен в черный список.

Ответ 2

это связано с WHM/cPanel, вы можете сделать то же самое, что и в предыдущем ответе или из оболочки, набрав этот

/scripts/smtpmailgidonly off

вы должны получить

"SMTP Mail protection has been disabled.  All users may make outbound smtp connections."

подробнее здесь https://forums.cpanel.net/threads/cant-enable-smtp-restrictions.360971/