Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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

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

使用php通过电子邮件发送的联系人表单

使用php通过电子邮件发送的联系人表单,php,html,Php,Html,我正在尝试让我的web项目上的myContact Us表单与php一起工作,这样当输入带有注释的全名和电子邮件地址时,它会向我发送一封电子邮件,然后显示一条成功消息,如果他们未能填写表单,则会显示一条错误消息,提示他们重试。我的代码不工作,我真的不明白为什么,它只是显示错误消息,无论什么,甚至当所有信息输入。下面是我的php代码:- `<?php` $name = $email = ""; if (isset ($_POST ['fullname'])) $name = fix

我正在尝试让我的web项目上的myContact Us表单与php一起工作,这样当输入带有注释的全名和电子邮件地址时,它会向我发送一封电子邮件,然后显示一条成功消息,如果他们未能填写表单,则会显示一条错误消息,提示他们重试。我的代码不工作,我真的不明白为什么,它只是显示错误消息,无论什么,甚至当所有信息输入。下面是我的php代码:-

`<?php`

$name = $email = "";

if (isset ($_POST ['fullname']))
    $name = fix_string ($_POST ['fullname']);
    if (isset ($_POST ['email'])) $email = fix_string ($_POST ['email']);

    $email_to = "my@eamiladdress.com";

    $email_subject = "Question asked";

    echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
        <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
            <head>
                <link href='myelearningtool.css' rel='stylesheet' type='text/css' />
                <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
                <title>Registration Confirmation E-Learning Tool Prototype</title>
                <div class='page'>
                    <div class='header'>
                        <div id='logo'>
                            <img src='images/BS_kids_ELearningToollogo.png' alt='E-Learning Tool Prototype v1' />
                        </div>
                        <ul id='navigation'>
                            <li><a href='****************.html'>Logout</a></li>
                            <li><a href='**************.html'>Activities</a></li>
                            <li><a href='****************.html'>Videos</a></li>
                            <li><a href='****************.html'>Glossary</a></li>
                            <li><a href='********'>Contact Us</a></li>
                        </ul>
                    </div><!--end of header div -->
                    <div class='content'><!--start of content -->
                        <div class='contact_details'>
                            <p>Thanks for that, someone will email you back as soon as possible.</P>
                            </div><!--end of contact details-->
                        </div>
                    </div><!--end of content div-->
                </div>
            </div>
        </html>"; 

$fail  = validate_fullname($name);
$fail += validate_email($email);

if ($fail == ""){
    echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
        <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
            <head>
                <link href='myelearningtool.css' rel='stylesheet' type='text/css' />
                <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
                <title>Registration Confirmation E-Learning Tool Prototype</title>
                <div class='page'>
                    <div class='header'>
                        <div id='logo'>
                            <img src='images/BS_kids_ELearningToollogo.png' alt='E-Learning Tool Prototype v1' />
                        </div>
                        <ul id='navigation'>
                            <li><a href='****************.html'>Return To Home Page</a></li>
                        </ul>
                    </div><!--end of header div -->
                    <div class='content'><!--start of content -->
                        <p>Ooops yous missed something off.  Please try again</p>
                        <fieldset><!--details section-->
                            <legend><b>Contact Us</b></legend>
                            <label for='name'> Your Full Name*:</label> <input type='text' name='fullname' id='name' maxlength='50' size='30' tabindex='1' accesskey='q' />
                            <label for='email'>Email Address*:</label><input type='text' name='email' id='email' maxlength='50' size='30' tabindex='2' accesskey='w' />
                        </fieldset><!--end of fieldset-->
                    <div class='message'>
                        <fieldset>
                            <legend>Message*</legend>
                            <textarea name='message' id='msge' cols='130' rows='10'>Please type your question or query here</textarea>
                        </fieldset>
                        <p><input type='submit' value='Enter' /></p>
                    </div><!--end of content div-->
                </div>
            </div>
        </html>";
}

function validate_fullname($name){
    return ($name == "")? "No name was entered<br>": "";
}
function validate_email($email){
    if ($email == "")
        return "No email was entered<br>";
    else if (!((strpos($email, ".") > 0) && (strpos($email, "@") > 0)) || preg_match ("/[^a-z A-Z 0-9.@_-]/", $email))
        return "The Email address is invalid<br>";
    return "";
}
function fix_string($string){
    if (get_magic_quotes_gpc()) $string = stripslashes($string);
        return htmlentities ($string);
}

?>

