[英]send contact form data in both database & mail
right now I am having code for database connection as well as mail.php 现在我有用于数据库连接以及mail.php的代码
I want save contact form data in database(which is working very well) as well as send mail also to my email address(Don't know how to put code with manage_comments.php) 我想将联系表单数据保存在数据库中(运行良好),也将邮件发送到我的电子邮件地址(不知道如何使用manage_comments.php放置代码)
Here is my contact from, manage_comments.php, mail.php & javascript 这是我的联系人,来自manage_comments.php,mail.php和javascript
Plz help me with same data to be saved in database as well as send email 请帮助我将相同的数据保存在数据库中以及发送电子邮件
contact form 联系表
<form method='post' action="manage_comments.php">
Name: <input type='text' name='name' id='name' />
<div style="color:red;" id="nameerror"></div><br />
Email: <input type='text' name='email' id='email' />
<div style="color:red;" id="emailerror"></div><br />
Contact: <input type='text' name='contact' id='contact' />
<div style="color:red;" id="phoneerror"></div><br />
<input type='submit' value='Submit' class="mailbtn" />
</form>
manage_comments.php manage_comments.php
<?php
if( $_POST )
{
$con = mysql_connect("localhost","username","pwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db_name", $con);
$users_name = $_POST['name'];
$users_email = $_POST['email'];
$users_contact = $_POST['contact'];
$users_name = mysql_real_escape_string($users_name);
$users_email = mysql_real_escape_string($users_email);
$users_contact = mysql_real_escape_string($users_contact);
$query = "
INSERT INTO `my_db_name`.`table_name` (`id`, `name`, `email`, `contact`)
VALUES ( Null, '$users_name', '$users_email', '$users_contact');";
mysql_query($query);
echo "<h2>Thank you for your Comment!</h2>";
mysql_close($con);
}
?>
mail.php mail.php
<?php
$to = array("email_Ad1","email_Ad2");
$subject = "My subject";
$message = "Inquiry from <b>".$_POST['name']."</b> and phone number is <b>".$_POST['phn']."</b>!";
$message .= "<br><br>";
$message .= "<table border='1'>";
$message .= "<tr><td>Name </td><td>".$_POST['name']."</td></tr>";
$message .= "<tr><td>Phone </td><td>".$_POST['phn']."</td></tr>";
$message .= "<tr><td>Email </td><td>".$_POST['email']."</td></tr>";
$message .= "</table>";
$from = "other_email_Ad";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= 'from: '.$from .'' . "\r\n" .
'Reply-To: '.$from.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
foreach($to as $row)
{
mail($row,$subject,$message,$headers);
}
echo "Mail Sent.";
die;
?>
javascript javascript
<script type="text/javascript">
$('.mailbtn').live('click',function(){
name = $('#name').val();
phn = $('#contact').val();
email= $('#email').val();
---------validations----------------
$.ajax({
type: "POST",
async : true,
url: "mail.php",
data: { name:name, email:email, phn:phn}
})
.done(function( msg ) {
$('.mail_middle').html('');
$('.mail_middle').html('Thank you for quote request. One of the Flamingo Transworld team members will get back to you soon.');
return false;
});
</script>
You could simply use include
and just POST to manage_comments.php
: 您可以只使用
include
而仅将POST到manage_comments.php
:
manage_comments.php manage_comments.php
[...]
mysql_close($con);
include "mail.php";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.