General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 25th, 2003, 07:06 AM
ozwold ozwold is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: London UK
Posts: 4 ozwold User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sending emails from DB

Hi,

I'm having some trouble trying to send mail out when I retrieve the emails from a DB. I really don't know whats going on, but I have tested this on 'normal' email and this works fine but when it comes to a email from a DB it doesn't work.

PHP Code:
 $emails=mysql_query("select email from email_list");

while (list(
$DBemail)=mysql_fetch_row($emails))
{
    
# recipients
    
$to "$DBemail" '<' $DBemail '>';

    
# this works well
    #$to = 'test' . '<test@hotmail.com>';

    # subject 
    
$subject whatever;
    
    
$message 'hello';

    
/* To send HTML mail, you can set the Content-type header. */
    
$headers  "MIME-Version: 1.0\r\n";
    
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
  
    
# now mail it!!
    
mail($to,$subject,$message,$headers);



The problem I'm trying to get around is the $to variable, the line of code beneath works well, so I don't know how to get round the problem.

Do you think I should create some sort of function?

Any suggestions?

Thanks

Reply With Quote
  #2  
Old September 25th, 2003, 07:45 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Have you verified that $DBemail is getting set properly? Try doing a print statement before sending the mail. Also, you don't need to put the variable in double quotes. I don't know that it'll hurt anything, but it's unnecessary and seems a little weird.

Reply With Quote
  #3  
Old September 25th, 2003, 07:55 AM
ozwold ozwold is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: London UK
Posts: 4 ozwold User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks...

Hi dhouston,

I've tried all sorts believe you me!!

I've approached this a different way, by getting all the emails into an array and then creating a function to send them off...

have a look...

PHP Code:
# email list
  
$emails=mysql_query("select email
                       from email_list"
);
  while (list(
$DBemail)=mysql_fetch_row($emails))
  {
    
$tot_emails[]=$DBemail;
  }
  
  function 
sendmails($arr_emails,$sub,$mess,$head)
  {
    foreach (
$arr_emails as $value)
    {
      
$to "$value";
      echo 
$to;
      
mail($to,$sub,$mess,$head);
    }
  }

sendmails($tot_emails,$subject,$message,$headers); 


Works okay...


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Sending emails from DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT