dounieyan2036 2017-04-19 10: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 10: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

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