You could check if the email address is valid, and if the mailserver will respond, before using $mail->addBCC()
. This function can do both:
function isValidEmailAddress($email, $performDomainCheck = FALSE)
// validate an email address, TRUE if the email address has the email address format and the domain exists
{
$atSignIndex = strrpos($email,'@');
// no @ sign
if (is_bool($atSignIndex) && !$atSignIndex) return FALSE;
// take parts
$domain = substr($email,$atSignIndex+1);
$name = substr($email,0,$atSignIndex);
$domainLen = strlen($domain);
$nameLen = strlen($name);
// name part length exceeded
if ($nameLen < 1 || $nameLen > 64) return FALSE;
// domain part length exceeded
if ($domainLen < 1 || $domainLen > 255) return FALSE;
// local part starts or ends with '.'
if ($name[0] == '.' || $name[$nameLen-1] == '.') return FALSE;
// local part has two consecutive dots
if (preg_match('/\.\./', $name)) return FALSE;
// character not valid in domain part
if (!preg_match('/^[A-Za-z0-9\-\.]+$/', $domain)) return FALSE;
// domain part has two consecutive dots
if (preg_match('/\.\./', $domain)) return FALSE;
// character not valid in local part unless local part is quoted
if (!preg_match('/^(\\.|[A-Za-z0-9!#%&`_=\/$'*+?^{}|~.-])+$/',str_replace("\\","",$name)))
{
if (!preg_match('/^"(\\"|[^"])+"$/',str_replace("\\","",$name))) return FALSE;
}
// domain not found in DNS?
if ($performDomainCheck)
{
// $domain = idn_to_ascii($domain); function not known yet (php 5.3 on 24-10-2015)
if (!(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) return FALSE;
}
// it's oke
return TRUE;
}
I didn't update the style of this function. It is not perfect, but using something like this will make your mass mailer work a lot better. Your code would look something like this:
foreach ($gonulluler as $gonullu){
if (isValidEmailAddress($gonullu, TRUE) {
$mail->addBCC($gonullu);
}
}
You could add an else
part to notify yourself of the invalid email addresses.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…