我有phpmailer的问题。我想发送多封不同内容的电子邮件。该脚本适用于多个地址,但不适用于几百个地址。当我尝试为100个用户发送电子邮件时,我遇到错误503“服务不可用。由于维护停机或容量问题,服务器暂时无法为您的请求提供服务。”
这是代码:
include('../config_inc.php');
include('../admin-settings.php');
if(isset($_POST['submit'])){
require("../phpmailer/class.smtp.php");
require("../phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if(!empty($_POST['wyslijemail'])){
foreach($_POST['wyslijemail'] as $ids){
set_time_limit(60);
$iduser = $ids;
$tabelka = '1234567890qwertyuiopasdfghjklzxcvbnm';
$ticket = '';
for ($i=0; $i<7; $i++) {
$ticket .= $tabelka[rand()%(strlen($tabelka))];
}
$zapytanie_user = mysql_query("SELECT * FROM users WHERE id = ".$iduser."");
$user_row = mysql_fetch_array($zapytanie_user);
$admin_email = $settings_cms['email'];
$title_page = $settings['tytul_email'];
$login = $user_row['login'];
$haslo_encode = $user_row['haslo_encode'];
$tytul_aktywacja = $powiadomienia['tytul_aktywacja'];
$tresc_aktywacja = $powiadomienia['tresc_aktywacja'];
$email = $user_row['email'];
$message = $powiadomienia['aktywacja_oferta'];
$message = str_replace("{login}",$login,$message);
$message = str_replace("{domena}",$domena2,$message);
$message = str_replace("{ticket}",$ticket,$message);
$message = str_replace("{iduser}",$iduser,$message);
$message = str_replace("{haslo}",$haslo_encode,$message);
$message = str_replace("{tytul}",$title_page,$message);
$message = str_replace("tytul_aktywacja}",$tytul_aktywacja,$message);
$message = str_replace("tresc_aktywacja}",$tresc_aktywacja,$message);
$mail->IsSMTP();
$mail->CharSet = "UTF-8";
$mail->PluginDir = "phpmailer/";
$mail->From = "".$admin_email."";
$mail->FromName = "".$settings['tytul_email']."";
$mail->Host = "".$settings['smtp_serwer']."";
$mail->Mailer = "smtp";
$mail->Username = "".$settings['smtp_login']."";
$mail->Password = "".$settings['smtp_haslo']."";
$mail->IsHTML(true);
$mail->Port = "".$settings['smtp_port']."";
$mail->SetLanguage("pl", "phpmailer/language/");
$mail->Subject = $powiadomienia['tytul_aktywacja'];
$mail->Body = ''.$message.'';
$mail->AddAddress("".$email."","".$login."");
if($mail->Send()){
$check = 1;
} else {
header('Location: https://xxx?akcja=email_masowo_error');
}
$mail->ClearAddresses();
$mail->ClearAttachments();
}
if($check == 1){
header('Location: https://xxxx/show_users_list.php?akcja=email_masowo');
}
}
}
?>
答案 0 :(得分:2)
在网页提交过程中需要花费很长时间的事情是不可靠的,并且会因为Web服务器认为PHP被破坏而导致503错误。您可以增加超时,但这不是一个合适的解决方案。
使用您的页面提交将消息标记为需要发送(但实际上不执行发送),然后使用cron脚本或长时间运行的守护程序来获取消息并异步发送它们。 A suitable script for sending messages to a list efficiently is provided with PHPMailer
为获得最佳性能,您应该运行本地邮件服务器并通过SMTP提交。 PHPMailer wiki有an article about sending to lists。
您正在运行旧版本的PHPMailer; get the latest
另外,请勿使用mysql_*
功能;它们已经过时了。请改用mysqli_*
或PDO。