473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

automatically send entire page in an email

How can I get a php page to automatically send all the contents in an
email when it is generated?

I managed to hack together a script that sends an email, but it will
only send the 1st record returned and I would like it to send all the
records that are on the page when it is loaded.

<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db", $con);

$sql = 'SELECT * FROM `table` WHERE status = "fail" AND `submitted` >
NOW() - INTERVAL 24 HOUR ';

$result=mysql_query($sql);

$i_mail = mysql_fetch_array($result);

$num = mysql_numrows($result);

$row = mysql_fetch_row($result);

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

mysql_close($con)
?>

<?php
// displays records in browser
$i=0;
while ($i < $num) {

$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");

echo "<br><b>$visited</b$id<br>$submitted<hr>";

$i++;
}

?>

<?php
//sends the email automatically

//to and from addressess

$email = "em***@someurl.com";
$fromemail = "anotherem***@someurl.com";
// The subject

$subject = "warning";

// The message

$message = $i_mail['visited'].", ".$i_mail['submitted']."
http://someurl.com/display.php?id=".$i_mail['id']." \n";

mail($email, $subject, $message, "From: $fromemail");

echo "<p>The email has been sent.";

?>

Jun 27 '08 #1
7 1584
Mc*******@gmail.com wrote:
<SNIP>
<?php
// displays records in browser
$i=0;
while ($i < $num) {

$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");

echo "<br><b>$visited</b$id<br>$submitted<hr>";

$i++;
}

?>
</SNIP>
>
Maybe part of the problem, maybe just a typo, but....

where are you initializing $id?
--
------------------------------------
Gene Kelley
Senior Open Source Software Engineer
Advanced Design Solutions Team
Network Solutions (MonsterCommerce)
Swansea, Illinois, USA
Jun 27 '08 #2
On Jun 9, 4:09 pm, Gene Kelley <g...@bizflowdesigns.comwrote:
Mcanaj...@gmail.com wrote:

<SNIP>
<?php
// displays records in browser
$i=0;
while ($i < $num) {
$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");
echo "<br><b>$visited</b$id<br>$submitted<hr>";
$i++;
}
?>

</SNIP>

Maybe part of the problem, maybe just a typo, but....

where are you initializing $id?

