Jump to content

Sending mail to all email addresses in mysql database


NealeWeb

Recommended Posts

I have no idea what im doing wrong but this just isnt working, theres no error messages but im not getting any of the emails. Here is all the code that i had anything to do with editing, i have removed any personal info from it.

 

<?php
$dbhost = 'localhost';
$dbuser = ' ';
$dbpass = ' ';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

mysql_select_db(" ", $conn);

$result = mysql_query("SELECT ****, ********** FROM **** WHERE name='*****'");

while($row = mysql_fetch_array($result))
{
$message =
"<p><u><b><font size=\"5\" color=\"#800080\">********************</font></b></u></p>
<p><b><font color=\"#800080\" size=\"4\">**************************************************</font></b></p>
<p><b><font color=\"#800080\">*********</font></b> <b><font color=\"#333333\">**********</font></b></p>
<p><b><font color=\"#800080\">********</font></b> <font color=\"#333333\"><b>***********</b></font></p>
<p><font color=\"#800080\"><b>*******</b></font> <font color=\"#333333\"><a href=\"***********************************************</a></font></p>
<p> </p>";
}

$query=mysql_query('SELECT `email`,`name` FROM `users`'); //grab emails and names from database
while($row = mysql_fetch_array($query)) //start a loop to send an email to each individual
{
    //mail function with $row['email'] as the email address
    //I'm using phpmailer as an example here - - >
    include_once('phpMailer/class.phpmailer.php');
    
    $mail             = new PHPMailer(); // defaults to using php "mail()"
    
    $body             = $message; //message inside the email
    
    $mail->From       = "**************"; //email address that the email is being sent from
    $mail->FromName   = "*************"; //more in depth for who the mail is from.
    
    $mail->Subject    = "***********************************"; //The subject for the message
    
    //$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    
    
    $mail->AddAddress($row[email], $row['name']);
} 

mysql_close($conn);
?> 

Link to comment
Share on other sites

$query=mysql_query('SELECT `email`,`name` FROM `users`'); //grab emails and names from database

while($row = mysql_fetch_array($query)) //start a loop to send an email to each individual
{
//convert database rows to variables
mail('$email', '$subject', '$message', null,'-finfo@yourdomain.info');
}

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.