gpt4 book ai didi

javascript - 在数据库和邮件中发送联系表单数据

转载 作者:行者123 更新时间:2023-11-30 00:26:01 26 4
gpt4 key购买 nike

现在我有数据库连接和mail.php的代码

我想将联系表单数据保存在数据库中(效果很好),并将邮件发送到我的电子邮件地址(不知道如何将代码与manage_comments.php一起放置)

这是我的联系方式,manage_comments.php、mail.php 和 javascript

请帮助我将相同的数据保存在数据库中并发送电子邮件

联系表格

    <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>

ma​​nage_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);
}
?>

ma​​il.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

<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>

最佳答案

您可以简单地使用 include 并 POST 到 manage_comments.php:

ma​​nage_comments.php

    [...]
mysql_close($con);

include "mail.php";
}

关于javascript - 在数据库和邮件中发送联系表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22878674/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com