Hi, i have problem to save record and send email in php. After selecting the responsible person, the system supposed to save the responsible person in the database and then send email to notify the responsible person on his progress. The coding is below but it doesn't work. Please kindly advise. Thanks.
<?php
//error_reporting(E_ALL ^ E_NOTICE);
$cn=mysql_connect("localhost","user","") or die(mysql_error());
mysql_select_db("p",$cn) or die(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>";
}
mysql_free_result($rs);
"</select>";
$q = "SELECT Email FROM user WHERE Position = '$responsible2'";
$r = mysql_query($q);
while($row = mysql_fetch_array($r))
{
echo "Email:".$row[Email]."<br/>";
}
if(isset($_POST['Notify2']))
{
$_SESSION['Progressid'];
echo $_SESSION['Progressid'];
$responsible2=$_POST['responsible2'];
echo $responsible2;
echo $_SESSION['Email'];
echo $_SESSION['Username'];
$cemail2=$_POST['Email'];
mysql_query("INSERT INTO improvement_plan (Responsible2,Progressid) VALUES ('" . $responsible2 . "',
'" .$_SESSION['Progressid'] . "')");
$Ipid = mysql_insert_id();
if(!empty($Ipid)) {
$message = "New improvement plan added successfully";
require 'PHPMailer_5.2.4/PHPMailer_5.2.4/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = 'smtp.office365.com'; // Specify main and backup server
$mail->Mailer = "smtp";
$mail->SMTPAuth = false;
$mail->IsHTML(true); // Set email format to HTML
$mail->ContentType = "text/html";
$mail->From =($_SESSION['Email']);
$mail->FromName =($_SESSION['Username']);
$mail->AddAddress('$cemail2'); // Name is optional
$mail->Subject = 'system Notification';
$mail->Body = 'Please do your <strong>Improvement Plan</strong>';
if(!$mail->Send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
else
{
echo 'Message has been sent';
}
}
}
?>