PHP联系人表单没有返回错误,但我仍然没有收到任何电子邮件

PHP联系人表单没有返回错误,但我仍然没有收到任何电子邮件,php,html,contact-form,Php,Html,Contact Form,如果这是一个愚蠢的问题,请原谅,但我对PHP非常陌生,并且遇到了一些问题。我试图用HTML、CSS和PHP构建一个联系人表单,但我似乎无法让我的PHP表单将表单内容发送到我的电子邮件地址。这是HTML的代码外观: <div id="contact-form"> <ul> <li><button id="quote" class="button1">Project Quote</button></li

如果这是一个愚蠢的问题,请原谅,但我对PHP非常陌生,并且遇到了一些问题。我试图用HTML、CSS和PHP构建一个联系人表单,但我似乎无法让我的PHP表单将表单内容发送到我的电子邮件地址。这是HTML的代码外观:

<div id="contact-form">
    <ul>
            <li><button id="quote" class="button1">Project Quote</button></li>
    </ul>

    <form class= "emai" action="mailer.php" method="post">
                    <p>Have a project in mind? Fill in the form for a quote!</p>
            <div>
                    <p><label for="name">What can I call you? <span>*</span></label></p>
                <input type="text" id="name" name="name">
            </div>
            <div>
                        <p><label for="email">What is your email? <span>*</span></label></p>
                <input type="email" name="email" id="email">
            </div>
            <div>
                        <p><label for="type">Type of Project? <span>*</span></label></p>
                <select id="type" name="type">
                        <option value="logo">Logo Design</option>
                    <option value="web dev">Website/WebApp Dev</option>
                        <option value="other">Other</option>    
                </select>
            </div>
            <div>
                    <p><label for="purpose">What is the main purpose of your project? <span>*</span></label></p>
                  <textarea id="purpose" name="purpose"></textarea>
            </div>
            <div>
                    <p><label for="features">Any extra features?</label></p>
                  <textarea id="features" name="features"></textarea>
            </div>

            <input class="button1" type="submit" value="submit">
    </form>

</div>

  • 项目报价
有计划吗?填写报价单

我能叫你什么*

你的电子邮件是什么*

项目类型*

标志设计 网站/网络应用开发 其他 你的项目的主要目的是什么*

还有其他功能吗

在一个名为“mailer.php”的单独文档中,代码是这样的:

<?php
/* Set e-mail recipient */
$myemail = "christopher.kenrick@gmail.com";
$subject = "Project Request";

/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$email = check_input($_POST['email']);
$type = check_input($_POST['type'], "Select a type of project");
$purpose = check_input($_POST['purpose'], "What is the purpose of your project?");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "

Name: $name
E-mail: $email
Type: $type
Purpose: $purpose
Features: $features

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>
您的代码缺少正确的代码。(最初缺少一个主题变量,您现在添加了该变量)

使用以下代码添加并修改当前的
mail()
函数,否则邮件将直接发送到垃圾邮件,就像我的测试一样

$headers = 'From: ' . $email . "\r\n";
mail($myemail, $subject, $message, $headers);
使用条件语句:

if(mail($myemail, $subject, $message, $headers)){ 
   echo "Success"; } else{ echo "There was a problem.";}

在运行了
sudo-apt-get-install-sendmail之后,我终于开始接收联系人表单的内容。此解决方案适用于使用DigitalOcean作为主机的用户

使用
mail()
时禁止出现错误。隐藏错误消息。使用
print\r($\u POST)
查看表单值是否确实正确提交。
@mail($myemail,$subject,$message)
,即
@
是用来隐藏任何错误的,因此您显然不应该收到任何…可能重复的No,在您的代码中,我可以看到
$subject
变量??我尝试了您建议的编辑,但仍然不起作用。我查看了垃圾邮件文件夹,但没有显示任何内容。您是通过托管网站还是从自己的计算机运行此功能@来自托管网站的IAMATINYCODER。我的网站是通过DigitalOcean托管的。该主机是否提供
mail()
?是免费的还是付费的@IAMATinyCoder Plus,尝试使用条件语句代替
if(mail($myemail,$subject,$message,$headers)){echo“Success”;}否则{echo“有问题”;}
我建议您查看他们的常见问题解答和此,并/或联系他们的技术支持@iMatinyCoder加上这个Q&A——我在谷歌上搜索了“digitalOcean邮件不工作”
,这就是我发现的。