Bootstrap,contact_php和contact.js不发送电子邮件[关闭]

I am using Bootstrap and wanting to use an email contact form. I have setup a test page - http://www.beatrootonline.co.uk/test.html. As you can see its validating ok (jqBootstrapValidation.js) and appears to send an email. However, I am not receiving an email from this form.

Heres the html

<div class="row">
<div class="col-lg-12">
<form name="sentMessage" id="contactForm" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
 <textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl">Send Message</button>
</div></div>
</form>
</div>
</div>

and the contact_me.js $(function() {

$("input,textarea").jqBootstrapValidation({
    preventSubmit: true,
    submitError: function($form, event, errors) {
        // additional error messages or events
    },
    submitSuccess: function($form, event) {
        event.preventDefault(); // prevent default submit behaviour
        // get values from FORM
        var name = $("input#name").val();
        var email = $("input#email").val();
        var phone = $("input#phone").val();
        var message = $("textarea#message").val();
        var firstName = name; // For Success/Failure Message
        // Check for white space in name for Success/Fail message
        if (firstName.indexOf(' ') >= 0) {
            firstName = name.split(' ').slice(0, -1).join(' ');
        }
        $.ajax({
            url: "bin/contact_me.php",
            type: "POST",
            data: {
                name: name,
                phone: phone,
                email: email,
                message: message
            },
            cache: false,
            success: function() {
                // Success message
                $('#success').html("<div class='alert alert-success'>");
                $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                $('#success > .alert-success')
                    .append("<strong>Your message has been sent. </strong>");
                $('#success > .alert-success')
                    .append('</div>');

                //clear all fields
                $('#contactForm').trigger("reset");
            },
            error: function() {
                // Fail message
                $('#success').html("<div class='alert alert-danger'>");
                $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                $('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                $('#success > .alert-danger').append('</div>');
                //clear all fields
                $('#contactForm').trigger("reset");
            },
        })
    },
    filter: function() {
        return $(this).is(":visible");
    },
});

$("a[data-toggle=\"tab\"]").click(function(e) {
    e.preventDefault();
    $(this).tab("show");
});
});


/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
$('#success').html('');

and my contact_me.php

    <?php
    // check if fields passed are empty
    if(empty($_POST['name'])        ||
    empty($_POST['email'])      ||
    empty($_POST['message'])    ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];

// create email body and send it    
$to = 'me@myaddress.com'; // put your email
$email_subject = "Contact form submitted by:  $name";
$email_body = "You have received a new message. 

".
                  " Here are the details:
 
Name: $name 
 ".
                  "Email: $email_address
 Message 
 $message";
$headers = "From: noreply@myaddress.com
";


$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

I get a successful message on screen to say that the email has been sent but no email arrives (I have substituted my real email address for a fake on the php)

dongxinche1264
dongxinche1264 我在第12行的contact.php代码中输入了一个拼写错误(上面的示例中未显示),只是将其删除,上传并且有效!
接近 6 年之前 回复
dongsimu4422
dongsimu4422 你不能从你的localhost发送邮件
接近 6 年之前 回复
duandu8202
duandu8202 你在共享或专用服务器上?你有php邮件设置吗?你检查过服务器上的邮件日志了吗?
接近 6 年之前 回复

4个回答



尝试将 mail()</ code>函数置于如下条件:</ p>

< pre> if(mail($ to,$ email_subject,$ email_body,$ headers)){
return true;
} else {
return false;
}
</ code> </ pre >

因此,您可以检查邮件是否已发送。</ p>
</ div>

展开原文

原文

Try to put the mail() function in condition like :

if (mail($to,$email_subject,$email_body,$headers)){
    return true;
}else{
    return false;
}

So you can check if the mail is sent or not.



确保contact_me.php在手动加载后发送邮件。 邮件功能仅适用于某些Web主机。 您需要手动启用它才能开始发送邮件。 </ p>
</ div>

展开原文

原文

Make sure that contact_me.php sends mail after loading it manually. Mail function would work only in certain web hosts. You need to enable it manually before you can start sending mails.



尝试使用PHPMailer。 您可以在此处找到它。 它比简单的邮件功能更安全,更可靠。 </ p>
</ div>

展开原文

原文

Try using PHPMailer. You can find it here. It's much more safer and much more reliable than simple mail function.



我在第12行的contact.php代码中输入了一个拼写错误(上面的示例中没有显示),只是删除了它,上传了它 作品!! - 谢谢大家!</ p>
</ div>

展开原文

原文

I had a typo in the contact.php code in line 12 (not shown in the example above) just removed it, uploaded and it works!! – Thanks everyone!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