`更新

问题太小了,我错过了

您需要使用
=
而不是
+=

$fail  = validate_fullname($name);
$fail .= validate_email($email);
同时从底部删除该代码的第二个匹配项

并关闭第一个html块上的表单标记

--原始答案--

除了缺少
表单
标记外,您还可以使用不同的sytnax重写if语句,这样您就可以正常键入html而无需回显它

围绕这个例子工作,它应该适合您

<?php

if (isset($_POST ['fullname']) || isset($_POST ['email'])):
    $name = fix_string($_POST ['fullname']);
    $email = fix_string($_POST ['email']);

    $email_to = "my@eamiladdress.com";
    $email_subject = "Question asked";

    $fail  = validate_fullname($name);
    $fail .= validate_email($email);

    if($fail!=""):
?>
    <!--Your error html-->
<?php 
    else:
?>
    <!--Your success html-->
<?php
    endif;
?>

<?php 
else:
?>

<!--Your form html-->

<?php
endif;

//Your functions

?>

更新

问题太小了,我错过了

您需要使用
=
而不是
+=

$fail  = validate_fullname($name);
$fail .= validate_email($email);
同时从底部删除该代码的第二个匹配项

并关闭第一个html块上的表单标记

--原始答案--

除了缺少
表单
标记外,您还可以使用不同的sytnax重写if语句,这样您就可以正常键入html而无需回显它

围绕这个例子工作,它应该适合您

<?php

if (isset($_POST ['fullname']) || isset($_POST ['email'])):
    $name = fix_string($_POST ['fullname']);
    $email = fix_string($_POST ['email']);

    $email_to = "my@eamiladdress.com";
    $email_subject = "Question asked";

    $fail  = validate_fullname($name);
    $fail .= validate_email($email);

    if($fail!=""):
?>
    <!--Your error html-->
<?php 
    else:
?>
    <!--Your success html-->
<?php
    endif;
?>

<?php 
else:
?>

<!--Your form html-->

<?php
endif;

//Your functions

?>



它显示了什么错误消息?我看到的第一个问题是,htmlIt中的任何地方都没有
表单
标记,而且第一个if语句似乎也有问题,我假设您只希望在表单已提交的情况下显示第一块html?@WheatBeak thank从未注意到表单标记的这一点。是的,我只希望在正确提交表单时显示第一个html块,如果出现错误或缺少某些内容,则显示第二个html块。目前,我只是得到这两个块的html回显到我的网页,没有电子邮件发送,你也需要一些更多的条件在那里。你应该有3种情况1)有人正常进入页面2)有人正确提交表单3)有人提交表单时出错显示了什么错误消息?我看到的第一个问题是,你的htmlIt中没有
表单
标记,你的第一个问题似乎也是如果声明,我假设您只希望在表单已提交的情况下显示第一块html?@WheatBeak thank从未注意到表单标记的这一点。是的,我只希望在正确提交表单时显示第一个html块,如果出现错误或缺少某些内容,则显示第二个html块。目前,我只是得到这两个块的html回显到我的网页,没有电子邮件发送,你也需要一些更多的条件在那里。你应该有3个场景1)有人正常进入页面2)有人正确提交了表格3)有人提交了带有错误的表格我现在得到的是成功的第一条信息。我可以输入我正在使用的代码吗?你也许能看出我哪里做错了?我应该在哪里上传,用新代码编辑我的问题?是的,这似乎正在工作,我得到了正确的回答。你能解释为什么要使用。=它似乎没有发送电子邮件或使用我的CSS样式表,所以你知道为什么会这样吗?不确定为什么它没有使用样式表,请检查你的路径。至于发送邮件,您需要使用php的邮件功能,前提是您的服务器支持它。这很容易学,谷歌教程,这是官方文件,我会查出来的谢谢。很高兴它现在起作用了-谢谢你的帮助。我现在得到的只是成功的第一条信息。我可以输入我正在使用的代码吗?你也许能看出我哪里做错了?我应该在哪里上传,用新代码编辑我的问题?是的,这似乎正在工作,我得到了正确的回答。你能解释为什么要使用。=它似乎没有发送电子邮件或使用我的CSS样式表,所以你知道为什么会这样吗?不确定为什么它没有使用样式表,请检查你的路径。至于发送邮件,您需要使用php的邮件功能,前提是您的服务器支持它。这很容易学,谷歌教程,这是官方文件,我会查出来的谢谢。很高兴它现在可以工作了-谢谢你的帮助。