Jump to content

Sending an email


taz321

Recommended Posts

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

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites


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

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>";
}
?>

                         

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.