dounieyan2036 2017-04-19 02:29
浏览 71
已采纳

创建PHP iframe表单以将数据发布到电子邮件地址以及数据库表

The first thing I'm struggling to figure out is if it's possible to add this PHP form to an iframe so I can drop it on several different sites (Facebook, Wordpress, personal sites etc). If not how else can I create a form that will allow me to drop the iframe code on different sites and still function correctly?

Currently my form just submits the data to my email but I want the data to also get posted and stored within a database. Can I do this within an iframe?

Below is my form..

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 
 Phone: $phone 
 Call Back: $call 
 Website: $website 
 Priority: $priority 
 Type: $type 
 Message: $message";
$recipient = "youremail@here.com";
$subject = "Contact Form";
$mailheader = "From: $email 
";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

展开全部

  • 写回答

1条回答 默认 最新

  • dsm0688 2017-04-19 02:46
    关注

    Yes, you can do this.

    If you host the iframe on your host, you have direct access to your database. The mail.php file should do the posting.

    Use this inside your code, before or after mailing the message:

    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();
    

    Reference: https://github.com/wolffe/nuuk

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
  • ¥15 ctrl win alt 键一直触发
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部