FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


SQL to Mail() for a mailing list





Relentless
Hi, I have an SQL data base. Well..., I'm going to have an SQL database soon...

But the I will have an email column for all the users. I have also found this:
http://css-tricks.com/2866-sending-nice-html-email-with-php/

And thought hey! I could make a pretty sweet mailing list. But how do I send an email to all my users on the database the same email without exposing the email addresses to everyone else in the "To:" header?

I would like to be able to have the email say:
Code:
 
To: Your@Email.com
From: maillist@mydomain.com
Subject: Did you know this email is awesome?

Message: Dear $username plus an HTML email I shall make.


I know enough of PHP to make the rest it's just collating the email address and sending a mail function to them all.
Peterssidan
I think you will have to call the mail function once for each receiving address.
sonam
Actually you need to call mail function for each mail and in that case my suggestion is for loop.

Code:
$mails = count($mails_accounts);
for($i=0; $<$mails; $i++) {
    mail($to, $subject, $content, $headers);
}

But be careful with this code because some servers have limitation for sending mails defined by number. Spam protection Very Happy

Sonam
Relentless
sonam wrote:
Actually you need to call mail function for each mail and in that case my suggestion is for loop.

Code:
$mails = count($mails_accounts);
for($i=0; $<$mails; $i++) {
    mail($to, $subject, $content, $headers);
}

But be careful with this code because some servers have limitation for sending mails defined by number. Spam protection Very Happy

Sonam


Sonam once again you are awesome.
But how do I call the sql database into this? Embarassed

My script is for a login system and calls my details like so:
Code:

<head><php>$rs_settings = mysql_query("select * from users where id='$_SESSION[user_id]'");</php>
<head>
<body>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) { ?>

<? echo $row_settings['user_email']; ?>

<? } ?>
</body>


So I will need a new script to access the database to use your script Embarassed
sonam
Independent of what you need from sql base. For example if you need name, address and email then you can create variables.
I assume ONLY you will use this script not anyone others. My suggestion is insert it in some password protected folder.

Ok, for me the simplest way is select all users ID from sql and insert in one array. Count this ID's in array and run for loop. Then under for loop:
Code:

$rs_settings = mysql_query("select * from users where id='$ids[$i]'");
while ($row_settings = mysql_fetch_array($rs_settings)) {

$to = $row_settings['user_email'];
$name = $row_settings['user_name'];
$address = $row_settings['user_address'];

}


I didn't tested this because I haven't time today. If is not working I am sorry.

Sonam
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.