Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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_Html_Forms_Contact - Fatal编程技术网

Php 我的联系方式没有发送任何电子邮件

Php 我的联系方式没有发送任何电子邮件,php,html,forms,contact,Php,Html,Forms,Contact,我在自己的vCard/简历网站上工作。 但是我在使用.php文件和联系表单时遇到了一些问题 我试图调试它,但没有成功 这是我的html表单 <!-- form --> <form name="contactForm" id="contactForm" method="post" action="inc/sendEmail.php"> <fieldset> <div class="form-field">

我在自己的vCard/简历网站上工作。 但是我在使用.php文件和联系表单时遇到了一些问题

我试图调试它,但没有成功

这是我的html表单

<!-- form -->
<form name="contactForm" id="contactForm" method="post" action="inc/sendEmail.php">
    <fieldset>
        <div class="form-field">
            <input name="contactName" type="text" id="contactName" placeholder="Name" value="" minlength="2" required>
        </div>
        <div class="form-field">
            <input name="contactEmail" type="email" id="contactEmail" placeholder="Email" value="" required>
        </div>
        <div class="form-field">
            <input name="contactSubject" type="text" id="contactSubject" placeholder="Subject" value="">
        </div>
        <div class="form-field">
            <textarea name="contactMessage" id="contactMessage" placeholder="Message" rows="10" cols="50" required></textarea>
        </div>
        <div class="form-field">
            <button class="submitform">Submit</button>
            <div id="submit-loader">
                <div class="text-loader">
                    Sending...
                </div>
                <div class="s-loader">
                    <div class="bounce1">
                    </div>
                    <div class="bounce2">
                    </div>
                    <div class="bounce3">
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
</form> 
<!-- Form End -->

提交
发送。。。
还有我的php文件

<?php
// Replace this with your own email address
$siteOwnersEmail = 'someone@example.com';
if($_POST) {
    $name = trim(stripslashes($_POST['contactName']));
    $email = trim(stripslashes($_POST['contactEmail']));
    $subject = trim(stripslashes($_POST['contactSubject']));
    $contact_message = trim(stripslashes($_POST['contactMessage']));
    // Check Name
    if (strlen($name) < 2) {
        $error['name'] = "Please enter your name.";
    }
    // Check Email
    if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
        $error['email'] = "Please enter a valid email address.";
    }
    // Check Message
    if (strlen($contact_message) < 15) {
        $error['message'] = "Please enter your message. It should have at least 15 characters.";
    }
    // Subject
    if ($subject == '') { $subject = "Contact Form Submission"; }
    // Set Message
    $message .= "Email from: " . $name . "<br />";
    $message .= "Email address: " . $email . "<br />";
    $message .= "Message: <br />";
    $message .= $contact_message;
    $message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
    // Set From: header
    $from =  $name . " <" . $email . ">";
    // Email Headers
    $headers = "From: " . $from . "\r\n";
    $headers .= "Reply-To: ". $email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if (!$error) {
        ini_set("sendmail_from", $siteOwnersEmail); // for windows server
        $mail = mail($siteOwnersEmail, $subject, $message, $headers);
        if ($mail) { echo "OK"; }
        else { echo "Something went wrong. Please try again."; }
    } # end if - no validation error
    else {
        $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
        $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
        $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
        echo $response;
    } # end if - there was a validation error
}
?>

您必须声明按钮的类型
type=“submit”
type=“button”
在这种情况下,使用表单,因此必须添加
type=“submit”

并检查用户点击按钮或直接访问您可以检查的文件
!空($\u POST)
带if

// Change in your HTML
<button class="submitform">Submit</button>
// to
<button type="submit" class="submitform">Submit</button>

//Change in your PHP
if($_POST)
// to
if(!empty($_POST))
//HTML中的更改
提交
//到
提交
//PHP中的更改
如果(美元邮政)
//到
如果(!空($\u POST))
请试试这个

<?php
$message ="";
if(isset($_POST)){
    mail(to,subject,message,headers,parameters);
}
?>


有任何错误消息吗?请尝试用print\r($mail)显示$mail的内容,在调用mail()之后插入对print\r的调用。没有错误消息。它只是不发送任何电子邮件。虽然这段代码可能会回答这个问题,但提供有关这段代码为什么和/或如何回答这个问题的附加上下文可以提高其长期价值。它不起作用:(那么你的意思是我应该更改我的整个php文件?你可以试试这个