Viewed   80 times

I know there are a few similar questions to this but I just can't get it working.

Ok, I have a list of emails grabbed from my database in a variable called $emailList. I can get my code to send an email from a form if I put the variable in the $to section but I cannot get it to work with bcc. I've even added an email to the $to incase it was that but it doesn't make a difference.

Here is my code.

$to = "name@mydomain.com";
$subject .= "".$emailSubject."";
$headers .= 'Bcc: $emailList';
$headers = "From: no-reply@thepartyfinder.co.ukrn" . "X-Mailer: php";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';

if (mail($to, $subject, $message, $headers)) {
    $sent = "Your email was sent!";
} else {
    $sent = ("Error sending email.");
}

I've tried both codes:

$headers .= 'Bcc: $emailList';

and

$headers .= 'Bcc: '.$emailList.';

It's not that the emails aren't separated because they are. I know they are because it works if I put $emailList in the $to section.


I Should add, ignore the $message bits and the HTML stuff. I've not provided all of that so that is why it's missing from this code.

 Answers

1

You have $headers .= '...'; followed by $headers = '...';; the second line is overwriting the first.

Just put the $headers .= "Bcc: $emailListrn"; say after the Content-type line and it should be fine.

On a side note, the To is generally required; mail servers might mark your message as spam otherwise.

$headers  = "From: no-reply@thepartyfinder.co.ukrn" .
  "X-Mailer: phprn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
$headers .= "Bcc: $emailListrn";
Sunday, December 25, 2022
2

The BCC addresses are not stripped off at the destination email server. That's not how it works.

How SMTP actually works

  • The sender will send a list of RCPT TO commands to the SMTP server, one for each receiver email addresses, and this command does not distinguish whether the receiver is a normal To, CC or BCC type receiver.
  • Soon enough after calling the command that tells the SMTP server who's the sender, who's the server, and everything else, only then the sender will call the DATA command, in which will contain the content of the email - which consist of the email headers and body - the one that are received by email clients. Among these email headers are the usual from address, to address, CC address.
  • The BCC address is not shown to the receiver, simply because it's not printed out under the DATA command, not because the destination SMTP server stripped them away. The destination SMTP server will just refer to the RCPT TO for the list of email addresses that should receive the email content. It does not really care whether the receiver is in the To, CC or BCC list.
    Update (to clarify): BCC email addresses must be listed in the RCPT TO command list, but the BCC header should not be printed under the DATA command.

Quoting a part of the RFC that I think is relevant to your case:

Please note that the mail data includes the memo header items such as Date, Subject, To, Cc, From [2].

Rolling out your own email sender

A couple of years ago, I frankly think, is quite a long time back to assume that you still memorize end-to-end of RFC 821. :)

Monday, October 3, 2022
5

PHPMailer is the best to use for email.

checkout some below links which will help you in future also:

  1. File Attachments in PHP Mail with PHPMailer
  2. php mailer attachments
  3. attachments using phpMailer
  4. PHPMailer Tutorial
  5. A Simple Example : Sending Email with Attachment Using Phpmailer
  6. PHP send email with multiple attachments with PHPMailer with SMTP Authentication
  7. Sending email with multiple attachments with PHP

may this help you.

Saturday, November 5, 2022
 
3

Well I came up with this solution similar to the PDO one. Are there any unforeseen problems with running this as a cron job?

<?php
$con = mysql_connect("localhost","root","123456");
$throttle = 0;
$batch = 50;
$pause = 10; // seconds

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("maildb", $con);

// Message Table
$MSGresult = mysql_query("SELECT * FROM msgs");

// User Table
$USERresult = mysql_query("SELECT * FROM members");

while($MSGrow = mysql_fetch_array($MSGresult))
  {
    while($USERrow = mysql_fetch_array($USERresult))
        {
          mail($USERrow['email'],$MSGrow['subject'],$MSGrow['body']);
          $throttle += 1;
          if ($throttle > $batch ) { sleep($pause); $throttle = 0;} 
        }
    mysql_data_seek($USERresult,0);
  }

mysql_close($con);
?> 
Thursday, December 22, 2022
 
chouser
 
1

Generate a single email per recipient. Use the To field instead of BCC to make it personal.

Advantages

  • The mail queue will accurately reflect what is happening.
  • You can distribute the load to multiple email servers.
  • You can personalize the "To" "Subject" "Body" etc.
  • You can use tracking URL's.
  • Mail servers often have a BCC limit per message. You will not hit a limit if you send a single message at a time.
  • BCC emails typically remain in the queue until all deliveries are complete. It is rare, but we have experienced (with the latest qmail) that sometimes a single recipient will respond with an error that confuses the mail server to send it again, fail, again, fail...until we remove it from the queue. This gets people very upset.

Disadvantages

  • PHP script has to work harder to generate the individual requests.

There are surely other advantages and disadvantages, but that is the list I follow.

UPDATE: Regarding the PDF attachment, I would recommend providing a download link unless it is crucial to include it with the email.

  • PDF attachments make an email look more suspicious to spam/virus scanners, because spam is known to try to exploit vulnerable versions of Acrobat. Those PDF attachments might make your newsletter more likely to end up in the recipient's Spam folder.
  • Large PDF's (1+mb) are not friendly to people checking their email with slow connections or constrained devices such as smartphones.
  • A link is much smaller than the attachment. You will save upwards to 13GB of bandwidth if you leave off that 5MB attachment!
Tuesday, October 4, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :