在填写表单或使用mysql中的触发器后将id号发送到他们的电子邮件

jecbmhm3  于 2021-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(364)

我看了其他问题,没有什么很适合,我正在努力适应我的代码部分,我已经建立了迄今为止,但新的东西,我加入我得到错误,我相信我不远了。我想学着做,所以我会继续努力。
我不指望有人为我做,我想做,并了解如何工作,不断提高。
所以我的mysql数据库有一个id字段自动递增和客户机细节。
在我的客户填写表格后,我想把一封带有他们身份证号码的电子邮件发送到他们刚刚在表格中输入的电子邮件地址(有意义吗?)
我可以这样做,因为客户填写表格后才在数据库中获得id号吗?
好 啊!写这篇文章的时候我意识到也许我可以在mysql数据库中创建一个触发器,一旦细节进入数据库,我就可以向客户端发送一封带有id号的电子邮件。
我只是在谷歌上搜索了一下,不知道是否可能
到目前为止,我的代码是这个,我建立了它,它的工作是一种享受!这是一个漫长的过程,但我正在实现并热爱它!

<?php

require 'connection.php';
$conn    = Connect();
$date    = $conn->real_escape_string($_POST['u_date']);
$name    = $conn->real_escape_string($_POST['u_name']);
$company    = $conn->real_escape_string($_POST['u_company']);
$tel    = $conn->real_escape_string($_POST['u_tel']);
$mtel    = $conn->real_escape_string($_POST['m_tel']);
$email   = $conn->real_escape_string($_POST['u_email']);
$occupation   = $conn->real_escape_string($_POST['occupation']);
$hear   = $conn->real_escape_string($_POST['hear']);
$used   = $conn->real_escape_string($_POST['used']);
$signature    = $conn->real_escape_string($_POST['signature']);

$query   = "INSERT into tb_cform (u_date,u_name,u_company,u_tel,m_tel,u_email,occupation,hear,used,signature)     VALUES('" . $date . "','" . $name . "','" . $company . "','" . $tel . "','" .     $mtel . "','" . $email . "','" . $occupation . "','" . $hear . "','" . $used .     "','" . $signature . "')";
$success = $conn->query($query);

if (!$success) {
die("Couldn't enter data: ".$conn->error);

}

echo "<p><center>Thank you <strong>$name</strong>, your message has been submitted to us. Check your email for your ID number</center></p>";

$conn->close();

?>

提前谢谢!

2exbekwf

2exbekwf1#

当您插入一条记录并想知道id值时,最简单的方法是获取 LAST_INSERT_ID() . 与 mysqli 这实际上很简单 insert_id :

$id = $conn->insert_id;
5jdjgkvh

5jdjgkvh2#

所以我找到了一个绕过身份证号码的方法,但我只想让它给我发一封电子邮件,然后把它放到联系表格里,它可以把它放到数据库里,但是我需要一些关于电子邮件发送部分代码的帮助。谢谢

<?php

 require 'connection.php';

 $conn    = Connect();
 $pass    = $conn->real_escape_string($_POST['pass']);
 $date    = $conn->real_escape_string($_POST['u_date']);
 $name    = $conn->real_escape_string($_POST['u_name']);
 $company    = $conn->real_escape_string($_POST['u_company']);
 $tel    = $conn->real_escape_string($_POST['u_tel']);
 $mtel    = $conn->real_escape_string($_POST['m_tel']);
 $email   = $conn->real_escape_string($_POST['u_email']);
 $occupation   = $conn->real_escape_string($_POST['occupation']);
 $hear   = $conn->real_escape_string($_POST['hear']);
 $used   = $conn->real_escape_string($_POST['used']);
 $signature    = $conn->real_escape_string($_POST['signature']);

 $query   = "INSERT into tb_cform (pass,u_date,u_name,u_company,u_tel,m_tel,u_email,occupation,hear,used,signature) VALUES('" . $pass . "','" . $date . "','" . $name . "','" . $company . "','" . $tel . "','" . $mtel . "','" . $email . "','" . $occupation . "','" . $hear . "','" . $used . "','" . $signature . "')";

 $success = $conn->query($query);

 $header = "From: $email\n" . "Reply-To: $email\n";
 $subject = "Inquiry Received";
 $email_to = "info@mydomain.co.uk";
 $message = "Full Name: $name\n"
           . "Word: $pass\n"
           . "Email: $email\n";
mail($email_to, $subject, $message, $header);

if (!$success) {
die("Couldn't enter data: ".$conn->error);

 }

 echo "<p><center>Thank you <strong>$name</strong>, your message has been 
 submitted to us.</center></p>";

 $conn->close();

 ?>

相关问题