how to send email while feteching data from database

hi i just want to know how can i send email i want when i click on submit button or send mail mail will go to email filed…

[php]

<?php $con = mysql_connect("localhost","root","puneet"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("complaintdatabase"); $cno=$_POST['cno']; $result = mysql_query("SELECT cno, name, natureofcomplaint, email, taskassigned FROM camplaint2 WHERE cno='".$cno."' "); if($row=mysql_fetch_array($result)); { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
"; echo "
name
"; echo "
"; echo " " .$row['name']. "
"; echo "
cno
"; echo "
"; echo " " .$row['cno']. "
"; echo "
natureofcomplaint
"; echo "
"; echo " " .$row['natureofcomplaint']. "
"; echo "
email
"; echo "
"; echo " " .$row['email']. "
"; echo "
taskassigned
"; echo "
"; echo " " .$row['taskassigned']. "
"; } ?> <? if(isset($_POST['submit'])) { $to=$_GET['email']; $name = $_GET['name']; $taskassigned=$_GET['taskassigned']; $from = '[email protected]'; $subject = 'Regarding your complaint status '; $msg = "Dear $name, This complaint has been assigned to \r\n\r\n$taskassigned"; (mail($to, $subject, $msg, 'From:' . $from)) echo "Mail Sent."; header("location:newform.php"); } ?> [/php]

Please no not Include Database Information. Consider changing your password.

$con = mysql_connect("localhost","root","puneet");

Hello,

you want to fetch all emails from from database and be able to select from a dropdown to which email you want to send ?

explain please

From reading the code provided, it looks like he wants an email to go out when someone has been assigned to the person’s task. I don’t see the code that will do that though, don’t see any form at all actually. Me thinks we’re missing some code lol :slight_smile:

LOL richei,

the way i would do it would be have 2 php files separately, one for insert assigments to users and one for sending out emails once assignments have been assigned.

insert.php

should contain a form with a dropdown with all users/or Employees

an update query assigning the assigment 

on your table add an extra field ‘notified’ as boolean 1 or 0
notify_users.php
[php]
“select * from users where notifeid = 0”// 0 means they have not been notifed
// set notifed to 1 once you notifies them
[/php]

you can run this notify_users.php script everything with cron technology on your server

That’s pretty much how i would do it also, just minus the cron job since it looks like he’s manually assigning people to the task.

Sponsor our Newsletter | Privacy Policy | Terms of Service