Forum Moderators: coopster
To begin with, I looped through sending a mail to each recepient, which worked fine for small numbers, but large number causes a timeout.
I therefore changed it to this:
<snip>
$query = "SELECT * FROM mailing_list;";
$result = (mysql_query($query));
$no_entries = mysql_num_rows($result);
$subject = $_POST['subject'];
$contents = $_POST['contents'];
// post it to me initially
$to = "me@my.dns.uk";
// create the rest of the mail header
$headers = "From: me@my.dns.uk\r\n";
$headers .= "Reply-To: me@my.dns.uk\r\n";
$headers .= "Return-Path: me@my.dns.uk\r\n";
// now BCC it to everyone else
$headers .= "BCC: ";
$x=0;
while ($row=mysql_fetch_assoc($result)) {
if ($x==0) {
$headers .= $row['address'].",";
$x++;
} else if ($x==1) {
$headers .= $row['address'];
$x++;
}
$headers .= ",".$row['address'];
}
$headers .= "\r\n";
// we will need an 'unsubscribe' footer
$footer = "Please note: If you wish to unsubscribe, click on the following web link:";
$y = "\n------------------------------------------\n\n";
$y .= $footer."\nhttp://my.url.uk/unsubscribe.php?ID=".$row['ID']."\n";
$y .= "or email me@my.dns.uk with the subject \"Unsubscribe\".";
$y .= "-------------------------------------------\n\n";
// put the body of the mail together
$email = $contents.$y;
// now send it
if (mail($to,$subject,$email,$headers))
echo 'The email was successfully sent.';
else
echo "Sorry, there was an error, the message has not been sent";
<snip>
Any ideas?
Thanks
Andy
Going back to your original method you might want to look at opening a socket connection to sendmail. There's a very interesting example in the user contributed notes [php.net] on the php web site by grey at greywyvern dot com.
You could try to make a for-loop which reads 10 adresses, sends out a mail() using bcc:, marks these 10 as sent and then calls itself (with Javascript or header()) to repeat the same procedure for the next 10 entries of your list.
Ad
set_time_out(0);
with my while loop, which seems to work, but gives me this message:
Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command. in C:\Inetpub\wwwroot\WEDC_Intra\do_email.php on line 97
Line 97 is the mail() function
Any ideas?
And Bcolflesh, I will take a look at PHPMailer, thanks
...the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP. PHP < 4.3 only supported the Cc: header element (and was case-sensitive). PHP >= 4.3 supports all the mentioned header elements and is no longer case-sensitive.
So in your example you're putting thousands of addresses in the bcc. I'm sure there must be a limitation on the length of the mail header.
I would send each email individually. There are a couple of reasons:
1.some mail filters treat an email where you have a couple of thousand recipient addresses as spam
2.some filters treat an email with "To: undisclosed recipient" as spam
3.If you send them seperately, everyone gets an email addressed only to him - looks a lot nicer.