0

i have a problem. I have created this code:

//Include Required PHPMailer files.
    require_once '../php/phpMailer/PHPMailer.php';
    require_once '../php/phpMailer/SMTP.php';
    require_once '../php/phpMailer/Exception.php';
    //Define Namespaces.
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;
    
    //Create Instance of PHPMailer.
    $mail = new PHPMailer();
    //Set Mailer to use SMTP.
    $mail->isSMTP();
    //Define SMTP Host.
    $mail->Host="ssl://smtp.gmail.com";
    //Enable SMTP Authentication.
    $mail->SMTPAuth="true";
    //Set type of Encryption (ssl/tls).
    $mail->SMTPSecure="ssl";
    //Set Port to connect SMTP.
    $mail->Port=465;
    //Set Username of Gmail.
    $mail->Username="PRIVACY";
    //Set Password of Gmail.
    $mail->Password="PRIVACY";
    //Set Sender of Email.
    $mail->setFrom("PRIVACY");
    //Enable HTML.
    $mail->isHTML(true);
    
    $arrayEmails = explode("\n", file_get_contents('PRIVACY'));
    unset($arrayEmails[count($arrayEmails)-1]);
    
    //Set Subject of Email.
    $mail->Subject=$_POST['titolo'];
    //Body of the Email.
    $mail->Body=$_POST['inviaNewsletter'];
    
    $listOfEmail = array();
    for ($i=0; $i<500; $i++) {
        //Add Receiver.
        $mail->AddBCC($arrayEmails[$i]);
        if ($i % 100 == 0) {
            //Send Email.
            $mail->send();
            $mail->clearAllRecipients();
        }
        array_push($listOfEmail, $arrayEmails[$i]);
    }

    //Send Email.
    $mail->send();
    $mail->clearAllRecipients();
    //Closing SMTP Connection.
    $mail->smtpClose();
    
    echo print_r($listOfEmail);

this code works but after the first sending of the first 100 emails, it does not continue further. Why? Have you encountered the same problem by any chance? Why doesn't it allow me to send 500 emails? if what I am trying to do is not possible, do you know a method to send 8,000 emails from my private server to the emails of my subscribers? I don't want to use external services so as not to spend more money. With this method, it seems that google is not reporting me as spam.

  • What is your max execution time set as in your PHP configuration – Jaquarh Sep 05 '21 at 09:50
  • What exactly happens after 500 emails? Can you explain a bit what "doesn't allow me" means? Does your script crash? Does it continue but the emails never reach their recipients? You should also check gmails limit. They don't allow you to send large mount of emails. It can also be the ISP that blocks you after a certain amount since they might believe that there's some virus or something. Consumer services (ISP's, free email services etc) aren't suited for this so if you need to send 8k+ emails, you will probably need to pay for a service to do it. – M. Eriksson Sep 05 '21 at 09:54
  • Have you [enabled error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)? – KIKO Software Sep 05 '21 at 10:02
  • 3
    The free Gmail SMTP server has a limit of [100 email recipients per day](https://developers.google.com/apps-script/guides/services/quotas). Note that 1 email with 100 BCC recipients will hit that daily limit. – rickdenhaan Sep 05 '21 at 10:03
  • Have you considered setting up your own mailserver on your private server? – brombeer Sep 05 '21 at 10:05
  • Yeah, it tells me that the email has been sent but in reality it does not reach anyone and there are no sending errors. – Founder Onepiecepower Sep 05 '21 at 10:17
  • My max execution time is more than 10 hours end it ended after 5/6 minute. – Founder Onepiecepower Sep 05 '21 at 10:17
  • but the emails are not actually sent. – Founder Onepiecepower Sep 05 '21 at 10:18
  • Can someone give me a guide to create my own mailserver into centos server? thanks – Founder Onepiecepower Sep 05 '21 at 10:19
  • 2
    Setting up your own mailserver is not so trivial that we can guide you here. Googling "centos smtp server" gives several walkthroughs. But I'd first check with your ISP or hosting provider if they do not already have one that you can use. – rickdenhaan Sep 05 '21 at 10:22
  • @RiggsFolly In a **B**CC list? Rather in a CC list – brombeer Sep 05 '21 at 10:57
  • 1
    @RiggsFolly Ok, thanks for enlightening me, didn't know that. Kind of defeats the **B** in **B**cc. Thanks again – brombeer Sep 05 '21 at 11:08
  • https://www.linuxbabe.com/mail-server/postfix-send-only-smtp-server-centos-8 is this a good guide? – Founder Onepiecepower Sep 05 '21 at 12:52
  • @RiggsFolly @brombeer No they cannot. The `Bcc` field is not included in the message sent to the recipients' mailboxes. The `Bcc` field is only added to the envelope but not to the headers, so the SMTP server will obviously know about them, but the recipients won't. See [this answer](https://security.stackexchange.com/questions/206003/can-i-retrieve-email-addresses-from-bcc) and [spec](https://www.rfc-editor.org/rfc/rfc2822#section-3.6.3). – CherryDT May 30 '22 at 09:06
  • @CherryDT Hmm wonder where I got that from. I am sure I have seen them in the header, but obviously I must have been dazed and confused – RiggsFolly May 30 '22 at 17:09

2 Answers2

1

Don't use Google to send this amount of emails. That's not the purpose of Gmail. I would highly recommend to use something like Mailchimp & Co. Otherwise it's just a matter of time until you're blacklisted.

Polaris
  • 712
  • 7
  • 21
0

Try setting $mail->SMTPDebug = 3; to get more info about this issue. I am having a similar issue, but not using Gmail, but an email relay server.