Im пытается отправить большое количество писем с паролями студентам, сдающим экзамен по определенному предмету. Теперь у меня есть ошибка «Ошибка SMTP: не удалось подключиться к узлу SMTP. Ошибка Mailer() Ошибка SMTP : Не удалось подключиться к узлу SMTP. " Что может быть проблемой?Отправка почты с помощью PHPMailer
мой код выглядит следующим образом:
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
//date_default_timezone_set('America/Toronto');
require_once('PHPMailer-phpmailer-5.2.0/class.phpmailer.php');
include("PHPMailer-phpmailer-5.2.0/class.smtp.php"); //optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "localhost";
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent
$mail->Host = "mail.yahoo.com"; // sets the SMTP server*/
$mail->Port = 26;
$mail->Username = "***********@yahoo.com"; // SMTP account username
$mail->Password = "****************"; // SMTP account password
$mail->From = "*************@yahoo.com";
$mail->FromName = "Exam System";
//$mail->IsHTML(true);
while ($row_email = mysql_fetch_array ($email)) {
$mail->Subject = "Subject: ".$row_email['subject_description']."";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "This is your password for ".$row_email['exam_title']." : ".$row_email['pass_password']."";
$mail->AddAddress($row_email['stud_email']);
if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("@", "@", $row_email['stud_email']) . ') ' . $mail->ErrorInfo . '<br />';
} else {
echo "Message sent to :" . $row_email['stud_email'] . ' (' . str_replace("@", "@", $row_email['stud_email']) . ')<br />';
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
mysql_free_result($email);
?>
порт 26 выглядит неправильно. SMTP обычно отправляется на порт 25. Попробуйте удалить эту строку, чтобы библиотека по умолчанию использовала правильный порт? – halfer
Установите secutiry (TLS/SSL) и попытайтесь сменить порт на 465. –
Still Im с той же ошибкой. Ive изменил мой порт на 465 и добавил строку: $ mail-> SMTPSecure = 'tls'; Могу ли я использовать gmail, даже если моя учетная запись электронной почты находится на yahoo? –