• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Sending out e-mails from MYSQL data

imported_KuJaX

Platinum Member
Hello,

I have a table in one of my MYSQL databases that have quite a few of my contacts information such as their name, email address, browser version, ip address, etc. I want to be able to e-mail all of the people using the e-mail column in the table.

What would be the best way of doing this? I do not want each person to see each others e-mail addresses. Is there an easy way of writing some PHP coding to e-mail a specific message to all of the e-mail column in that table, one by one? Any idea's will be appreciated.
 
Originally posted by: notfred
Do this:

result = "select email from table";
foreach (line in result){
//send email to 'line';
}

I'm not an expert in any programming languages by any means. I am one of those people that can look at some coding that is already done and understand what it is doing.

When you say "select email from table" do you mean to put in the column title of the e-mail column ("email")

Also, foreach (line in result) do you actually put "line in result" in there?

What would be put in the //send email to 'line'; and how does it know what 'line' is?

I dont believe i understand fully. Also what language is that?
 
Originally posted by: KuJaX
Originally posted by: notfred
Do this:

result = "select email from table";
foreach (line in result){
//send email to 'line';
}

I'm not an expert in any programming languages by any means. I am one of those people that can look at some coding that is already done and understand what it is doing.

When you say "select email from table" do you mean to put in the column title of the e-mail column ("email")

Also, foreach (line in result) do you actually put "line in result" in there?

What would be put in the //send email to 'line'; and how does it know what 'line' is?

I dont believe i understand fully. Also what language is that?

PHP is your best bet for ease-of-use with MySQL.

Example:

$query = "SELECT `email_address` FROM `contacts`";
$result = mysql_query($query);
$line = myself_fetch_array($result);
foreach($line) {
echo "The email address contained in this line is: " . $line['email_address'] . "<br />";
}

My above snippet is following the above assumptions:

A database connection has already been established elsewhere in this script.
The table holding the data you want is named "contacts".
The column you want to use is "email_address".

The line beginning with $result queries the mysql engine for the data from the table, sets it to the variable $result.
The line beginning with $line makes an array from the mysql data (setting it to $line) being represented by $result.
The foreach loop cycles through the array, line by line.

I cannot remember the syntax for sending an email from within PHP... so I substituted that command, and instead echo it to the user, primarily so that you can see how to reference the variable you will need to use for the email address.

Search www.php.net for email, and see if you can find the syntax there on how to do what you're wanting. www.php.net is an excellent website to use for quickly looking up and referencing things.
 
I would argue that perl would be better for interfacing, as you don't have to write this into a web application. I do raw smtp stuff with perl all the time.
 
You wouldn't have to write that into a web application, PHP can run from CLI as well. That said, I assumed that his scenario was already on a webserver, and that a PHP script would prolly be easier for a beginner than Perl. But that's just my opinion. I could be very wrong.

 
Back
Top