Jump to content

need help in sending php data to email in html/text format.(CLOSED)


hanwei

Recommended Posts

hi guys, i need some help here.

i have created a table in my database. And i would like to send the table to my email everyday at a certain time. i know i have to use crontab.

but right now is how do i display the table and send it over to my mail?

i have tried to use the following:

$to="myemailaddress"
$subject="mysubject"
$headers="myheaders"
$message="mymessage"
mail($to,$subject,$message,$headers)

it will send a mail to my mailbox. but now i wanted to send over all the data in a table.

so can anyone give me some idea on how to do it?

thanks in advance.
erm.. thanks, but what i want is to send a daily report to my email. not doing a backup.

for example:
Number of Client online : ___
Number of Client submitted: ___


i just want a simple text base report to be sent to my mail. But all the data i have to retrive from my table so that i can display it and send to my mail.


thanks in advance
the table is in a database. all the data in the tables is updated everday.

if i execute
mysql>select * from mytable\G;

output is:

ClientName:___
LoginDate:___
LoginTime:___

so i have to mail a list of client who login into my web.
if i'm not wrong, i use the select * from mytable where LoginDate='xxx'; to get the data i want. but i'm not sure how to mail it in text/html form.

thanks in advance
[code]
<?php

$db=mysql_connect('localhost' , 'xxxxxx' , 'xxxxxx' );
mysql_select_db('xxxxxx',$db);

$query="select * from xxxxxx where xxxxx='xxxxx'";

$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){

$to = $record['email_address'];

$subject = 'Wakeup bob!';


$message = '

memeber $record['user'] logeed in at $record['date']

';


$headers = "From: [email protected]\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
mail($to, $subject, $message, $headers);

}

?>
[/code]
i think have to put a mysql_close($db) at the end of the script right? now i'm waiting for it to reach my mail.

[quote author=redarrow link=topic=113442.msg461008#msg461008 date=1162375437]
[code]
<?php

$db=mysql_connect('localhost' , 'xxxxxx' , 'xxxxxx' );
mysql_select_db('xxxxxx',$db);

$query="select * from xxxxxx where xxxxx='xxxxx'";

$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){

$to = $record['email_address'];

$subject = 'Wakeup bob!';


$message = '

memeber $record['user'] logeed in at $record['date']

';


$headers = "From: [email protected]\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
mail($to, $subject, $message, $headers);

}

?>
[/code]
[/quote]
i'hv change my script to this
<?php

$link = mysql_connect("127.0.0.1", "mysql") or die("Could not connect: " . mysql_error());
mysql_select_db("ttmodule", $link) or die("Unable to select database: . mysql_error()");

$query="select userID, logTime from mytable";

$result=mysql_query($query);


while($record=mysql_fetch_assoc($result)){


$to = "hanwei<[email protected]>";

$subject = "Test";


$message = ' member $record["userID"] logged in $record["logTime"] ';


$headers = "From: [email protected]\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
mail($to, $subject, $message, $headers);

}

?>

the mail i got is:
member $record["userID"] logged in $record["logTime"]

it directly print out the message.
can someone help me?

thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.