Help needed

Hi everyone.

i need some help in my php+mysql.

i’m a newbie on both php + mysql.

i hv a silly question to ask.

is that possible that i able to email information from my mysql database using php? my information from my database consist of information and picture directory. i would like to upload both this information from my database and email using php.

Thanks for your kind help…

please be more descriptive on your topic, something like “how can email information from my database?” would be more helpful for people with that knowledge help you faster

ins response to your question

yes it is possible.

you can fetch information from your database and then email it to someone.

Hi WIlson,

How do i fetch it? and how can i upload picture where it is in a folder. i did not store the whole picture in database

well you have to do the following

[ol][li]connect to the database[/li]
[li]runa query fetching what you need[/li]
[li]fetch the result of the query[/li]
[li]and then print or you use it where you want it[/li][/ol]

if you are unfamiliar with this, google something like “how to connect and fetch data from database”

or take a look here
http://www.phphelps.com/10_How_to_connect_and_fetch_data_from_mySQL_database_in_PHP.shtml

i want you to try first so you learn

i know how to connect database. and fetch the query, will it be ok if i’m using get function?

well since in the database you are storing the path to picture i assume it looks something like thisimages/customers/image14.jpg

once you connect you can say
[php]
$result = mysql_query(“select * blah bah”);
$row = mysql_fetch_assoc($result);

echo $row[‘image_dir’]l; // or whatever you want to do with the patch

[/php]

So i just use echo $row to get the information?? will i get the picture as well?? coz i did some testing. i only manage the get the picture url not the actual file

you managed to get the path of image? excellent you are on the right track.

to display the image you need to use the html img tag and assign the path you have got from the database

example
[php]
echo “<img src=’”.$row[‘image_path_here’]"’/>";
[/php]

there is some logic i do not understand here. i manage the get the image path, and show before i send. but when i send the email, i did not get the picture in the attachment. what is the problem ? i only manage to get the text info and picture url from the server. which this case is not good for me.

Every body needs help.Some one needs help for their achivement and some one needs for their poorness.In Bangladesh every person, they help each other.I think its a good thinking for every person in this world.

ahhh you want to send the image as an attachment, i understand, i thought you wanted to display it anyway.

the image is stored in your server and the path to image is stored in DB, right?

yup… you get me right… hah… so is there any solution for it?

yes of course

[php]

<?php $fromAddr = '[email protected]'; // the address to show in From field. $recipientAddr = '[email protected]'; //the address to who it will send the email. $subjectStr = 'Thank you'; $mailBodyText = <<<END89283 Thank You

Login: dummy text blah blah blah
Password: blah blah blah blah

END89283; // change this to the path of the image from the database $filePath = 'great_house.jpg'; $fileName = basename($filePath); $fileType = 'image/jpeg'; /* to find out what string to use for type, see http://en.wikipedia.org/wiki/Internet_media_type or $_FILES['attachment']['type']; */ /* encode the email content */ $mineBoundaryStr='otecuncocehccj8234acnoc231'; $headers= <<<EEEEEEEEEEEEEE From: $fromAddr MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="$mineBoundaryStr" EEEEEEEEEEEEEE; // Add a multipart boundary above the plain message $mailBodyEncodedText = <<<TTTTTTTTTTTTTTTTT This is a multi-part message in MIME format. --{$mineBoundaryStr} Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable $mailBodyText TTTTTTTTTTTTTTTTT; $file = fopen($filePath,'rb'); $data = fread($file,filesize($filePath)); fclose($file); $data = chunk_split(base64_encode($data)); // file attachment part $mailBodyEncodedText .= <<<FFFFFFFFFFFFFFFFFFFFF --$mineBoundaryStr Content-Type: $fileType; name=$fileName Content-Disposition: attachment; filename="$fileName" Content-Transfer-Encoding: base64 $data --$mineBoundaryStr-- FFFFFFFFFFFFFFFFFFFFF; if ( mail( $recipientAddr , $subjectStr , $mailBodyEncodedText, $headers ) ) { echo '

SenT successfully!

'; } else { echo '

Message not Sent

'; } ?>

[/php]

all you need to change to have a working script is line 2,3 and 24.
along any modification you make
I didn’t make the script so Don’t credit me for the script.

Sponsor our Newsletter | Privacy Policy | Terms of Service