Ray Ray - 1 year ago 57
SQL Question

PHP - How to send emails to address on MYSQL?

How can I send emails to all emails on my database? E.g. here is my format of MYSQL.

MYSQL -- Table = users --- column = email. I need to send emails to everyone of the email on column "email".

Answer Source

Simple ready to use PHP script for sending mail from mysql data


mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());

$result = mysql_query("SELECT email FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {

function sendMail($to){
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download