By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,500 Members | 2,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,500 IT Pros & Developers. It's quick & easy.

emailing data from my DB...??

P: n/a
I've been working on this for some time now and have gotten
nowhere...hoping someone here can help.

I want to take and email all records in a database for the current
date when this php page is run.

Now I have a number of tables in this database...looking like this:
editorial
editorialdate, editorialname, editorialcomments
press
pressdate, pressname, presscomments
mail
maildate, mailname, mailcomments

So what I want to do is take anything for $today and put it into an
email, the email would look like this:
==
Editorial Report:
editorialdate
editorialname
editorialcomments

Mail Report:
maildate
mailname
mailcomments

etc...

here is what I have now, wich I thought would do it:

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);

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
print $row->editorialdate;
print $row->editorialname;
print $row->editorialcomments;
}
}

//this part sends email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$to = "pa**@company.com";
$subject = "Production report";
$txt = "$row[0] \n\r\n\rPLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT
A VALID EMAIL ADDRESS";
$headers = "From: Da****************@company.com";
mail($to,$subject,$txt,$headers); # <--- sends the email

mysql_close($con); //closes the connection to the DB

?>
my $today works fine because at the very beginning it will say:
Generating and emailing report for: Dec 21, 2007,

So I know it is getting the right date....so I am trying this for one
table in my DB now....and all I get is a blank email with no data in
it from my database.

Anyone have any ideas?
Dec 21 '07 #1
Share this Question
Share on Google+
20 Replies


P: n/a
pa*****@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: Da****************@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() ...
--
----------------------------------
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:04:05 up 29 days, 5:19, 4 users, load average: 0.54, 0.63,
0.70

Dec 21 '07 #2

P: n/a
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
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() ...

--
----------------------------------
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:04:05 up 29 days, 5:19, 4 users, load average: 0.54, 0.63,
0.70
How would I store it?
Dec 21 '07 #3

P: n/a
pa*****@excite.com wrote:
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>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

Dec 21 '07 #4

P: n/a
On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
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 = "pa**@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: Da****************@company.com";
mail($to,$subject,$txt,$headers); # <--- sends the email

mysql_close($con); //closes the connection to the DB

?>

Any ideas? thanks.
Dec 24 '07 #5

P: n/a
pa*****@excite.com said:
On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>paul...@excite.com wrote:
>>On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
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 thedata
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 = "pa**@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: Da****************@company.com";
mail($to,$subject,$txt,$headers); # <--- sends the email

mysql_close($con); //closes the connection to the DB

?>

Any ideas? thanks.
I might be wrong, but don't the headers require a newline at the end?
That might have something to do with it, but I don't see anything else.

~A!
Dec 24 '07 #6

P: n/a
On Dec 24, 9:32 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
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 ISNOT
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, andPHP
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.

I might be wrong, but don't the headers require a newline at the end?
That might have something to do with it, but I don't see anything else.

~A!
Well I tried that and that did not change anything
Dec 24 '07 #7

P: n/a
pa*****@excite.com said:
On Dec 24, 9:32 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
>paul...@excite.com said:
>>On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>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, THISIS 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 NOTA
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.
I might be wrong, but don't the headers require a newline at the end?
That might have something to do with it, but I don't see anything else.

~A!
Well I tried that and that did not change anything
What do you get if you print $txt and exit? Is that populated ok?
Dec 24 '07 #8

