Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
联系人表单PHP电子邮件脚本_Php_Forms_Email_Twitter Bootstrap - Fatal编程技术网

联系人表单PHP电子邮件脚本

联系人表单PHP电子邮件脚本,php,forms,email,twitter-bootstrap,Php,Forms,Email,Twitter Bootstrap,您好,我的网站上的电子邮件脚本有问题 我用这个文件 但是我添加了一些字段。它正在发送到我的电子邮件,但我没有收到字段中输入的所有数据 这是我的HTML表单 <form role="form" id="feedbackForm"> <div class="form-group"> <input type="text" class="form-control" id="first_name" name="first_name

您好,我的网站上的电子邮件脚本有问题

我用这个文件

但是我添加了一些字段。它正在发送到我的电子邮件,但我没有收到字段中输入的所有数据

这是我的HTML表单

<form role="form" id="feedbackForm">
          <div class="form-group">
            <input type="text" class="form-control" id="first_name" name="first_name" placeholder="First Name">
            <span class="help-block" style="display: none;">Please enter your name.</span>
          </div>
          <div class="form-group">
            <input type="text" class="form-control" id="last_name" name="last_name" placeholder="Last Name">
            <span class="help-block" style="display: none;">Please enter your name.</span>
          </div>
          <div class="form-group">
            <input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
            <span class="help-block" style="display: none;">Please enter a valid e-mail address.</span>
          </div>
          <div class="form-group">
            <input type="text" class="form-control" id="company_name" name="company_name" placeholder="Company">
            <span class="help-block" style="display: none;">Please enter your name.</span>
          </div>
          <div class="form-group">
            <textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
            <span class="help-block" style="display: none;">Please enter a message.</span>
          </div>
          <div class="form-group">
            <label for="selectbasic">How did you hear about us?</label>
                <select id="selectbasic" name="selectbasic" class="form-control">
                    <option>Select</option>
                    <option>Search engine</option>
                    <option>Microsoft DPE</option>
                    <option>Microsoft event</option>
                    <option>Social media</option>
                    <option>Word of mouth</option>
                    <option>Other</option>
                </select>
            </div>
          <img id="captcha" src="library/vender/securimage/securimage_show.php" alt="CAPTCHA Image" />
          <a href="#" onclick="document.getElementById('captcha').src = 'library/vender/securimage/securimage_show.php?' + Math.random(); return false" class="btn btn-info btn-sm">Show a Different Image</a><br/>
          <div class="form-group" style="margin-top: 10px;">
            <input type="text" class="form-control" name="captcha_code" id="captcha_code" placeholder="For security, please enter the code displayed in the box." />
            <span class="help-block" style="display: none;">Please enter the code displayed within the image.</span>
          </div>

          <span class="help-block" style="display: none;">Please enter a the security code.</span>
          <button type="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style="display: block; margin-top: 10px;">Send Feedback</button>
        </form>

请输入您的姓名。
请输入您的姓名。
请输入有效的电子邮件地址。
请输入您的姓名。
请输入一条消息。
你是怎么听说我们的?
挑选
搜索引擎
微软DPE
微软事件
社会化媒体
口头传述的
其他

请输入图像中显示的代码。 请输入一个安全代码。 发送反馈
这是我的PHP脚本

<?php
 //start a session -- needed for Securimage Captcha check
 session_start();

 //add you e-mail address here
 define("MY_EMAIL", "dummyemail@gmail.com");

/**
 * Sets error header and json error message response.
 *
 * @param  String $messsage error message of response
 * @return void
 */
function errorResponse ($messsage) {
header('HTTP/1.1 500 Internal Server Error');
die(json_encode(array('message' => $messsage)));
}

/**
 * Return a formatted message body of the form:
 * Name: <name of submitter>
 * Comment: <message/comment submitted by user>
 *
 * @param String $name     name of submitter
 * @param String $messsage message/comment submitted
 */
