发送电子邮件和插入数据到数据库php mysql

编程入门 行业动态 更新时间:2024-10-09 16:27:33
本文介绍了发送电子邮件和插入数据到数据库php mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已在表格中创建此表单插入数据

I have created this form for insert data in a table

<form class="form" method="post" action="myactionpage.php" enctype="multipart/form-data"> <p> <label>Name *</label> <input type="text" name="co_name" placeholder="Full Name" required /> </p> <p> <label>Mobile *</label> <input type="number" name="co_mobile" required /> </p> <p> <label>Email *</label> <input type="email" name="co_email" required /> </p> <p> <label>Message</label> <textarea rows="5" name="co_message" cols="15"></textarea> </p> <input type="submit" name="enq_submit" value="Apply Online" /> </form>

和我的操作php页

$host="localhost"; $username="root"; $password=""; $db_name="mydb"; $tbl_name="metbl"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(isset($_POST['enq_submit'])) { $name=$_POST['co_name']; $mobile=$_POST['co_mobile']; $email=$_POST['co_email']; $message=$_POST['co_message']; $sql="INSERT INTO $tbl_name(fco_name, fco_mobile, fco_email,fco_text)VALUES('$name', '$mobile', '$email','$message' )"; $result=mysql_query($sql); if($result){ echo "OK"; else { echo "ERROR"; } ?> <?php mysql_close(); } ?>

1)我想知道插入数据库后如何发送电子邮件田野。 2)我还需要更新另一个表,但我不知道该怎么做

1)I would like to know how after the insert to database could sent an email with the entries of the fields. 2)I need also to update another table but I am not sure how to do that

推荐答案

要发送电子邮件,基本的mail()php函数。

To send email, you can use the basic mail() php function.

首先,定义标题:

$headers = "From: myplace@yourdomain\r\n"; $headers .= "Reply-To: myplace2@yourdomain\r\n"; $headers .= "Return-Path: myplace@yourdomain\r\n"; $headers .= "CC: sombodyelse@anotherdomain\r\n"; $headers .= "BCC: hidden@anotherdomain\r\n"; $headers .= "X-Mailer: PHP/" . phpversion();

之后,将主题行放在变量中以方便使用:

After that, put the subject line in a variable for easier use:

$subject = "My example email subject";

接下来,您对电子邮件的正文也是这样:

Next you do the same for the email's body:

$body = "This is the body of the email.\n\n"; $body .= "The name is: ".$name."\n"; $body .= "The mobile is: ".$mobile."\n"; $body .= "The email is: ".$email."\n"; $body .= "The message is: ".$message."\n"; $body .= "This is the end of the message";

最后,指定收件人:

$to = "recipient@yourdomain";

包装成邮件功能:

mail($to, $subject, $body, $headers);

您已完成邮件!

有关邮件功能的详情,请访问此处。

More about mail function you can find here.

至于更新mysql,你可以这样做:

As for updating the mysql, you can do this:

首先确保你如何识别表。这可以通过例如行id来实现:

First make sure how you are going to identify the table. This can be done for example by the row id:

$id = "3"; //3 is hypothetical

然后运行查询:

mysql_query=("UPDATE other_tbl_name SET fco_name = '$name', fco_mobile = '$mobile', fco_email = '$email', fco_text = '$message' WHERE id = '$id'"); //here we used the row's id to specify which row to update

希望这是你在看for ...

Hope this was what you were looking for...

更多推荐

发送电子邮件和插入数据到数据库php mysql

本文发布于:2023-10-12 16:16:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485245.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   数据库   数据   mysql   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!