Asked  7 Months ago    Answers:  5   Viewed   34 times

I am currently writing a music blog. The administrator posts a new article every 2-3 days. Once the administrator posts an article, a mass email will be sent to around 5000 subscribers immediately.

What is the best way to implement the mass mail feature?

Does the following function work?

function massmail() 
  $content = '...';
  foreach ($recipients as $r) {
    $_content = $content . '<img src="http://xxx/trackOpenRate.php?id='.$r.'">';
    mail($r, 'subject', $_content);

Another question: If all 5000 subscribers are using Yahoo Mail, will Yahoo treat it as a DDOS attack and block the IP address of my SMTP server?



First off, using the mail() function that comes with PHP is not an optimal solution. It is easily marked as spammed, and you need to set up header to ensure that you are sending HTML emails correctly. As for whether the code snippet will work, it would, but I doubt you will get HTML code inside it correctly without specifying extra headers

I'll suggest you take a look at SwiftMailer, which has HTML support, support for different mime types and SMTP authentication (which is less likely to mark your mail as spam).

Wednesday, March 31, 2021
answered 7 Months ago

The vast majority of time spent sending an email is the SMTP communication between your web server and the SMTP server it is talking with.

Both scenarios are likely to be equivalently fast.

If you need to increase performance, look into having multiple threads sending to different email addresses concurrently.

Wednesday, March 31, 2021
answered 7 Months ago

I'd recommend using the third party mailing service Silverpop, or something like it. We've used them for a few years and have been fairly satisfied. They already have relationships with the major email clients (AOL, Yahoo!, Gmail, etc.) and they do a good job of telling you if the stuff you're sending is likely to be classified as SPAM.

They have a fairly extensive API that uses XML HTTP/HTTPS requests that can tie in to existing systems. You can use it to remotely trigger emails, schedule mailings, customize email contents, set up, manage and query huge lists of recipients, run batch processes, etc.

It isn't a perfect service, but compared to a lot of others out there, they do pretty well. I have had very few complaints about them thus far.

Wednesday, March 31, 2021
answered 7 Months ago

After almost giving up, finally got it to work. Its a combination of few things linked here and suggested. This post on github html2pdf helped a bit also.

I'm posting it here as none of the examples worked for me, took me two days to find what works for me and my interment. Hope it helps someone.

window.onload = function pdfDivload (){
let el = document.getElementById('printableArea');
let opt = {
    margin:       1,
    filename:     'myfile.pdf',
    image:        { type: 'jpeg', quality: 0.98 },
    html2canvas:  { scale: 2 },
    jsPDF:        { unit: 'in', format: 'A4', orientation: 'portrait' }

html2pdf().set( opt ).from( el ).toPdf().output('datauristring').then(function( pdfAsString ) {
    let data = {
        'fileDataURI': pdfAsString,
    $.post( "../prog/mail.php", data);
    console.log( data );
} );


  if (isset($_POST['fileDataURI'])) {

                $pdfdoc         = $_POST['fileDataURI'];

            $b64file        = trim( str_replace( 'data:application/pdf;base64,', '', $pdfdoc ) );
            $b64file        = str_replace( ' ', '+', $b64file );
            $decoded_pdf    = base64_decode( $b64file );
            //file_put_contents( $attachment, $decoded_pdf );

            $mail = new PHPMailer;
            $mail->setFrom( '', 'website' );
            $mail->addAddress( '', 'OdedTa' );
            $mail->Subject  = 'First PHPMailer Message';
            $mail->Body     = 'Hi! This is my first e-mail sent through PHPMailer.';
            $mail->addStringAttachment($decoded_pdf, "nalog.pdf");
            $mail->isHTML( true );
Saturday, May 29, 2021
answered 5 Months ago

You can loop it 200 times with few problems I would imagine, although it will be much slower than a custom mailer or a package set up properly to handle that.

The end result depends on many factors. The main thing you'll want to make sure of is that you use set_time_limit() to give the script enough time to do the work. Offloading the work into some kind of queue that's serviced by a cron script can make life easier on you as well, as keeping PHP scripts running for a long time will bring up other resource problems.

Back in the day, I used to send about 50,000 emails to a subscriber newsletter using PHP's mail function and a RedHat server with Exim installed. It would take 4-6 hours with the custom script I had running. There was nothing efficient about it, but it did the job.

Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :