View Full Version : mail with multiple emails
fastsol1
08-14-2010, 01:53 PM
Ok so I don't understand why this won't work consistently. The code does send the mail, but I randomly won't get 1 2 or all 3 emails. For testing I only have 3 emails in the table with three different addresses. If I try it one time I'll get the first and last email in the list, then next time just the last one and another time only the second one in the list. There seems to be no pattern to what I get. I am using a while loop and have echoed out the emails within the loop to see if it gets all three and everytime it does but still with random results of receiving them. Is there a better way or what. I have been at this for hours and tried a for loop but I really don't understand that and I'm not sure how to use a foreach loop either.
$get_mail = mysql_query("SELECT emaile, name, lname FROM fam_info");
while ($mail = mysql_fetch_array($get_mail))
{
$emaile = $mail['emaile'];
$name = $mail['name'];
$lname = $mail['lname'];
$headers = 'From: System Admin <noreply@domain.com>';
$to = "$emaile";
$from = "Posted Events for Cousins@amewebdesigns.com/cousins";
$subject = "A cousins event has been posted for you to attend!";
$signature = "Thank you from all your cousins!";
$body = "Dear $name $lname,\r\n You have been invited to attend the event \"$title\" set to be held on $eventdate.\r\n";
if ($rsvp=="yes")
{
$body .= "RSVP's have been requested of you so please logon to the website and submit your RSVP.\r\n";
}
$body .= "For full details about the event please logon to the website.\r\n\r\n";
$body .= "$signature";
mail ($to, $subject, $body, "From: $from");
}
djr33
08-14-2010, 03:52 PM
What is the exact output of this code?
$get_mail = mysql_query("SELECT emaile, name, lname FROM fam_info");
while ($mail = mysql_fetch_array($get_mail))
{
$emaile = $mail['emaile'];
echo $emaile;
}
Is that correct?
fastsol1
08-14-2010, 06:42 PM
What is the exact output of this code?
$get_mail = mysql_query("SELECT emaile, name, lname FROM fam_info");
while ($mail = mysql_fetch_array($get_mail))
{
$emaile = $mail['emaile'];
echo $emaile;
}
Is that correct?
It showed me all the emails it sent to and they were the ones in the db.
I figured it out. Seemed to be a header issue. I had tried several things with the headers before I got it consistant. Here is the code I ended up with.
$get_mail = mysql_query("SELECT emaile, name, lname FROM fam_info");
while ($the_mail = mysql_fetch_array($get_mail))
{
$emaile = $the_mail['emaile'];
$name = $the_mail['name'];
$lname = $the_mail['lname'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Posted Events for Cousins <jd@amewebdesigns.com>' . "\r\n";
$to = "$emaile";
$subject = "A cousins event has been posted for you to attend!";
$signature = "Thank you from all your cousins!";
$body = "Dear $name $lname,<br><br>You have been invited to attend the event \"$title\" set to be held on $eventdate.<br>";
if ($rsvp=="yes")
{
$body .= "RSVP's have been requested of you so please logon to the website and submit your RSVP.<br>";
}
else{}
$body .= "For full details about the event please <a href='http://amewebdesigns.com/cousins'>logon</a> to the website.<br><br>";
$body .= "$signature";
mail($to, $subject, $body, $headers);
}
fastsol1
08-16-2010, 10:32 PM
So a little continuation on this. I thought I had it licked earlier but maybe not. At this point I don't really think it's the script specifically that is causing the lack of getting the emails. I host with Godaddy and after calling them they say that I might be tripping their email flood control. That seemed pretty shitty to me if it trips at 3 emails at a time. I would think maybe at a 100 or something but 3, really guys.
So they suggested using their email accounts and then setting up a CC for every email address I ultimately want the email sent to. I would then send a single email to that account and their server would CC to all the contacts I put in there. Now for the situation I am doing right now that maybe fine since it's just a simple family site, but that is far from dynamic for a site that has new users and emails being added all the time, cause I would have to manually ad the new email addresses to the Godaddy account.
Anyone have any other suggestions or know more about this flood control thing so I can yell at Godaddy for a better answer.
djr33
08-17-2010, 05:14 PM
If godaddy is blocking it, I don't think there really are any suggestions. Perhaps get a better host. I used godaddy for a few years, but I've now switched and I really don't regret it... so that's my suggestion... haha.
fastsol1
08-17-2010, 08:07 PM
yeah that's what I'm starting to realize. So much for being the "world's #1", yeah if you don't want to do anything even semi-complex. this isn't the first time I've had to try a figure a work-around for their dumb servers.
I have even tried Rmail() but even that has been inconsistent in results, so I'm at a loss.
fastsol1
08-18-2010, 04:20 AM
Ok so Godaddy emailed me saying they have checked my script and found an issue on their side with their mail system and have since fixed that, now they don't tell me what that was or if it's really solved my issue. The other thing they said was that their server only allows so much being sent at one time and if I could limit the sending of the emails to one per second that should take care of the issue completely. So how do you limit that in a script?
djr33
08-18-2010, 04:39 AM
Yes, that sounds like a confusing answer.
You can use sleep() in PHP to delay processing. However... this will delay processing. That is, the page will take 3 seconds to load (3 emails), plus whatever time it already takes.
There is no way to use PHP to do this differently. The only other option would be to create a mail queue.
You could store files or database entries with each email message (to, subject, body, headers) then run a cron job (every second? every 10 seconds?) to send an email from the queue. Most of the time, it might find that there are no emails to send and not send anything. Otherwise, it would continue on this loop until all of the emails were sent.
This might create a slight delay in sending the messages, but usually, unless you have a VERY busy site, no more than a minute or two.
One other problem with this is that if two users try to send an email at the same time, it would be overloaded. So for this also, the queue idea may help.
However, technically this is not actually more efficient: it would require running an extra script and sending the same emails. It just would look nicer to godaddy's restrictions.
Again, a new host may be the right answer. And you could ask the new host about email restrictions.... it's important to know that if you plan to send a lot.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.