P: n/a
On Dec 24, 10:22 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
On Dec 24, 9:32 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
>On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
> while ($row = mysql_fetch_array($result)) { // puts the valuesinto
>$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.
I might be wrong, but don't the headers require a newline at the end?
That might have something to do with it, but I don't see anything else.
~A!
Well I tried that and that did not change anything

What do you get if you print $txt and exit? Is that populated ok?
If I echo $txt on the page....I get:
PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A VALID EMAIL ADDRESS
Dec 24 '07 #9

P: n/a
pa*****@excite.com said:
On Dec 24, 10:22 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
>paul...@excite.com said:
>>On Dec 24, 9:32 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>paul...@excite.com wrote:
>>On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
>>escomposlinux.-.punto.-.orgwrote:
>>>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 printingthe 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.
I might be wrong, but don't the headers require a newline at the end?
That might have something to do with it, but I don't see anything else.
~A!
Well I tried that and that did not change anything
What do you get if you print $txt and exit? Is that populated ok?
If I echo $txt on the page....I get:
PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A VALID EMAIL ADDRESS
Just out of curiosity, what is the column def on the date field in the
table? The usual format for date queries from MySQL is Y-m-d for DATE
and Y-m-d g:i:s for date time. It looks like $txt is not getting
populated at all, and I'm thinking it's maybe not getting anything from
the recordset.

~A!
Dec 24 '07 #10

P: n/a
On Dec 24, 10:36 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
On Dec 24, 10:22 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
>On Dec 24, 9:32 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
>On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
>escomposlinux.-.punto.-.orgwrote:
>>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.
I might be wrong, but don't the headers require a newline at the end?
That might have something to do with it, but I don't see anything else.
~A!
Well I tried that and that did not change anything
What do you get if you print $txt and exit? Is that populated ok?
If I echo $txt on the page....I get:
PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A VALID EMAIL ADDRESS

Just out of curiosity, what is the column def on the date field in the
table? The usual format for date queries from MySQL is Y-m-d for DATE
and Y-m-d g:i:s for date time. It looks like $txt is not getting
populated at all, and I'm thinking it's maybe not getting anything from
the recordset.

~A!
Well the editorialdate is stored as a VARCHAR and I have to do it that
way because of some other things that I am doing...I cant store it as
DATE/TIME. But it is populated as:
Dec 24, 2007, 8:37 am
for example.
Dec 24 '07 #11

P: n/a
pa*****@excite.com said:
Well the editorialdate is stored as a VARCHAR and I have to do it that
way because of some other things that I am doing...I cant store it as
DATE/TIME. But it is populated as:
Dec 24, 2007, 8:37 am
for example.
Ouch, sorry to hear that. Have you traced back to see what you're
getting from the DB? Just a print_r on the rows would do ya. That way
you can narrow down where the problem is. If it's just the query, that's
pretty simple to resolve in most cases.

~A!
Dec 24 '07 #12

P: n/a
On Dec 24, 10:59 am, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
paul...@excite.com said:
Well the editorialdate is stored as a VARCHAR and I have to do it that
way because of some other things that I am doing...I cant store it as
DATE/TIME. But it is populated as:
Dec 24, 2007, 8:37 am
for example.

Ouch, sorry to hear that. Have you traced back to see what you're
getting from the DB? Just a print_r on the rows would do ya. That way
you can narrow down where the problem is. If it's just the query, that's
pretty simple to resolve in most cases.

~A!
I dont know how to do the print_r but this is what one of my
editorialdate fields looks like...its a copy and paste right from the
DB:
Dec 24, 2007, 8:37 am
that is exactly what it looks like in the DB.
but in my page I am only looking for the first characters of the
date....so my query is anyhting that looks like this:
Dec 24, 2007,
I don't care about the time at all just the date, that is why I am
doing this:

$today = date("M j, Y,");
echo $today; (this displays like: Dec 24, 2007,)

and then that is why my query looks like this:
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%' ";

So basically select everything from editorial where the editorialdate
field is like Dec 24, 2007,
Dec 24 '07 #13

P: n/a
pa*****@excite.com said:
[snip]
>
$today = date("M j, Y,");
echo $today; (this displays like: Dec 24, 2007,)

and then that is why my query looks like this:
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%' ";

So basically select everything from editorial where the editorialdate
field is like Dec 24, 2007,
Oh, no, don't get me wrong, I know what you're doing in the code, I'm
just curious what you're actually getting for records in the page. When
you print $txt and nothing comes out, I start to think things aren't
coming out of the DB. Try just echoing the mysql_num_rows call to the
page, see what you come up with.

print_r is a variable dumper, and the syntax is:
print_r($variable);

Doing that extracts all the info about a variable and prints to the
screen for you.

~A!
Dec 24 '07 #14

P: n/a
pa*****@excite.com wrote:
If I echo $txt on the page....I get:
PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A VALID EMAIL ADDRESS
'Cause you're overwriting $txr ...

Please stop trying things blindly, and start thinking about what your
program is doing.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Now listening to: Sigur Rós - Takk... (2005) - [5] Sé Lest (8:40)
(96.000000%)
Dec 24 '07 #15

P: n/a
On Dec 24, 12:40 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
If I echo $txt on the page....I get:
PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A VALID EMAIL ADDRESS

'Cause you're overwriting $txr ...

Please stop trying things blindly, and start thinking about what your
program is doing.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Now listening to: Sigur Rós - Takk... (2005) - [5] Sé Lest (8:40)
(96.000000%)
So what do I need to do to put editorialdate, editorialname, and
editorialcomments in an email?
Dec 24 '07 #16

P: n/a
aeg
On Dec 21, 5:56 pm, paul...@excite.com wrote:
print $row->editorialdate;
print $row->editorialname;
print $row->editorialcomments;
You should be doing $row['editorialdate'] to read from the array not
the way you're doing it which is attempted to read from a class (which
you haven't got).

Surely? Unless I'm missing something?
Dec 25 '07 #17

P: n/a
On Dec 24, 1:06 pm, paul...@excite.com wrote:
On Dec 24, 12:40 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-

escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
If I echo $txt on the page....I get:
PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A VALID EMAIL ADDRESS
'Cause you're overwriting $txr ...
Please stop trying things blindly, and start thinking about what your
program is doing.
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Now listening to: Sigur Rós - Takk... (2005) - [5] Sé Lest (8:40)
(96.000000%)

So what do I need to do to put editorialdate, editorialname, and
editorialcomments in an email?
A better way to do this would be the following:

$txt = "PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A
VALID EMAIL ADDRESS";

/* do your mysql work here */

while ($row = mysql_fetch_array($result))
{
$txt .= $row['editorialname'] . "\r\n";
/* do others */
}

then do your mail commands.

By the way, you realize that $headers has nothing in it, yes?

I'd suggest a refresher on the basics of PHP, as it looks like you're
just copying and pasting from several sources and hoping it'll work.
I suggest "CORE PHP Programming" as a good place to start. PHP isn't
like HTML; you can't just steal stuff out of context and expect it to
work.
Dec 26 '07 #18

P: n/a
On Dec 26, 9:10 am, Evil Otto <zburn...@gmail.comwrote:
On Dec 24, 1:06 pm, paul...@excite.com wrote:
On Dec 24, 12:40 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
If I echo $txt on the page....I get:
PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A VALID EMAIL ADDRESS
'Cause you're overwriting $txr ...
Please stop trying things blindly, and start thinking about what your
program is doing.
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Now listening to: Sigur Rós - Takk... (2005) - [5] Sé Lest (8:40)
(96.000000%)
So what do I need to do to put editorialdate, editorialname, and
editorialcomments in an email?

A better way to do this would be the following:

$txt = "PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A
VALID EMAIL ADDRESS";

/* do your mysql work here */

while ($row = mysql_fetch_array($result))
{
$txt .= $row['editorialname'] . "\r\n";
/* do others */

}

then do your mail commands.

By the way, you realize that $headers has nothing in it, yes?

I'd suggest a refresher on the basics of PHP, as it looks like you're
just copying and pasting from several sources and hoping it'll work.
I suggest "CORE PHP Programming" as a good place to start. PHP isn't
like HTML; you can't just steal stuff out of context and expect it to
work.
OK. I appriciate all the help and input....this is starting to do
what I want it to do. with this code:
<?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
$txt = "EDITORIAL REPORT:\n\r";

if (mysql_num_rows($result)) { // if there are results
while ($row = mysql_fetch_array($result)) { // puts the values into
$row
$txt .= $row['editorialdate'] . "\n\r";
$txt .= $row['editorialname'] . "\n\r";
$txt .= $row['editorialcomments'] . "\n\r";
}
}

//this part sends email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$to = "pa**@company.com";
$subject = "Production report";
$headers = "From: Da****************@company.com";
mail($to,$subject,$txt,$headers); # <--- sends the email

mysql_close($con); //closes the connection to the DB

?>

My email looks like this now:
EDITORIAL REPORT:
Dec 27, 2007, 1:19 pm
TEST TEST
Testing this.....

ok so If I wanted to add other data now would I just do the same thing
but maybe just use $txt2 and $txt3?

Like say I want me email to look like this:

EDITORIAL REPORT:
Dec 27, 2007, 1:19 pm editorialdate
TEST TEST editorialname
Testing this..... editorialcomments

MAIL REPORT:
Dec 27, 2007, 1:19 pm maildate
TEST TEST mailname
Testing this..... mailcomments

CIR REPORT:
Dec 27, 2007, 1:19 pm cirdate
TEST TEST cirname
Testing this..... circomments

all of these also have their own DB
so I have a DB:
editorial
mail
cir
Dec 27 '07 #19

P: n/a
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.-.orgwrote:
paul...@excite.com wrote:
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>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.
Dec 28 '07 #20

P: n/a
On Dec 24, 3:50 pm, paul...@excite.com wrote:
On Dec 21, 1:41 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-

escomposlinux.-.punto.-.orgwrote:
paul...@excite.com wrote:
On Dec 21, 1:05 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>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.
What? Blank or "PLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT A
VALID EMAIL ADDRESS"?

I don't test it but it seems you set a new value to $txt variable then
all rowing stuff is being gone.. ;)
What about putting $txt "the do not reply message" above the while
block?

Dec 29 '07 #21

This discussion thread is closed

Replies have been disabled for this discussion.