I'm trying to get the emails which have "all" under "selectedoption" column from MySQL database table and then sending emails to them.
Here is my PHP code:
<?php
include("config.php");
$con = mysql_connect($opt_host, $opt_user, $opt_pw);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("databasename_",$con);
$result = mysqli_query($con,"SELECT * FROM optins");
if(mysql_num_rows($selectedoption == "all")
{
while($selectedoption_result = mysql_fetch_array($selectedoption))
{
$opt_name = "Name: Advisor\n"
$opt_header = "From: $MYEMAILADDRESS\n"
$opt_subject = "Test";
$opt_email_to = "$email";
$opt_message = "Hey $name\n"
. "\n"
. "Message.\n"
. "\n"
. "\n"
. "Click Here To Unsubscribe.";
@mail($opt_email_to, $opt_subject ,$opt_message ,$opt_header, $opt_name) ;
}
}
echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Email Sent Out</font></p>");
?>
What is the right way to select a column field from MySQL table and send emails to the recipients associated with that column?