'email@google.com','admin' => 'admin@example.com');$email_to_use = $emails[$select_7];JRequest::setVar('email_to_use', $email_to_use);?>"> How to send email to Multiple Recipients in PHP? - Forums

Forums

How to send email to Multiple Recipients in PHP?

mostlyseven 15 Nov, 2010
Hello there,
I have a dropdown form which is working perfect with the code below. I send it as a BCC. And is working fine. BUT I want to send to multiple (40 to 50) emails if one option is selected eg.
'Salzburg' => [email]'email@yahoo.com[/email],email2@yahoo.com',

I get the following error:
[email]PHPMAILER_RECIPIENTS_FAILEDemail@yahoo.com[/email],email2@yahoo.com

How can you do it? Or is there a solution to get the emails out of database?

Thanks for your help.

Mostlyseven

PS: I have bought the book "ChronoForms 1.3 for Joomla! Site Cookbook" it is great!


<?php
$select_7 = JRequest::getString('select_7', 'admin', 'post');
$emails = array (
'Salzburg' => 'email@yahoo.com',
'Wien' => 'email@google.com',
'admin' => 'admin@example.com'
);
$email_to_use = $emails[$select_7];
JRequest::setVar('email_to_use', $email_to_use);
?>
Max_admin 18 Nov, 2010
Hi,

try to set them as an array instead of a comma separated string:

'Salzburg' => array('email@yahoo.com', 'email2@mmm.com'),


Cheers,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
GreyHead 18 Nov, 2010
Hi mostlyseven ,

It may also be that 40-50 emails is more than the mailer function can handle in one go. You might be better off hand-coding a mailer using a foreach loop to will send individual emails to each adressee.

Bob
mostlyseven 18 Nov, 2010
Hi all,

If I use an array I get following:

SMTP-Fehler! Die folgenden Empfänger sind nicht korrekt:

Warning: trim() expects parameter 1 to be string, array given in \libraries\joomla\mail\helper.php on line 39

In the BCC it says: Array

The code is:
<?php
$select_7 = JRequest::getString('select_7', 'admin', 'post');
$emails = array (
'Salzburg' => array('email1@yahoo.com','email2@yahoo.com'),
'Wien' =>'email3@yahoo.com',
'admin' =>'admin@example.com'
);
$email_to_use = $emails[$select_7];
JRequest::setVar('email_to_use', $email_to_use);
?>


Thanks for your help!

Mostlyseven
mostlyseven 23 Nov, 2010
I set the SITE configuration => server => mailing - to PHP funktion and then it worked with following code:

<?php
$select_7 = JRequest::getString('select_7', 'admin', 'post');
$emails = array (
'Salzburg' =>'email1@yahoo.com,email2@yahoo.com,email3@yahoo.com,email4@yahoo.com,email5@yahoo.com',
'Wien' =>'webmaster@example.com',
'admin' =>'admin@example.com'
);
$email_to_use = $emails[$select_7];
JRequest::setVar('email_to_use', $email_to_use);
?>


Following question remains: since there will be more and more emails to send to, is there a way to get the emails out of a table? What would the code be?

Thank you so much for your help.

Sabine
GreyHead 08 Jan, 2011
Hi Sabine,

Going through some old posts I noticed that I hadn't replied to this.

Yes you can get the emails from the database using a MySQL query to get the data and then a foreach loop to send the emails.

Bob
This topic is locked and no more replies can be posted.