Pain Posted November 28, 2013 Share Posted November 28, 2013 Hello. I have a problem. I am trying to send approximately 1200 emails at once. Each email has to be retrieved from the database. <?php ... $query = mysql_query("SELECT * FROM mass_subscribers"); while($row = mysql_fetch_assoc($query)) { $email = $row['email']; $name = $row['name']; $mail = new SendGrid\Mail(); $mail-> setTo($email)-> setFrom('me@yahoo.com')-> setSubject($subject)-> setText($message)-> setHtml($message); $sendgrid->web->send($mail); } ... ?> Problem is the loop gets executed 1200 times which causes 500 error. Is there any way around this? Thank you, any advice appreciated guys. Link to comment https://forums.phpfreaks.com/topic/284368-sending-massive-amount-of-emails/ Share on other sites More sharing options...
banfw001 Posted November 28, 2013 Share Posted November 28, 2013 Could you not import your email addresses into a list array, then send the email from the list array Link to comment https://forums.phpfreaks.com/topic/284368-sending-massive-amount-of-emails/#findComment-1460566 Share on other sites More sharing options...
Pain Posted November 28, 2013 Author Share Posted November 28, 2013 Are you referring to the php's list() function? Can you explain this in more detail please? Thank you. Link to comment https://forums.phpfreaks.com/topic/284368-sending-massive-amount-of-emails/#findComment-1460568 Share on other sites More sharing options...
Pain Posted November 28, 2013 Author Share Posted November 28, 2013 I did put all the emails into an array. $email = array(); $name = array(); $query = mysql_query("SELECT * FROM test"); while($row = mysql_fetch_assoc($query)) { $name[] = $row['name']; $email[] = $row['email']; } $email = implode(",", $email); $name = implode(" ", $name); This is now the main problem as the email gets sent to the first recipient in the database only. $mail = new SendGrid\Mail(); $mail-> addTo($email)-> setFrom('test@test.com')-> setSubject($subject)-> setText($message)-> setHtml($message); $sendgrid->web->send($mail); PHPs built-in mail () function works properly, but i have to use sendgrid for this one. I'm lost:/ Link to comment https://forums.phpfreaks.com/topic/284368-sending-massive-amount-of-emails/#findComment-1460580 Share on other sites More sharing options...
jazzman1 Posted November 29, 2013 Share Posted November 29, 2013 Can I see the format of all emails after imploding? while($row = mysql_fetch_assoc($query)) { $name[] = $row['name']; $email[] = $row['email']; } $email = implode(",", $email); echo $email; Link to comment https://forums.phpfreaks.com/topic/284368-sending-massive-amount-of-emails/#findComment-1460584 Share on other sites More sharing options...
Pain Posted November 29, 2013 Author Share Posted November 29, 2013 Email@yahoo.com,email2@yahoo.com,email3@yahoo.com etc. Link to comment https://forums.phpfreaks.com/topic/284368-sending-massive-amount-of-emails/#findComment-1460607 Share on other sites More sharing options...
jazzman1 Posted November 29, 2013 Share Posted November 29, 2013 Try to add manually more than one email. Something like - <?php $mail = new SendGrid\Mail(); $mail-> addTo('foo1@bar.com','foo2@bar.com','foo3@bar.com')-> setFrom('me@bar.com')-> setSubject('Subject goes here')-> setText('Hello World!')-> setHtml('<strong>Hello World!</strong>'); // send emails $sendgrid-> web-> send($mail); ?> Link to comment https://forums.phpfreaks.com/topic/284368-sending-massive-amount-of-emails/#findComment-1460619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.