Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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中的lightbox联系人表单_Php_Forms_Lightbox_Contact - Fatal编程技术网

php中的lightbox联系人表单

php中的lightbox联系人表单,php,forms,lightbox,contact,Php,Forms,Lightbox,Contact,我现在完全同意这一点。当lightbox联系人表单发布到lightbox中时,我需要成功消息。未发送邮件,也未显示成功消息 我的站点中有以下代码来收集数据并将其发布到发送邮件的单独页面。问题是电子邮件不是使用mail.php文件发送的。我需要帮助 <script> function sendEmail() { // 1. Create XHR instance - Start var xhr;

我现在完全同意这一点。当lightbox联系人表单发布到lightbox中时,我需要成功消息。未发送邮件,也未显示成功消息

我的站点中有以下代码来收集数据并将其发布到发送邮件的单独页面。问题是电子邮件不是使用mail.php文件发送的。我需要帮助

<script>
        function sendEmail() {
            // 1. Create XHR instance - Start

            var xhr;
            if (window.XMLHttpRequest) {
                xhr = new XMLHttpRequest();
            }

            else if (window.ActiveXObject) {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            }
            else {
                throw new Error("Form is not supported by this browser");
            }

            // 1. Create XHR instance - End

            // 2. Define what to do when XHR feed you the response from the server - Start

            xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                    if (xhr.status == 200 && xhr.status < 300) {
                        // document.getElementById('loadix').innerHTML = xhr.responseText;
                        if(xhr.responseText == "success"){
                            $('#confirmation').html("<h2><i>Thank you for Registering for the webinar. An email with a link to the webinar will be emailed to you soon.</i></h2>");
                            $('#tosend').val(0);
                        }
                        else {
                            $('#confirmation').html("<h2>Email sending failed</h2>");
                        }
                    }
                }
            }
            // 2. Define what to do when XHR feed you the response from the server - Start
            var message = document.getElementById("message").value;
    var subject = document.getElementById("subject").value;
            var email = document.getElementById("email").value;
    var Home_phone = document.getElementById("Home_phone").value;
    var full_name = document.getElementById("full_name").value;
    var day = document.getElementById("day").value;
            var tosend = document.getElementById("tosend").value;

            var post_str = "&message=" + message +"&subject=" + subject +"&email=" + email +"&Home_phone=" + Home_phone +"&full_name=" + full_name +"&day=" + day;

            // 3. Specify your action, location and Send to the server - Start 
            if(tosend == 1){
                xhr.open('POST', 'mail.php');
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xhr.send(post_str);
            }
            // 3. Specify your action, location and Send to the server - End

    return true;
      }

函数sendmail(){
//1.创建XHR实例-启动
var-xhr;
if(window.XMLHttpRequest){
xhr=newXMLHttpRequest();
}
else if(window.ActiveXObject){
xhr=新的ActiveXObject(“Msxml2.XMLHTTP”);
}
否则{
抛出新错误(“此浏览器不支持表单”);
}
//1.创建XHR实例-结束
//2.定义当XHR从服务器向您提供响应时要做什么-启动
xhr.onreadystatechange=函数(){
if(xhr.readyState==4){
如果(xhr.status==200&&xhr.status<300){
//document.getElementById('loadix').innerHTML=xhr.responseText;
如果(xhr.responseText==“成功”){
$(“#确认”).html(“感谢您注册参加网络研讨会。我们将很快通过电子邮件向您发送一封带有网络研讨会链接的电子邮件。”);
$('#tosend').val(0);
}
否则{
$(“#确认”).html(“电子邮件发送失败”);
}
}
}
}
//2.定义当XHR从服务器向您提供响应时要做什么-启动
var message=document.getElementById(“message”).value;
var subject=document.getElementById(“subject”).value;
var email=document.getElementById(“email”).value;
var Home\u phone=document.getElementById(“Home\u phone”).value;
var full_name=document.getElementById(“full_name”).value;
var day=document.getElementById(“day”).value;
var tosend=document.getElementById(“tosend”).value;
var post_str=“&message=“+message+”&subject=“+subject+”&email=“+email+”&Home_phone=“+Home_phone+”&full_name=“+full_name+”&day=“+day;
//3.指定您的操作、位置并发送到服务器-启动
如果(tosend==1){
open('POST','mail.php');
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
xhr.send(post_str);
}
//3.指定您的操作、位置并发送到服务器端
返回true;
}

mail.php包含以下代码

<?php

if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "xxx@gmail.com"; 
$full_name = $_POST['full_name']; // required 
$day = $_POST['day']; // required 
$email_from = $_POST['email']; // required
$Home_phone = $_POST['Home_phone']; // not required 
$subject = $_POST['subject']; // required
$message = $_POST['message']; // required

$email_message = "Webinar request details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string); 
}
$email_message .= "Message: ".clean_string($message)."\n";
$email_message .= "Name: ".clean_string($full_name)."\n";
$email_message .= "Home_phone: ".clean_string($Home_phone)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n"; 
$email_message .= "Day: ".clean_string($day)."\n";

// create email headers

$headers = 'From: '.$email_from."\r\n".
 'Reply-To: '.$email_from."\r\n" .
 'X-Mailer: PHP/' . phpversion();
 @mail($email_to, $email_subject, $email_message, $headers); 
}
?>

也许您可以看看jQuery中的ajax调用。这是一种用不到3行代码发出复杂post请求的简单方法。使用jqXHR对象,您可以处理响应。

在mail.php中,您使用了mail函数。开始时您使用@,这意味着mail函数不会抛出任何错误。也许你必须删除它才能在发送电子邮件时看到任何错误

这里有一个更新的mail.php

<?php
if (isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "xxx@gmail.com";
    $full_name = $_POST['full_name']; // required 
    $day = $_POST['day']; // required 
    $email_from = $_POST['email']; // required
    $Home_phone = $_POST['Home_phone']; // not required 
    $subject = $_POST['subject']; // required
    $message = $_POST['message']; // required

    $email_message = "Webinar request details below.\n\n";

    function clean_string($string) {
        $bad = array("content-type", "bcc:", "to:", "cc:", "href");
        return str_replace($bad, "", $string);
    }

    $email_message .= "Message: " . clean_string($message) . "\n";
    $email_message .= "Name: " . clean_string($full_name) . "\n";
    $email_message .= "Home_phone: " . clean_string($Home_phone) . "\n";
    $email_message .= "Email: " . clean_string($email_from) . "\n";
    $email_message .= "Day: " . clean_string($day) . "\n";

    $headers = 'From: ' . $email_from . "\r\n" .
        'Reply-To: ' . $email_from . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    $error = @mail($email_to, $email_subject, $email_message, $headers);
    if ($error) {
        header($_SERVER['SERVER_PROTOCOL'] . ' Internal Server Error', true, 500);
    }
} else {
    header($_SERVER['SERVER_PROTOCOL'] . ' Bad Request', true, 400);
}