与我们联系表格:未收到邮件

时间:2018-09-02 08:54:33

标签: php email

我正在尝试使用PHP创建与我们联系的表单。问题是,我没有在我的帐户中收到电子邮件。单击提交按钮后,会将我带到mail.php页面,其中显示“谢谢”消息。 代码如下所示:

<div class="container">
    <div class="col-xs-offset-2 col-xs-10 col-sm-8">
    <h2>Contact Us</h2>
    <form action="mail.php" method="POST" class="form-horizontal">
        <div class="form-group">
            <label class="control-label col-sm-2 col-xs-6" for="email">First Name:</label>
            <div class="col-sm-6 col-xs-6">
                <input type="text" class="form-control" id="fname" placeholder="First Name*" name="fname" required="required">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="email">Last Name:</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" id="lname" placeholder="last Name" name="lname" >
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="email">Email ID:</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" id="email" placeholder="Email Address*" name="email" required="required">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="message">Message:</label>
            <div class="col-sm-6">
                <textarea id="form_message" name="message" class="form-control" placeholder="Message*" rows="4" required="required" data-error="Please, leave us a message."></textarea>
            </div>
        </div>

        <div class="form-group">        
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
    </form>
</div>

mail.php的代码:

<?php 
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $fname $lname \n Message: $message";
$recipient = "rubeena.ajeed@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

1 个答案:

答案 0 :(得分:0)

请尝试使用SMTP吗?

PHPmailler.class

下载:https://github.com/PHPMailer/PHPMailer