我正在努力弄清楚的第一件事是,是否可以将这个PHP表单添加到iframe中,这样我就可以将它放在几个不同的站点(Facebook,Wordpress,个人站点等)上。 如果不是,我怎么能创建一个表单,允许我将iframe代码放在不同的网站上并仍能正常运行?
目前我的表单只是将数据提交到我的电子邮件,但我希望数据也可以发布并存储在数据库中。我可以在iframe中执行此操作吗?
以下是我的表格..
HTML
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call"><br />
No:<input type="checkbox" value="No" name="call"><br />
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">New Products</option>
</select>
<br />
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "youremail@here.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
答案 0 :(得分:0)
是的,你可以这样做。
如果您在主机上托管iframe,则可以直接访问您的数据库。 mail.php文件应该发布。
在邮件发送之前或之后,在代码中使用此内容:
define('DBHOST', 'localhost');
define('DBNAME', '');
define('DBUSER', '');
define('DBPASS', '');
function nuukDb() {
$nuukDb = new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8', DBUSER, DBPASS);
$nuukDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$nuukDb->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$nuuk = $nuukDb->prepare("INSERT INTO tablename (value1, value2, value3) VALUES ('$name', '$email', '$phone')");
$nuuk->execute();