如果表单已提交,则将php邮件发送给用户 [英] Send php mail to user if form submitted

查看:71
本文介绍了如果表单已提交,则将php邮件发送给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户的帖子被接受,我正在尝试使用phpmail函数向用户发送电子邮件.首先,如果表单已提交,我将在查询中捕获用户电子邮件,但是我不确定如何实现邮件功能.应该是这样吗?:

I am trying to use the phpmail function to send an email to a user if their post was accepted. First I am capturing the user email in a query if a form is submitted, but I'm not sure how to implement the mail function. Should it be something like this?:

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: WHATEVER@WHATEVER.COM\r\n";
$headers .= "Reply-To: WHATEVER@WHATEVER.COM \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(); 
} 

推荐答案

如果我对您的理解正确,则可以执行以下操作:

If I understand you correctly, you could do the following:

try{

/*YOUR INSERT STATEMENT FROM ABOVE*/

$to=$results;
$subject="Whatever you want your subject to be";
$headers = "From: WHATEVER@WHATEVER.COM\r\n";
$headers .= "Reply-To: WHATEVER@WHATEVER.COM \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";
}
Catch($error){
Do whatever you want here. Add another mail function to let you know that     the post was not accepted, etc.
}

让我知道这是您要去的吗.

Let me know if this is what you were going for.

这篇关于如果表单已提交,则将php邮件发送给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