在表单提交中获取id并输入PHP邮件
我创建了一个票证系统,它执行以下操作:(仅供参考,st_id是我表中的id)在表单提交中获取id并输入PHP邮件,php,mysql,forms,email,phpmailer,Php,Mysql,Forms,Email,Phpmailer,我创建了一个票证系统,它执行以下操作:(仅供参考,st_id是我表中的id) 用户填写表单并点击提交 提交后,它会从表单中获取信息,并通过phpmailer发送电子邮件给我 在电子邮件处理过程中,它还将所有信息输入到支持票证表中 我遇到的问题是,我使用support_ticket tables st_id作为票号 Ticket Number: '.$st_id.' 当用户填写表单时,条目首先通过电子邮件发送所有表单数据,而不是获取st_id号 我需要在电子邮件中显示st_id号 因此,我正
- 用户填写表单并点击提交
- 提交后,它会从表单中获取信息,并通过phpmailer发送电子邮件给我
- 在电子邮件处理过程中,它还将所有信息输入到支持票证表中
Ticket Number: '.$st_id.'
当用户填写表单时,条目首先通过电子邮件发送所有表单数据,而不是获取st_id号
我需要在电子邮件中显示st_id号
因此,我正在寻求有关如何将st_id/票号与其他数据一起发送到电子邮件的帮助。
// form data
$ticket_type = $_POST['ticket_type'];
$subject = $_POST['subject'];
$content = $_POST['content'];
$user_id = $_POST['user_id'];
$unit = $_POST['unit'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$st_id = $_POST['st_id'];
// query
$addticket = DB::getInstance()->insert('support_ticket', array(
//'st_id' => $st_id,
'ticket_type' => $ticket_type,
'subject' => $subject,
'content' => $content,
'user_id' => $user_id,
'unit' => $unit,
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'phone' => $phone
));
下面是我的数据库的外观
下面是发送给我的电子邮件的样子:
在动作脚本中,我有以下内容。
// form data
$ticket_type = $_POST['ticket_type'];
$subject = $_POST['subject'];
$content = $_POST['content'];
$user_id = $_POST['user_id'];
$unit = $_POST['unit'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$st_id = $_POST['st_id'];
// query
$addticket = DB::getInstance()->insert('support_ticket', array(
//'st_id' => $st_id,
'ticket_type' => $ticket_type,
'subject' => $subject,
'content' => $content,
'user_id' => $user_id,
'unit' => $unit,
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'phone' => $phone
));
然后是电子邮件部分:
User::sendNewticket('myemail@fake.com', 'Subject of email', '<strong>'.Input::get('first_name') .' '.Input::get('last_name').'</strong>, from unit <strong>'.Input::get('unit').',</strong> ' . 'has called in a maintenance ticket for the following:<br><br>
<strong>Ticket Number:</strong> '.Input::get('st_id') .'<br><br>
<strong>Ticket Type:</strong> '.Input::get('ticket_type') .'<br><br>
<strong>Subject:</strong> '.Input::get('subject') .'<br><br>
<strong>Message:</strong> '.Input::get('content') .'<br><br>
....etc
User::sendNewticket('myemail@fake.com“,”电子邮件主题“,””。Input::get('first_name')。”。Input::get('last_name')。,来自单位”。Input::get('unit'),。。”已为以下事项发出维护通知单:
票号:”。输入::获取('st_id')。
票证类型:”。输入::获取(“票证类型”)。
主题:”。输入::获取('Subject')。
消息:”。输入::获取('content')。
等
我需要找到一种方法来获取票号:'。输入::获取('st_id')。
这就可以了
我认为我需要编写一个查询,从表中获取st_id,并在发送电子邮件之前将其发布到电子邮件脚本中,但同样不确定如何使其工作
任何想法或解决方案都将不胜感激。如果您需要我发布更多代码,请让我知道。我尽量将相关内容保持在最低限度。在此插入查询下,我添加了:
$addticket = DB::getInstance()->insert('support_ticket', array(
//'st_id' => $st_id,
'ticket_type' => $ticket_type,
'subject' => $subject,
'content' => $content,
'user_id' => $user_id,
'unit' => $unit,
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'phone' => $phone
));
$st_id = DB::getInstance()->lastInsertId();
在我的DB.php类文件中,我必须添加以下内容:
public function lastInsertId() {
return $this->_pdo->lastInsertId();
}
最后,在我的电子邮件部分,我简单地添加了这个来检索票号
Ticket Number: '.$st_id.'
请不要发布双倍行距的代码。我没有看到真正起作用的代码。逻辑应该是:1.插入,2.获取(缺失)3.发送邮件。如果用户正在创建一个新的票证,那么在他们填写之前没有ID,因此在隐藏字段中没有任何内容。ID是在您在DB中创建票证时分配的。正如@VMai所说,您将票证添加到DB中,获取分配的ID,然后将其放入邮件中。大多数数据库API还提供了一种获取它。查看并。@echo,您就快到了-
$addticket
不是PDO实例,因此无法工作,请在插入后尝试$st_id=DB::getInstance()->lastInsertId();
,它将返回新插入的记录的id,无需再进行查询。