所以我有一个循环,它发送电子邮件到hours_left <= .5
的所有记录。
使用:$sql = 'SELECT first_name, email, last_emailed FROM clients WHERE hours_left <= .5';
我抓住要发送的电子邮件。
在第4行,我认为我会将身体设置在那里,所以它可以说:&#34;你好<first_name>
,检查一下。&#34;但是我不确定如何访问first_name
以便身体随着每个人的变化而变化。我是php的新手,对于像我这样的假人来说,更容易解释会很棒。
while ($row = $result->fetch_assoc()) {
var_dump($row);
$mail->addAddress($row['email'], $row['first_name']);
$mail->Body = "hello" ; // <----this is where I'm clueless
if (!$mail->send()) {
echo "Mailer Error (" . str_replace("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
break; //Abandon sending
} else {
echo "Message sent to :" . $row['first_name'] . ' (' . str_replace("@", "@", $row['email']) . ')<br />';
//preapre statement safer way of updating shit
if (!($stmt = $mysqli->prepare("UPDATE clients SET last_emailed = ? WHERE email = ?"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param('ss', $today, $row['email'])) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$stmt->close();
}
// Clear all addresses and attachments for next loop
$mail->clearAddresses();
}
我无法准确地描述我应该谷歌的内容,所以现在我在这里。哦,我也使用PHPMailer,我正在发送和访问数据库,除了弄清楚如何插入将接收此消息的人first_name
之外,一切都在工作。
答案 0 :(得分:0)
替换此行:
$mail->Body = "hello" ; // <----this is where I'm clueless
<强>与强>
$mail->Body = "hello {$row['first_name']}";
或强>
$name = $row['first_name']; $mail->Body = "hello $name";
或强>
$name = $row['first_name']; $mail->Body = "hello ".$name;
PS:你必须在循环中做到这一点。