--
------------------------------------
Gene Kelley
Senior Open Source Software Engineer
Advanced Design Solutions Team
Network Solutions (MonsterCommerce)
Swansea, Illinois, USA
that's just a typo, sorry
Jun 27 '08 #3
the code should read as follows (i forgot that i took $id out of it
when i was copying/pasting/etc...

<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db", $con);

$sql = 'SELECT * FROM `table` WHERE status = "fail" AND `submitted` >
NOW() - INTERVAL 24 HOUR ';

$result=mysql_query($sql);

$i_mail = mysql_fetch_array($result);

$num = mysql_numrows($result);

$row = mysql_fetch_row($result);

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

mysql_close($con)
?>

<?php
// displays records in browser
$i=0;
while ($i < $num) {

$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");

echo "<br><b>$visited</b><br>$submitted<hr>";

$i++;

}

?>

<?php
//sends the email automatically

//to and from addressess

$email = "em...@someurl.com";
$fromemail = "anotherem...@someurl.com";

// The subject

$subject = "warning";

// The message

$message = $i_mail['visited'].", ".$i_mail['submitted']."\n";

mail($email, $subject, $message, "From: $fromemail");

echo "<p>The email has been sent.";

?>

sorry about that
Jun 27 '08 #4
ca******@gmail.com wrote:
the code should read as follows (i forgot that i took $id out of it
when i was copying/pasting/etc...

<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db", $con);

$sql = 'SELECT * FROM `table` WHERE status = "fail" AND `submitted` >
NOW() - INTERVAL 24 HOUR ';

$result=mysql_query($sql);

$i_mail = mysql_fetch_array($result);

$num = mysql_numrows($result);

$row = mysql_fetch_row($result);

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

mysql_close($con)
?>

<?php
// displays records in browser
$i=0;
while ($i < $num) {

$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");

echo "<br><b>$visited</b><br>$submitted<hr>";

$i++;

}

?>

<?php
//sends the email automatically

//to and from addressess

$email = "em...@someurl.com";
$fromemail = "anotherem...@someurl.com";

// The subject

$subject = "warning";

// The message

$message = $i_mail['visited'].", ".$i_mail['submitted']."\n";

mail($email, $subject, $message, "From: $fromemail");

echo "<p>The email has been sent.";

?>

sorry about that
A couple of things.

First of all, don't use die() in a production system. It's good for
testing, but in a live system, put out an error message (NOT the results
from mysql_error()!) and bypass the rest of the script with an else {...
statement.

Using die() like you are displays some of the internals of your scripts
and can leave you open to hackers.

Also, you're calling mysql_query() twice. That just returns the same
result set a second time, creating unnecessary overhead.

Also, the mysql_fetch... calls only return one row at a time - not the
entire result set. So once you've gotten a good return value from your
SELECT statement, you need to loop to fetch all of the returned rows., i.e.

while ($i_mail = mysql_fetch_array($result)) {

Of course, each time you call mysql_fetch_array(), it will overlay the
previous data in $i_mail, so you either need to add the data to your
email now, or save it (i.e. in an array), i.e.

(initialize $message to '' before calling mysql_fetch_array!)

$message .= $i_mail['visited'].", ".$i_mail['submitted']."\n";

Hope this leads you to the correct solution.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #5
THANKS!!!

thats a heck of a lot easier than what I was trying to do, and it
works

(I was trying to turn:

<?php
// displays records in browser
$i=0;
while ($i < $num) {

$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");

echo "<br><b>$visited</b><br>$submitted<hr>";

$i++;

}

?>

into a function and have $message=function
Jun 27 '08 #6
ca******@gmail.com wrote:
THANKS!!!

thats a heck of a lot easier than what I was trying to do, and it
works

(I was trying to turn:

<?php
// displays records in browser
$i=0;
while ($i < $num) {

$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");

echo "<br><b>$visited</b><br>$submitted<hr>";

$i++;

}

?>

into a function and have $message=function
Yep, we all go through doing things the hard way when we're learning.

Then we find the easy way.

Then we find the fastest way and create the most unmanageable mess
you've ever seen :-)

Glad to be of help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #7
On Jun 10, 2:18 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
canaj...@gmail.com wrote:
THANKS!!!
thats a heck of a lot easier than what I was trying to do, and it
works
(I was trying to turn:
<?php
// displays records in browser
$i=0;
while ($i < $num) {
$visited=mysql_result($result,$i,"visited");
$submitted=mysql_result($result,$i,"submitted");
echo "<br><b>$visited</b><br>$submitted<hr>";
$i++;
}
?>
into a function and have $message=function

Yep, we all go through doing things the hard way when we're learning.

Then we find the easy way.

Then we find the fastest way and create the most unmanageable mess
you've ever seen :-)

Glad to be of help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
:)
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Erik T. Nomad | last post by:
I've created a link that will enable the reader of any page on my website to click it, enter an e-mail address, and have it arrive in that inbox with a hyperlink to the site. However, I'm...
4
by: Mark J. McGinty | last post by:
Greets, Part of the content of one of our web pages uses wingdings and Chr(239) through Chr(242) (which are little arrow outlines, though that's not really important.) It worked just fine in...
11
by: Tim Smallwood | last post by:
Hi, I have an Access project that I use to allow a client to hit an SQL server at my host. This project has several forms that are used to udpate tables, etc, but I'd also like to be able to...
7
by: Martin | last post by:
Hi, I have a standard aspx page (form) that contains a few user controls. Upon form submission the page is validated. If validation passses then a text based email is sent. This is all working...
2
by: Baron Samedi | last post by:
My whole site is PHP. That means that there are various includes which make up each page so that I can have standard headers/footers/menu, etc If the content of one of these changes, it might break...
10
by: Sam Polos | last post by:
Is there a way, with javascript, that if someones visits a webpage that I automatically get an email with information about the visitor? Info such as IP, referrer, etc. Thanks.
4
by: fjm | last post by:
Hello eveyone Is there a way to email an entire html page after the page is processed for data? What I have is an entire html page that draws data from a db. I would like to email that form...
2
by: Ty | last post by:
I have a Web site project in VS 2008 vb.net. What I'm trying to do is send a page by email via a button click. I have tried to use this as an example. http://www.systemnetmail.com/faq/4.8.aspx ...
9
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
I want to download pfx from my asp.net server, add the pfx to client's X509Store as a trusted publisher, Is it possible? my func in aspx is like this: void InstallCertification() { try{...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.