因此,我一直致力于一个项目,并且我有一个将电子邮件发送给选择雇主的员工的功能。现在这个工作除了邮件功能(我使用WinHost,我们需要包括Mail.php为了使邮件功能工作)它有时会发送3封电子邮件,而不是2,有时1封电子邮件,而不是2.在php中发送邮件的问题
代码:
if (isset($_POST['openemailmem'])){
$memberuser = $_POST['openemailmemusername'];
$sql = "SELECT email, username, password, status FROM csvdata WHERE memberview =:user ";
$getinfo=$DBH->prepare($sql);
$getinfo->execute(array(':user' => $memberuser));
while ($row = $getinfo->fetch(PDO::FETCH_ASSOC)) {
$check = $row;
$newEmployeeEmail = $check['email'];
$csvusername = $check['username'];
$password = $check['password'];
$status = $check['status'];
if ($status == "Open"){
echo "tesing";
$from = "the email of where it is coming from is here but i removed";
$to = $newEmployeeEmail;
if (!empty($_POST['cc'])){
$cc = $_POST['cc'];
}
if (!empty($_POST['ccsend'])){
$cc = $_POST['ccsend'];
$to .= ", $cc";
}
$subject = "removed msg";
$body = "removed msg";
$host = "i removed";
$username = "i removed";
$password = "i removed";
$headers = array ('From' => $from, 'To' => $to,'Cc' => $cc, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
}
}
header("Location: I removed this.php?getmsg=12");
exit;
}
感谢您所有的时间!
我修正了您的缩进。 – ceejayoz
您是否检查过您暗示的异常情况下数据库中的数据? – Thomas
你很好。 –