phpmailer не работает после перехода на php 7

Ниже мой php-код

Ранее сервер был на php 5.9, а недавно мы обновили его до php 7.0.

при отправке почты мы получаем следующую ошибку, она говорит об ошибке SMTP, но учетные данные верны

Сообщение не может быть отправлено. Ошибка почтовой программы: SMTP connect() не удалось. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

<?php
$cname = $_REQUEST[ 'cname' ];
//echo $cname;
$email = $_REQUEST[ 'email' ];
//echo $email.',';
$phone = $_REQUEST[ 'phone' ];
//echo $phone.',';
$datetime = $_REQUEST[ 'datetime' ];
//echo $datetime.',';
$package = $_REQUEST[ 'packages' ];
//echo $package.',';


$message = '<table style="height: 231px; width: 490px; float: left;">
<tbody>
<tr style="height: 21.5px;">
<td style="width: 235.433px; height: 21.5px;"><strong>Name:-</strong></td>
<td style="width: 253.567px; height: 21.5px;">' . $cname . '</td>
</tr>
<tr style="height: 21px;">
<td style="width: 235.433px; height: 21px;"><strong>Email:-</strong></td>
<td style="width: 253.567px; height: 21px;">' . $email . '</td>
</tr>
<tr style="height: 21px;">
<td style="width: 235.433px; height: 21px;"><strong>Phone No:-</strong></td>
<td style="width: 253.567px; height: 21px;">' . $phone . '</td>
</tr>
<tr style="height: 21px;">
<td style="width: 235.433px; height: 21px;"><strong>Date & Time:-</strong></td>
<td style="width: 253.567px; height: 21px;">' . $datetime . '</td>
</tr>
<tr style="height: 21.5px;">
<td style="width: 235.433px; height: 21.5px;"><strong>Packages:-</strong></td>
<td style="width: 253.567px; height: 21.5px;">' . $package . '</td>
</tr>';

require "PHPMailer/PHPMailerAutoload.php";
// require_once "PHPMailer/class.phpmailer.php"; //include phpmailer class

// Instantiate Class  
$mail = new PHPMailer();

// Set up SMTP  
$mail->IsSMTP(); // Sets up a SMTP connection  
//$mail->SMTPDebug  = 2;       // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization    
$mail->SMTPSecure = "ssl"; //"ssl";      // Connect using a TLS connection 
//$mail->SMTPSecure = "tls";

//$mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
$mail->Host = "mail.test.com";
$mail->Port = '465'; //'465';  //Gmail SMTP port
$mail->Encoding = '8bit';

// Authentication  

$mail->Username = "[email protected]";
$mail->Password = "password";


// Compose
$mail->SetFrom( '[email protected]', 'Test' );

$mail->Subject = "Appointment for $package has been received"; // Subject (which isn't required)  
$mail->MsgHTML( $message );

// Send To  
//$mail->AddAddress("", "Recipient Name"); // Where to send it - Recipient
//$mail->AddAddress("[email protected]", "Recipient Name");



// $result = $mail->Send();     // Send!  
//$message = $result ? 'Successfully Sent!' : 'Sending Failed!'; 
//$message = $result ? header("Location:thank_you.php"); : 'Sending Failed!';      
//unset($mail);

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


?>
<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Favicon -->
    <link rel="icon" href="favicon.png">
        <link href="css/main.css" rel="stylesheet" type="text/css">
    <style>
    .text-xs-center {
    text-align: center !important;
}
.jumbotron {
    padding: 4rem 2rem;
}
.jumbotron {
    background-color: #eceeef;
    border-radius: 0.3rem;
    margin-bottom: 0rem;
    padding: 5rem 1rem;
}
        .display-3 {
    font-size: 4.5rem;
    font-family: Poiret One; font-weight: bold;
}
        .lead {
    font-size: 1.25rem;
    font-weight: 300;
    font-family: Poiret One; font-weight: bold;
}
p {
    margin-bottom: 1rem;
    margin-top: 0;
    font-family: Poiret One; font-weight: bold;
}
    .thankyou-check {
    color: #15639a;
    font-size: 100px;
    text-align: center;
    margin: 6px;    
}
    </style>

    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/bootstrap.min.js" type="text/javascript"></script>
</head>

<body>
    <?php echo  file_get_contents('header.php'); ?>
    <div class="jumbotron text-xs-center">
    <i class="fa fa-check-circle thankyou-check"></i>
  <h1 class="display-3">Thank You!</h1>
  <p class="lead">for your appointment and We will get back to you soon.</p>
</div>  
    <?php echo  file_get_contents('footer.php'); ?>
</body>

    enter code here

</html>

person Brijesh Savaliya    schedule 25.07.2018    source источник
comment
Включить отладку SMTP: $mail->SMTPDebug = 2; и проверь что там написано   -  person Klian    schedule 25.07.2018
comment
Попробуйте использовать порт 587, так как 465 — это порт для Gmail, и у вас есть хост обновлений.   -  person Lovepreet Singh    schedule 25.07.2018
comment
ОШИБКА SMTP: команда пароля не удалась: 535 5.7.8 @klian   -  person Brijesh Savaliya    schedule 25.07.2018
comment
@LovepreetSingh смена порта не помогла   -  person Brijesh Savaliya    schedule 25.07.2018
comment
Ошибка 535 — это проблема аутентификации. Вам нужно будет проверить правильность учетных данных: хост SMTP правильный. Имя пользователя правильное. Пароль правильный. Порт правильный. Метод аутентификации правильный.   -  person Klian    schedule 25.07.2018


Ответы (1)


Вы можете просто изменить номер строки 459 и заменить функцию split на функцию explode.

-  $toArr = split(',', $to);
+  $toArr = explode(',', $to);
person Ankit Yadav    schedule 15.09.2020
comment
Это вообще не связано с проблемой. Проблема OP - проблема аутентификации. - person Raptor; 15.09.2020