taz321 Posted March 15, 2008 Share Posted March 15, 2008 Hi Iv developed a help desk system and want an section in the system where a user would inform a client of the progress of their query by emailing them. I believe Dreamweaver (which i am using to design my system) has this as a feature but not the way i would like it. Within my system is stored (Client table) the clients contact details such as email address. I would like to email that particular client with their email address from the database pre-filled in when i click on the email button with details of the query filled in as well (all read from the database) I hope thats clear. Any help would be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 I'm not sure what you want here... did you want the script made for you? If so, please go to the PHP freelance forums. Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 15, 2008 Author Share Posted March 15, 2008 Sorry may have worded it badly. Didnt mean to sound like i wanted it done for me, im just at a lost with this and just wanted some advice on how to go about doing it. This is the code i have already - <a href="mailto:??"> but not sure how i would express the code here to read from the database. Thanks Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 I don't see any code. How to grab the data from the database would really depend on the database being used. Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 15, 2008 Author Share Posted March 15, 2008 Sorry this is the code - <a href="mailto:??"> Im developing this is PHP, mysql if thats what you mean. Thanks Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 mysql_connect('localhost', 'root', 'password') or die('Failed'); mysql_select_db('database') or die('Failed'); $q = 'SELECT `name`, `email` FROM `client_table`' . ( is_numeric($id) ? ' WHERE `id`=' . $id : ''); if (!$r = mysql_query($q) ) echo 'Query error:<br>' . mysql_error(); else { if (mysql_num_rows($r) < 1) echo 'No rows found'; else while ($data = mysql_fetch_assoc($r) ) echo '<a href="mailto:' . $data['email'] . '">' . $data['name'] . '</a>'; } Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 15, 2008 Author Share Posted March 15, 2008 Thanks for your help, im going to try and adapt that into my system. Cheers Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 16, 2008 Author Share Posted March 16, 2008 Hi Im not quite understanding the code given above. I have looked at a few different sites and have seen this code come up a few times <?php $to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> But i want the $to, $subject and $message to read from the database instead of me hardcoding it (like above). Any ideas how i could do this. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted March 16, 2008 Share Posted March 16, 2008 how is the database set up?? run a query to get the data from the database and then assign the data dynamically $query = "SELECT * FROM table"; $result = mysql_query($query) or die ("Error in query" . mysql_error()); while ($row = mysql_fetch_assoc($result) { $to = $row['to']; $subject = $row['subject']; $message = $row['message']; $from = $row['frommail']; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent to $to <BR>"; } Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 16, 2008 Author Share Posted March 16, 2008 The database is set up in a file called "connect.php" so i would put the following code on top of what you've given me. require "connect.php"; Il try that and see where i get.. Thanks Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 16, 2008 Author Share Posted March 16, 2008 Just a quick question. I need the email to read from 2 tables, which are: - Client Form From client i would need - email From Form i would need - issuetitle, systemaffected, issuedetails & supportcomments. Would i need to join the two tables together in the SQL statement and create another table in my database to show this? Any suggestions how i could do this ? Thanks Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 16, 2008 Author Share Posted March 16, 2008 Does anyone know have an idea on my sql question ? Thanks Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 16, 2008 Share Posted March 16, 2008 not really a PHP question, but it will be something like SELECT A.email, B.issuetitle, B.systemaffected, B.issuedetails, B.supportcomments FROM client A, Form B WHERE A.id = B.client_id assuming you've got an id field on client and a matching client_id field on Form Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 16, 2008 Share Posted March 16, 2008 is it a join you want but we dont no the id name try this change the id name......... <?php $sql="SELECT client.email, form.issuetitle, form.systemaffected, form.issuedetails, form.supportcomments FROM client,form WHERE client.id=form.id"; $sql_result=mysql_query($sql)or die(mysql_error()); while ($row = mysql_fetch_assoc($sql) { $x="system affected: ".$row['systemaffected']." <br><br> Issue:".$row['issuedetails']." <br><br> comments: ".$row['supportcomments']." "; $to = $row['email']; $subject = $row['issuetitle']; $message = $x; $from = $row['frommail']; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent to $to <BR>"; } ?> Quote Link to comment Share on other sites More sharing options...
taz321 Posted March 16, 2008 Author Share Posted March 16, 2008 Thanks for all your help, im going to implement this now Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.