function setMessageBody ($first_name, $last_name, $email, $message, $selectbasic) {
  $message_body = "Name: " . $first_name. $last_name. "\n\n";
  $message_body = "Email: " . $email."\n\n";
  $message_body = "Company Name: " . $company_name."\n\n";
  $message_body .= "Message:\n" . nl2br($message);
  $message_body .= "How did you hear about us?:" . $selectbasic."\n\n";
  return $message_body;
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];  
$email = $_POST['email']; 
$company_name = $_POST['company_name']; 
$message = $_POST['message'];
$selectbasic = $_POST['selectbasic'];

header('Content-type: application/json');
//do some simple validation. this should have been validated on the client-side also
if (empty($email) || empty($message)) {
errorResponse('Email or message is empty.');
}

//do Captcha check, make sure the submitter is not a robot:)...
include_once './vender/securimage/securimage.php';
$securimage = new Securimage();
if (!$securimage->check($_POST['captcha_code'])) {
  errorResponse('Invalid Security Code');
}

//try to send the message
if(mail(MY_EMAIL, "Feedback Form Results", setMessageBody($_POST["first_name"],         
$_POST["last_name"], $_POST["email"], $_POST["selectbasic"], $message), "From:    
 $first_name, $last_name")) {
echo json_encode(array('message' => 'Your message was successfully submitted.'));

  } else {
header('HTTP/1.1 500 Internal Server Error');
echo json_encode(array('message' => 'Unexpected error while attempting to send e-   
 mail.'));
 }
 ?>

看起来还可以,只需修改一下:

<form role="form" id="feedbackForm" method="post">  

在表单标记中添加method属性,因为在代码中没有定义任何post方法,而是
get
。所以你有两个选择

一次修改


将所有
$\u POST
修改为
$\u GET
如下更新您的HTML表单:

<form action="email.php" method="post" role="form" id="feedbackForm">

我可以给你更好的解决方案,如果你能给我什么数据,你收到的电子邮件。 但看起来,您在这一行的函数setMessageBody(…)中遗漏了一些点(.)-

$message_body = "Email: " . $email."\n\n";
$message_body = "Company Name: " . $company_name."\n\n";
添加点(.)-

选中您的选择选项。你的线路

<option>Select</option>
<option>Search engine</option>
<option>Microsoft DPE</option>
<option>Microsoft event</option>
<option>Social media</option>
<option>Word of mouth</option>
<option>Other</option>
选择
搜索引擎
微软DPE
微软事件
社会化媒体
口头传述的
其他
会像-

<option>Select</option>
<option value="Search engine">Search engine</option>
<option value="Microsoft DPE">Microsoft DPE</option>
<option value="Microsoft event">Microsoft event</option>
<option value="Social media">Social media</option>
<option value="Word of mouth">Word of mouth</option>
<option value="Other">Other</option>
选择
搜索引擎
微软DPE
微软事件
社会化媒体
口头传述的
其他

你好!在等号前加一个点会有帮助,但我仍然缺少字段。我已经编辑了我的帖子。我附上了发送给我的电子邮件。对不起,我看不到任何图片!你能把截图上传到别处并给我图片链接吗?缺少的是公司名称。我将编辑我的帖子,并将我正在使用的新php代码放入其中。谢谢你的帮助。加上那个点有帮助!我已经获得了所有详细信息:)还请选中“选择更新”选项。如果你不按我说的那样做,你就不能得到他选的东西。
$message_body .= "Email: " . $email."\n\n";
$message_body .= "Company Name: " . $company_name."\n\n";
<option>Select</option>
<option>Search engine</option>
<option>Microsoft DPE</option>
<option>Microsoft event</option>
<option>Social media</option>
<option>Word of mouth</option>
<option>Other</option>
<option>Select</option>
<option value="Search engine">Search engine</option>
<option value="Microsoft DPE">Microsoft DPE</option>
<option value="Microsoft event">Microsoft event</option>
<option value="Social media">Social media</option>
<option value="Word of mouth">Word of mouth</option>
<option value="Other">Other</option>