我已在表格中创建此表单插入数据
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
发布评论