Jump to content

Mail a set of addresses from a MYSQL result


woolyg

Recommended Posts

Hi all,

 

I'm populating a field in MYSQL that collects email addresses for a certain topic and saves them like this:

 

mail1@mail.com|emailaddress2@mail.com|email3@email.com

 

 

- Basically what I'd like to do is explode the data, and set up a mailer from PHP that informs each of the addresses individually that there has been an update to the topic.

 

I *don't* want each of the mail addresses to be visible to all the recipients on the list, so simply inserting the data into the TO: field won't do, because then all the addresses are visible, causing security concerns.

 

I tried doing this:

 

<?php


//Send a mail to the mailing list
$get_mailing_list = mysql_query("SELECT mailing_list  FROM table WHERE post_id='$post_id'");
$runget_mailing_list = mysql_fetch_assoc($get_mailing_list);
$mailing_list = $runget_mailing_list['mailing_list'];


while($rad=explode('|',$mailing_list)){

$reciever=$rad['mailing_list'];


$subject = " Reply to a posting";
$message = "
A reply has been posted to a posting you are tracking.

Have a look here : [url of reply]

No need to reply to this email.

Thanks!


";
$from = "myemail@site.com";
$headers = "From: $from";

mail($reciever,$subject,$message,$headers);
}

?>

 

..but something happened server-side when it tried to carry out the command and brought the CPU usage up to 100%. Has anyone done this before, or could you give me any pointers?

 

All info appreciated.

Woolyg.

 

 

 

 

Link to comment
Share on other sites

you cant just run a loop like that... a loop have to have an end ohterwise it will never stop and therefore your CPU goes crazy... also if you are storing the mails in a database anyways, then do it like this instead:

 

mail_id - 1 - mail: test@test.com

mail_id - 2 - mail: test@test.com

mail_id - 3 - mail: test@test.com

mail_id - 4 - mail: test@test.com

 

and so on... then you can do a loop on your query for that mail table..

 

 

Link to comment
Share on other sites

OK, thanks for letting me know about the CPU usage!

 

I don't fully understand what you mean to do with the information - do you mean to create new fields for mail_id1, mail_id2 etc? That will not work, as it's not known how many mail addresses will be added to the list, it could be 1, it could be 100..

 

How do you reckon I should do it? Thanks for your input so far..

 

Cheers,

Woolyg

 

 

Link to comment
Share on other sites

I think this will work.

 

<?php
$get_mail_address = mysql_query("SELECT mailing_list FROM table_name WHERE post_id = '$post_id'");
$row_mail_addresses = mysql_fetch_assoc($get_mail_address);
$number_rows = mysql_num_rows($get_mail_address);

if($number_rows > 0) {

$mail_address = explode('|', $row_mail_addresses['mailing_list']);

foreach($mail_address as $address) {

$subject = " Reply to a posting";
$message = "
			A reply has been posted to a posting you are tracking.

			Have a look here : [url of reply]

			No need to reply to this email.

			Thanks!
";

$from = "myemail@site.com";
$headers = "From: $from";

mail($address, $subject, $message, $headers);

}

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.