Javascript 在数据库和;邮政
现在我有了数据库连接和mail.php的代码 我希望将联系人表单数据保存在数据库中(这很好),并将邮件发送到我的电子邮件地址(不知道如何使用manage_comments.php编写代码) 这是我的联系人,来自manage_comments.php、mail.php和javascript Plz帮助我将相同的数据保存在数据库中,并发送电子邮件 联系方式Javascript 在数据库和;邮政,javascript,php,mysql,email,Javascript,Php,Mysql,Email,现在我有了数据库连接和mail.php的代码 我希望将联系人表单数据保存在数据库中(这很好),并将邮件发送到我的电子邮件地址(不知道如何使用manage_comments.php编写代码) 这是我的联系人,来自manage_comments.php、mail.php和javascript Plz帮助我将相同的数据保存在数据库中,并发送电子邮件 联系方式 <form method='post' action="manage_comments.php"> Name: <
<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
<?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);
}
?>
<?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;
?>
[...]
mysql_close($con);
include "mail.php";
}
您只需使用包含
,然后发布到管理注释。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);
}
?>
<?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;
?>
[...]
mysql_close($con);
include "mail.php";
}
只要包含在manage_comments.php中就可以了???是的,您只需要调用额外的代码,对吗?它不是特别好的样式(您至少应该创建一个函数emailForm()
或类似的),但它可以工作。好的,让我试试。。。您还可以帮我做以下几件事吗:--------------------------------------在表单存在的同一标记中打开感谢消息,只需禁用表单并启用感谢消息