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

为什么我的PHP联系人表单没有在消息中发送

为什么我的PHP联系人表单没有在消息中发送,php,email,Php,Email,好的,我在我的网站上得到了这个表格,当我测试它并试图发送电子邮件时,它说消息已经发送了,但我无法将它发送到我的电子邮件中 代码如下: contact.php: <?php function ValidateEmail($email) { $regex = '/([a-z0-9_.-]+)'. # name '@'. # at '([a-z0-9.-]+){1,255}'. # domain & possibly subdomains '.'. # p

好的,我在我的网站上得到了这个表格,当我测试它并试图发送电子邮件时,它说消息已经发送了,但我无法将它发送到我的电子邮件中

代码如下:

contact.php:

<?php
function ValidateEmail($email)
{
    $regex = '/([a-z0-9_.-]+)'. # name
    '@'. # at
    '([a-z0-9.-]+){1,255}'. # domain & possibly subdomains
    '.'. # period
    "([a-z]+){2,10}/i"; # domain extension 
    if($email == '') {
        return false;
    }
    else {
        $eregi = preg_replace($regex, '', $email);
    }
    return empty($eregi) ? true : false;
}

include 'config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{
    $name = stripslashes($_POST['name']);
    $email = $_POST['email'];
    $subject = stripslashes($_POST['subject']);
    $message = stripslashes($_POST['message']);
    $error = '';
    if(!$name)
    {
        $error .= '<p>Please enter your name.</p>';
    }
    if(!$email)
    {
        $error .= '<p>Please enter an e-mail address.</p>';
    }
    if($email && !ValidateEmail($email))
    {
        $error .= '<p>Please enter a valid e-mail address.</p>';
    }
    if(!$subject || strlen($subject) < 2)
    {
        $error .= "<p>Please enter the subject.</p>";
    }
    if(!$message || strlen($message) < 2)
    {
        $error .= "<p>Please enter your message.</p>";
    }
    if(!$error)
    {
        $mail = mail(WEBMASTER_EMAIL, $subject, $message,
             "From: ".$name." <".$email.">\r\n"
            ."Reply-To: ".$email."\r\n"
            ."X-Mailer: PHP/" . phpversion());
        if($mail)
        {
            echo 'OK';
        }
    }
    else
    {
        echo '<div id="notification">'.$error.'</div>';
    }
}

config.php:

<?php
// Change this to your email account
define("WEBMASTER_EMAIL", 'my mail address');

form.js:

$(document).ready(function(){
$("#contactForm").submit(function(){
    var str = $(this).serialize();
    $.ajax({
        type: "POST",
        url: "contact.php",
        data: str,
        success: function(msg){
            $("#note").ajaxComplete(function(event, request, settings){
                if(msg == 'OK')
                {
                    result = '<div id="notification"><p>Your message has been sent. Thank you!</p></div>';
                    $('#contactForm').each (function(){
                        this.reset();
                    });
                }
                else
                {
                    result = msg;
                }
                $(this).html(result);
            });
        }
    });
    return false;
});
$(文档).ready(函数(){
$(“#contactForm”).submit(函数(){
var str=$(this.serialize();
$.ajax({
类型:“POST”,
url:“contact.php”,
数据:str,
成功:功能(msg){
$(“#注意”).ajaxComplete(功能(事件、请求、设置){
如果(msg=='OK')
{
结果=“您的邮件已发送。谢谢!

”; $('#contactForm')。每个(函数(){ 这是reset(); }); } 其他的 { 结果=味精; } $(this).html(result); }); } }); 返回false; });
}))


谢谢

Change var str=$(this).serialize();数据:$(“#contactForm”).serialize(),

((我知道我需要把我的电子邮件地址放在写有“我的电子邮件地址”的地方。我已经在这篇文章中删除了它。)这是你在线上的脚本吗?我不知道为什么需要js文件,因为你可以用php来完成这一切,甚至可以回显警报框。你在php.ini中正确配置了本地电子邮件系统吗?你在微软视窗上吗?您使用本地电子邮件服务器还是外部中继?顺便说一句:有一个安全问题,因为$name参数启用了头注入。好吧,很抱歉我的愚蠢,但它正在工作!!我查错邮箱了。我用代码写了我的另一封电子邮件,所以我没有看到它。。它工作得很好。!!