HTML5表单使用邮件功能不在托管服务器上的我的Gmail帐户中接收邮件

时间:2018-05-23 10:38:23

标签: html html5 html5-formvalidation

我创建了一个简单的html5表单,我使用php邮件功能在我的Gmail帐户中邮寄表单,但我在提交该表单后没有收到任何邮件。我没有使用任何本地主机它在互联网上。需要一些解决方案的人

index.html   <----- Contact Form ------>

<form action="mail.php" method="POST">
                        <input type="text" name="username" id="one" class="form-input" placeholder="Name">
                        <input type="text" name="phone" id="two" class="form-input" placeholder="Mobile Number">
                        <input type="text" name="email" id="three" class="form-input" placeholder="Email Address">

                        <select class="form-input" id="four" name="place">
                            <option value="volvo">Centers</option>
                          <option value="volvo">India</option>
                          <option value="saab">USA</option>
                          <option value="mercedes">Singapore</option>
                          <option value="audi">China</option>
                          <option value="audi">Pakistan</option>
                        </select>

                        <div class="submit">
                            <input type="submit" name="submit" class="submit-btn">
                        </div>

                    </form>

mail.php  <------ mail function written here ------>

<?PHP
$sender = $_POST['email'];
$recipient = 'jhon@gmail.com';

$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;

if (mail($recipient, $subject, $message, $headers))
{
    echo "Message accepted";
}
else
{
    echo "Error: Message not accepted";
}
?>

2 个答案:

答案 0 :(得分:0)

某些托管服务提供商未启用mail()。因此,在发送邮件之前,您需要确定mail()是否已启用。使用以下内容对其进行测试。

<?php
if ( function_exists( 'mail' ) )
{
    echo 'mail() is available';
}
else
{
    echo 'mail() has been disabled';
}
?>

如果启用了邮件功能但仍未发送邮件,请尝试使用

@mail($recipient, $subject, $message, $headers) 

它强制使用服务器中的mail()。

答案 1 :(得分:0)

如果您使用gmail发送邮件,请单击此链接https://myaccount.google.com/intro/security?pli=1#connectedapps并转到允许安全性较低的应用程序(登录到您的gmail.com后),将其更改为是..