Hi everyone,i have this mail notification whereby the receiver is selected from combobox. Upon combobox selection, the sender will click the submit button and the mail suppose to be sent to the receiver. But it seems that the combobox selection cannot be read.There is error message ie "Message could not be sent.Mailer Error: You must provide at least one recipient email address." Appreciate for your advise on this matter. Thanks a lot.
responsible.php
<html>
<head>
<title>Send Notification</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="<?php echo $_SERVER['PHP_SELF']?>" method="post" action="ipdnotify2.php">
<?php
$cn=mysql_connect("localhost","pqa","") or die(mysql_error());
mysql_select_db("pq",$cn) or die(mysql_error());
$sql = "SELECT * FROM user";
$rs = mysql_query($sql) or die(mysql_error());
echo "<select>";
while($row = mysql_fetch_array($rs)){
echo "<option value=".$row["Email"].">".$row["Position"]."</option>";
$_POST['Email']='".$row["Email"]."';
echo $email=$_POST['Email'];
}
mysql_free_result($rs);
echo "</select>";
?>
<button type="submit" name="submit" value="Submit">Notify</button>
</form>
</body>
</html>
ipdnotify2.php
<?php
echo $_SESSION['Email'];
error_reporting(E_ALL);
$cn=mysql_connect("localhost","pqa","") or die(mysql_error());
mysql_select_db("pq",$cn) or die(mysql_error());
$sql = "SELECT Email FROM user where Userid>0 order by Username desc limit 1";
$rs = mysql_query($sql) or die(mysql_error());
if($row=mysql_fetch_array($rs))
{
echo "Email:<input type='text' name='Email' value='".$row['Email']."'><br>";
mysql_free_result($rs);
}
if( isset($_POST["submit"]) )
{
echo $email=$row['Email'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = '2'; // Specify main and backup server
//$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = false; // Enable SMTP authentication
//$mail->Username = ''; // SMTP username
//$mail->Password = ''; // SMTP password
//$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$mail->From = $_SESSION['Email'];
$mail->FromName = $_SESSION['Username'];
echo $mail->AddAddress('$email'); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'IPDS system Notification';
$mail->Body = 'Please do your <strong>Improvement Plan</strong>';
$mail->AltBody = 'Appreciate if you could process Improvement Plan. Thank you.';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
}
echo 'Message has been sent';
?>