Hi, tried to update record in table and send email to the responsible person but no email is being sent. When current user select the responsible person from the option select and click Notify2 button, it suppose to update Responsible2 in improvement_plan table and send email to notify the Responsible2 person. Please advise.Below is the code:

error_reporting(E_ALL ^ E_NOTICE);
$con = mysql_connect("localhost","user","");

    if (!$con){

die("Can not connect: " . mysql_error());


$sql = "SELECT * FROM user";
$rs = mysql_query($sql) or die(mysql_error());
echo "<select name='responsible2'>";

    while($row = mysql_fetch_array($rs)){

echo "<option value=".$row['Position'].">".$row['Position']."</option>";
"<option value=".$row['Email']."</option>";




echo $Responsible2;
echo $cemail;
mysql_query("INSERT INTO improvement_plan (Responsible2,Progressid) VALUES ('" . $_POST['responsible2'] . "','" . $_SESSION['Progressid'] . "')"); 
$Ipid = mysql_insert_id();

if(!empty($Ipid)) { 
$message = "New improvement plan added successfully"; 


$sql ="SELECT Email FROM user where Userid='".$_SESSION['Userid']."'";
$rs = mysql_query($sql) or die(mysql_error());


"Email:<input type='text' name='Email' value='".$row['Email']."'><br>";
echo $row['Email'];


require 'PHPMailer_5.2.4/PHPMailer_5.2.4/class.phpmailer.php';
$mail = new PHPMailer;

    $mail->IsSMTP();                                      // Set mailer to use SMTP

$mail->Host = 'smtp.office365.com';   // Specify main and backup server

    $mail->SMTPAuth = false;                               // Enable SMTP authentication

$mail->From = $row['Email'];
$mail->FromName = $_SESSION['Username'];

    $mail->AddAddress('$cemail');                               // Add a recipient

$mail->IsHTML(true);                                  // Set email format to HTML
$mail->Subject = 'system Notification';

    $mail->Body    = 'Improvement Plan';

$mail->AltBody = 'Improvement Plan.';

    if(!$mail->Send()) {

   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;



echo 'Message has been sent'; 
<form name="" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

        <input type="hidden" name="Progressid" value="<?php echo $_SESSION['Progressid']; ?>" >

    <table width="850" border="1">
      <tr align="center">
        <th width="80" scope="col">Responsible</th>
        <input type="submit" name="Notify2" value="Notify"> 
 $disable = '';

        $i = 0;

    $d = 0;

$con = mysql_connect("localhost","user","");
if (!$con)


die('Could not connect: ' . mysql_error());


mysql_select_db("pq", $con);    

$sql = "SELECT * FROM improvement_plan where  Ipid='" . $Ipid . "'";
$res_list = mysql_query($sql) or die(mysql_error());

    if( isset( $_SESSION['Progressid'] ) ) {

  $Progressid = $_SESSION['Progressid'];  


    while($row_list = mysql_fetch_array($res_list)){

 <td align="center"><div id="Responsible2<?php echo $i; ?>"><?php if($row_list['Responsible2'] != '0000-00-00'){ echo ($row_list['Responsible2']); }else{ echo '-'; } ?></div></td> 
 <td align="center"><div id="Progressid<?php echo $i; ?>"><?php if($row_list['Progressid'] != '0000-00-00'){ echo ($row_list['Progressid']); }else{ echo '-'; } ?></div></td>


    if($i == 0){

<tr><td colspan="7">No data.</td></tr>
  $disable = 'disabled="disabled"';



Edited by diafol: reformatted code - please use the code block button in the editor

2 Years
Discussion Span
Last Post by lps

Please reformat your code with proper indenting, this is impossible to read. In addition, use the Code button in the editor as your original post did not contain a proper codeblock until I edited it.


First of all, supporting @diafol's comment on the 'proper indenting' issue. Proper indenting easier the job for us.

Then the problem in this program:
1. The <select> and the looping for its <options> is outside the <form> tag where it is imposible for the selection to be 'post' to $_SERVER['PHP_SELF'].
2. The html tags no match with each other and causing layout messed up. Example, there is no closing of <form> tag or not open for <td> and having </td> in while loop.
3. There is no update queries to update the table from your codes.
4. Code like this doesn't work

echo "<option value=" . $row['Position'] . ">" . $row['Position'] . "</option>";
"<option value=".$row['Email']."</option>";

Edited by lps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.