| 
	
 | 
 Posted by jpyers@gmail.com on 12/28/07 11:05 
On Dec 24, 5:50 am, paul...@excite.com wrote: 
> On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba- 
> 
> 
> 
> escomposlinux.-.punto.-.org> wrote: 
> > paul...@excite.com wrote: 
> > > On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba- 
> > > escomposlinux.-.punto.-.org> wrote: 
> > >> paul...@excite.com wrote: 
> > >> >   while ($row = mysql_fetch_array($result)) { // puts the values into 
> > >> > $row 
> > >> >     print $row->editorialdate; 
> > >> >     print $row->editorialname; 
> > >> >     print $row->editorialcomments; 
> > >> >   } 
> > >> [...] 
> > >> > $txt = "$row[0] \n\r\n\rPLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT 
> > >> > A VALID EMAIL ADDRESS"; 
> > >> > $headers = "From: Daily_Prod._Rep...@company.com"; 
> > >> > mail($to,$subject,$txt,$headers); # <--- sends the email 
> > >> [...] 
> > >> > all I get is a blank email with no data in it from my database. 
> 
> > >> > Anyone have any ideas? 
> 
> > >> I'm not very sure *grin*, but maybe it's because you're printing the data 
> > >> instead of storing it in the variable that will be fed to mail() ... 
> 
> > > How would I store it? 
> 
> > Geez. 
> 
> > $txt = ''; 
> > while ($row = mysql_fetch_array($result)) { 
> >  $txt .= $row->editorialdate; 
> >  $txt .= $row->editorialname; 
> >  $txt .= $row->editorialcomments;} 
> 
> > (snip) 
> > mail($to,$subject,$txt,$headers); 
> 
> > -- 
> > ---------------------------------- 
> > Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org- 
> 
> > Proudly running Debian Linux with 2.6.22-3-amd64 kernel, KDE 3.5.8, and PHP 
> > 5.2.4-2 generating this signature. 
> > Uptime: 19:39:46 up 29 days,  5:55,  4 users,  load average: 0.75, 1.34, 
> > 1.05 
> 
> I still can not get this to work...I've added your changes and still 
> get a blank email. 
> 
> Generating and emailing report for: 
> <?php 
> $today = date("M j, Y,"); 
> echo $today; 
> 
> $host="localhost"; 
> $user="root"; 
> $pass=""; 
> $db="productiondb"; 
> $con = mysql_connect($host, $user, $pass); 
> $txt = ''; 
> 
> if (!$con) 
>   { 
>   die('Unable to connect: ' . mysql_error()); 
>   } 
> mysql_select_db($db, $con) or die('Unable to connect: ' . 
> mysql_error()); 
> 
> $sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%' "; 
> 
> $result = mysql_query($sql,$con); // actually runs the query 
> 
> if (mysql_num_rows($result)) { // if there are results 
>   while ($row = mysql_fetch_array($result)) { // puts the values into 
> $row 
>     $txt .= $row->editorialdate; 
>     $txt .= $row->editorialname; 
>     $txt .= $row->editorialcomments; 
>   } 
> 
> } 
> 
> //this part sends email 
> ini_set("SMTP", "texchange.company.com"); 
> ini_set("smtp_port", "25"); 
> $to = "p...@company.com"; 
> $subject = "Production report"; 
> $txt = "$row \n\r\n\rPLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A 
> VALID EMAIL ADDRESS"; 
> $headers = "From: Daily_Prod._Rep...@company.com"; 
> mail($to,$subject,$txt,$headers); # <--- sends the email 
> 
> mysql_close($con); //closes the connection to the DB 
> 
> ?> 
> 
> Any ideas? thanks. 
 
You're using the same variable ($txt) for two different purposes. 
You're saving all of your information from your database into $txt, 
and then changing it to "PLEASE DO NOT REPLY TO THIS E-MAIL", and THEN 
you send the e-mail. 
 
Try changing this line: 
 
 $txt = "$row \n\r\n\rPLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A 
VALID EMAIL ADDRESS"; // You're getting rid of everything that $txt 
used to hold, and giving it this new value. ($row only existed for the 
purposes of your while loop, and doesn't hold any information any 
more) 
 
to something like.. 
 
$body = "$txt \n\nPLEASE DO NOT.."; 
 
Also, you should save each field from your table into an array for 
easier output.
 
  
Navigation:
[Reply to this message] 
 |