sniperscope Posted May 27, 2010 Share Posted May 27, 2010 Hi gurus. I am trying to write some sort of mail magazine system. I am getting registered mail addresses and assign into an array and try send them but my code send only the first record of array. What is wrong with this code? Any help will be great appreciate. Regards Note: my hosting is on win server. $GetMailList = mysql_query("SELECT mailaddress FROM maillist WHERE GroupID = '$_POST[GrpID]' ORDER BY id ASC", $cn); while($i = mysql_fetch_array($GetMailList)){ $to[] = $i['MailAdd']; // this is array for let's 20 mail addresses } require_once('Rmail.php'); $mail = new Rmail(); $mail->setFrom('Weeklynews <[email protected]>'); $mail->setSubject($title); $mail->setText($body); $result = $mail->send($to[]); Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/ Share on other sites More sharing options...
mrMarcus Posted May 27, 2010 Share Posted May 27, 2010 you need to select 'MailAdd' from your database table as well. ... SELECT mailaddress, `MailAdd` FROM maillist ... and this: $result = $mail->send($to[]); needs to be: $result = $mail->send($to); notice how i removed the [] from $to Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1063937 Share on other sites More sharing options...
sniperscope Posted May 27, 2010 Author Share Posted May 27, 2010 oppsss sorry it is my fault. it should like SELECT MailAdd FROM Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1063938 Share on other sites More sharing options...
mrMarcus Posted May 27, 2010 Share Posted May 27, 2010 i'm assuming the mail class you're using will handle an array of email addresses? 'cause that's what you're sending it. Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1063939 Share on other sites More sharing options...
jcbones Posted May 27, 2010 Share Posted May 27, 2010 1. Are you sure you are getting multiple email addresses from the database? 2. It is either $i['mailaddress'] or you need to select MailAdd from the database. <<Answered 3. I assume $mail->send() supports array's. <<Asked. 4. Does your host allow multiple emails? Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1063941 Share on other sites More sharing options...
sniperscope Posted May 27, 2010 Author Share Posted May 27, 2010 mrMarcus thank you for your interest i dont know why, but i think array has problem because orriginal code was like below and i edited it. here is the original code of Rmail.php class require_once('Rmail.php'); /** * Now create the email it will be attached to */ $mail = new Rmail(); $mail->setFrom('Richard <[email protected]>'); $mail->setSubject('Test email'); $mail->setCc('[email protected]'); $mail->setBcc('[email protected]'); $mail->setText('Sample text'); $result = $mail->send(array('[email protected]')); instead of sending one mail to [email protected] , i put all mails into $to[]. Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1063942 Share on other sites More sharing options...
sniperscope Posted May 27, 2010 Author Share Posted May 27, 2010 @jcbones; the original class was like this: $result = $mail->send(array('[email protected]')); do you think array causing this problem? Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1063943 Share on other sites More sharing options...
jcbones Posted May 28, 2010 Share Posted May 28, 2010 The only way to tell if the array is causing a problem, is to view the class. Is the function send() set up to take an array? If it isn't, then the function mail() is trying to send an email to the address of Array. Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1064764 Share on other sites More sharing options...
sniperscope Posted May 29, 2010 Author Share Posted May 29, 2010 thanks for you help guys. I solved my problem. Solution was very simple. I sent 200 mail at same time to same mail server (let's say hotmail) and server was accept first mail then figured out rest 199 mails are spam. That's why my mails did not reach all subscribers. I passed this problem with sleep(60); Now all mails deliver to users. Thank you very much for all of you who interested. PS: how can i change header to SOLVED ? Link to comment https://forums.phpfreaks.com/topic/203045-mail-not-looping/#findComment-1064909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.