jopo Posted October 10, 2008 Share Posted October 10, 2008 I am trying to create a php script that emails all the rows of a table at certain time intervals using cron. How do I pass in all the rows to the mail function? I can only seem to get the last row emailed to me. Link to comment https://forums.phpfreaks.com/topic/127850-php-mail/ Share on other sites More sharing options...
aebstract Posted October 10, 2008 Share Posted October 10, 2008 We're gonna most likely need to see your code that you're working with. It'd be pretty hard to tell why all of your rows aren't sending without seeing what you are doing. Link to comment https://forums.phpfreaks.com/topic/127850-php-mail/#findComment-661900 Share on other sites More sharing options...
jopo Posted October 10, 2008 Author Share Posted October 10, 2008 Yikes . Well, this is what I have so far but do not think I am approaching the solution correctly. while($row=mysql_fetch_array($result)){ $message= "Name: ".$row['name']; echo $message; } $email="***@***.com"; $to = $email; $subject = "Test"; mail($to, $subject, $message); Link to comment https://forums.phpfreaks.com/topic/127850-php-mail/#findComment-661907 Share on other sites More sharing options...
kenrbnsn Posted October 10, 2008 Share Posted October 10, 2008 You are overwriting the value of $message each time through the loop. Here's how I would do this: <?php $tmp = array(); while($row=mysql_fetch_array($result)){ $tmp[] = "Name: ".$row['name']; } $email="***@***.com"; $subject = "Test"; mail($email, $subject, implode("\n",$tmp)); ?> Ken Link to comment https://forums.phpfreaks.com/topic/127850-php-mail/#findComment-661913 Share on other sites More sharing options...
jopo Posted October 10, 2008 Author Share Posted October 10, 2008 Thanks! Link to comment https://forums.phpfreaks.com/topic/127850-php-mail/#findComment-661915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.