getting email from mysql database to phpmailer (1 Viewer)

mdcory

Registered User.
Local time
Today, 02:02
Joined
Sep 28, 2004
Messages
73
Not sure if I am posting this in the right place, sorry if it's not.
I am stuck. Not real familiar with mysql or php but can fiddle my way around. I am trying to set up a script that will get email addresses from the database and insert it to the script and email the addresses it gets. I have the query working, I have it printing out to the page for testing. The mail script also works if I hard code the email address. But if I try using the email addresses from the database it sends me a failure notice email saying that the to field was blank. I have tried about everything that I can think of to make it work. I have included the code that I am using below. I have removed the sensitive info.
Thanks in advance for any help
Matt

PHP:
<?php 
require("class.phpmailer.php");
// Connects to your Database 
mysql_connect("HOST", "USERNAME", "PASSWORD") or die(mysql_error()); 
mysql_select_db("DATABASE") or die(mysql_error()); 

$data = mysql_query("SELECT * FROM phpbirthday WHERE date_format(B_Date, '%m%d') = date_format(now(), '%m%d')
") 
or die(mysql_error()); 
 Print "<table border=0 cellpadding=3>";
while($info = mysql_fetch_array($data)) 
{ 
Print "<tr>";
Print "<td>".$info['Name'] . "</td> ";
Print "<td>".$info['Email'] . "</td> ";
Print "<td>".$info['B_Date'] . " </td></tr>"; 
} 
Print "</table>";
$toemail=$info["Email"];
$mail = new PHPMailer(); 
$mail->IsSendmail(); // telling the class to use SMTP 
$mail->Host = "HOST.COM"; // SMTP server 
$mail->From = "EMAIL@EMAIL.COM"; 
$mail->FromName = "NAME"; 
$mail->AddAddress=($info['Email']); 
//$mail->AddBCC("$display_block"); 
//$mail->AddAddress($info["Email"]);
//$mail->AddEmbeddedImage("../images/cover17.jpg", "my", "cover17.jpg"); 
$mail->IsHTML(true); 
$mail->Subject = "Online"; 

$mail->Body = 'Test'; 
$mail->Body = " 
<table width=\"500\" border=\"1\" align=\"center\" cellpadding=\"3\" cellspacing=\"4\" bordercolor=\"#CCCCCC\" bgcolor=\"#FFFFFF\"> 
<tr><td><a href=\"http://www.mysite.com/comments/unsubscribe.php?unsubscriber=$email_id\">Click here</a> to remove your address from this mailing list</td></tr> 
</table>"; 
$mail->WordWrap = 50; 


if(!$mail->Send()) 
{ 
   echo "Message was not sent"; 
   echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else 
{ 
  $display_block= " meassage sent to $Email\n";

}  
?>
 
Last edited:

Banana

split with a cherry atop.
Local time
Today, 00:02
Joined
Sep 1, 2005
Messages
6,318
Hey, I'd recommend trying DevShed- they have PHP forum as well MySQL forum so they may have people who can help answer your question.

I do know MySQL but PHP, sorry.

Best of luck.
 

mdcory

Registered User.
Local time
Today, 02:02
Joined
Sep 28, 2004
Messages
73
Thanks, I posted over there. I hope someone can help me out. I know it has to be something simple but I just can't figure it out. It's driving me crazy.

Thanks again,
Matt
 

Users who are viewing this thread

Top Bottom