我试图使用phpmail函数发送邮件给用户,如果他们的帖子被接受。首先,如果表单已提交,我将在查询中捕获用户电子邮件,但我不确定如何实现邮件功能。它应该是这样的?:如果提交表单提交php邮件给用户
if(isset($_POST ['submit'])){
//Some query to get the user email address
$results = $dbh->prepare("select $user_email from wp_users where
wp_users.ID=$user_ID");
$to=$results;
$subject="Whatever you want your subject to be";
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message= "WHATEVER MESSAGE";
mail ($to , $subject , $message, $headers);
echo "Your message has been sent";
$insrt = "INSERT INTO table(ID,
text,
VALUES (
:ID,
:text)";
$stmt = $dbh->prepare($insrt);
$stmt->bindParam(':ID', $user_ID, PDO::PARAM_INT);
$stmt->bindParam(':text', $_POST['post_text'], PDO::PARAM_STR);
$stmt->execute();
}
你确定这是正确的'select $ user_email' – Shehary
和你的意思'发送邮件到$ results ?????你wana发送电子邮件到mysql查询? – Shehary
选择$ user_email只是为了表达想法。我主要询问查询后的评论部分。我知道我需要在邮件被接受时收到用户的电子邮件(我将用查询捕获并保存诸如$ results的内容),但我无法弄清楚的是如何实际发送邮件到该邮件用户在他们的电子邮件($结果) – JW500