PHPMailer问题,电子邮件将不会发送

时间:2016-03-16 17:16:33

标签: php email

我正在努力让我的联系表格得以运作。我已经在使用PHP 5.4的实时服务器上上传了该网站。我填写联系表格,上面写着“您的邮件已发送”,但由于某种原因,我没有收到任何电子邮件。

这是HTML表单。

<form role="form" id="contactForm">

    <div class="form-group control-group">
        <div class="controls">
            <p class="help-block"></p>
            <input type="text" class="form-control" 
                   placeholder="First Name" id="firstname" 
                   data-validation-required-message="Please enter your first name." 
                   aria-invalid="false">
        </div>
    </div>

    <div class="form-group control-group">
        <div class="controls">
            <p class="help-block"></p>
            <input type="text" class="form-control" 
                   placeholder="Last Name" id="lastname" 
                   data-validation-required-message="Please enter your last name." 
                   aria-invalid="false">
        </div>
    </div>

    <div class="form-group control-group">
        <div class="controls">
            <p class="help-block"></p>
            <input type="email" class="form-control" 
                   placeholder="Email" id="email" 
                   data-validation-required-message="Please enter your email address." 
                   aria-invalid="false">
        </div>
    </div>

    <div class="form-group control-group">
        <div class="controls">
            <p class="help-block"></p>
            <textarea class="form-control" placeholder="Message" 
              id="message" data-validation-required-message="Please enter some message." 
              aria-invalid="false"></textarea>
        </div>
    </div>

    <div class="form-group">
        <button type="submit" class="btn btn-primary">Send message</button>
    </div>
</form>

这是潜在的错误。我在我的目录中有url:“send.php”文件...

<script>
$(function () { 
    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,

        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var firstname = $("input#firstname").val();
            var lastname = $("input#lastname").val();
            var email = $("input#email").val();
            var message = $("textarea#message").val();

            $.ajax({

                url: "send.php",
                type: "POST",
                data: {
                    firstname: firstname,
                    lastname: lastname,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('.contact-alert').html("<div class='alert alert-success'>");
                    $('.contact-alert > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'><i class='fa fa-times'></i></button><strong>Your message has been sent.</strong></div>");
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('.contact-alert').html("<div class='alert alert-danger'>");
                    $('.contact-alert > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'><i class='fa fa-times'></i></button><strong>Sorry, it seems that my mail server is not responding. Please try again later!</strong></div>");
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        }
    });
});
</script>

send.php文件..我也下载了class.phpmailer.php,它与send.php在同一个位置

if(isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email']) && isset($_POST['message'])) {
require("class.phpmailer.php"); //you have to download this plugin from github.com - link is in documentation

$firstname =    $_POST['firstname'];
$lastname =     $_POST['lastname'];
$email =        $_POST['email'];
$message =      $_POST['message'];

$mail = new PHPMailer();

$mail->From = $email;
$mail->CharSet = "UTF-8";
$mail->FromName = $email;
$mail->addAddress("adomas2006@gmail.com"); 

$mail->IsHTML(true);
$mail->Subject = $name." sent you an email";

$mail->Body = $message."<br><br>".$name."<br>".$email."<br>".$phone."<br>";

$mail->send();

0 个答案:

没有答案