php电子邮件发送重复

时间:2013-10-15 10:17:49

标签: php email duplicates

出于某种原因,我使用发送联系表单的代码是将副本发送到我的邮箱,有人可以帮助我,我需要在底部的if语句让我的jquery能够显示错误和成功的消息,代码工作只是发送一个副本我错过了什么?

和我一起稳定,因为我不是一个用PHP编写的大编码器,但我非常清楚我在做什么:)

<?php
$subject = $_REQUEST['subject']; // Subject of your email
$to = 'my@emailaddress.co.uk';  //Recipient's E-mail

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Contact Number: ' . $_REQUEST['tel'];
$message .= "<br>";
$message .= 'Message Sent:'."<br>";`enter code here`
$message .= $_REQUEST['message'];
$message .= "<br>";
$message .= 'This is an enquiry from Circles website';

if (@mail($to, $subject, $message, $headers))
{
    // Transfer the value 'sent' to ajax function for showing success message.
    echo 'sent';


}
else
{
    // Transfer the value 'failed' to ajax function for showing error message.
    echo 'failed';
}
?>

Validation.js

$(document).ready(function(){
    $('#send_message').click(function(e){

        //Stop form submission & check the validation
        e.preventDefault();

        // Variable declaration
        var error = false;
        var name = $('#name').val();
        var tel = $('#tel').val();
        var email = $('#email').val();
        var subject = $('#subject').val();
        var message = $('#message').val();

        // Form field validation
        if(name.length == 0){
            var error = true;
            $('#name_error').fadeIn(500);
        }else{
            $('#name_error').fadeOut(500);
        }
        if(tel.length == 0){
            var error = true;
            $('#tel_error').fadeIn(500);
        }else{
            $('#tel_error').fadeOut(500);
        }
        if(email.length == 0 || email.indexOf('@') == '-1'){
            var error = true;
            $('#email_error').fadeIn(500);
        }else{
            $('#email_error').fadeOut(500);
        }
        if(subject.length == 0){
            var error = true;
            $('#subject_error').fadeIn(500);
        }else{
            $('#subject_error').fadeOut(500);
        }
        if(message.length == 0){
            var error = true;
            $('#message_error').fadeIn(500);
        }else{
            $('#message_error').fadeOut(500);
        }

        if(tel.length == 0){
            var error = true;
            $('#tel_error').fadeIn(500);
        }else{
            $('#tel_error').fadeOut(500);
        }

        // If there is no validation error, next to process the mail function
        if(error == false){
           // Disable submit button just after the form processed 1st time successfully.
            $('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });

            /* Post Ajax function of jQuery to get all the data from the submission of the form as soon as the form sends the values to email.php*/
            $.post("email.php", $("#contact_form").serialize(),function(result){
                //Check the result set from email.php file.
                if(result == 'sent'){
                    //If the email is sent successfully, remove the submit button
                     $('#submit').remove();
                    //Display the success message
                    $('#mail_success').fadeIn(500);


                }else{
                    //Display the error message
                    $('#mail_fail').fadeIn(500);
                    // Enable the submit button again
                    $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
                }
            });
        }
    });    
});

联络表格

<div id="contact">
              <form name="contactForm" id='contact_form' autocomplete="of" method="post" action='email.php'>
                <label>Your Name:</label>
                  <div id='name_error' class='error'><img src='images/error.png'>Please enter your name.</div>
                  <input type='text' name='name' id='name'>
                  <label>Telephone Number:</label>
                  <div id='tel_error' class='error'><img src='images/error.png'>Please enter a contact number</div>
                  <input type='text' name='tel' id='tel'>
                <label>Your E-mail Address:</label>
                  <div id='email_error' class='error'><img src='images/error.png'>Please enter your valid E-mail ID.</div>
                  <input type='text' name='email' id='email'>
                <label>Topic:</label>
                  <div id='subject_error' class='error'><img src='images/error.png'>Please enter the subject.</div>
                  <input type='text' name='subject' id='subject'>
                <label>Your Message:</label>
                  <div id='message_error' class='error'><img src='images/error.png'>Please enter your message.</div>
                  <textarea name='message' id='message'></textarea>
                <div id='mail_success' class='success'><img src='images/success.png'>Your message has been sent successfully.</div>
                <div id='mail_fail' class='error'><img src='images/error.png'> Sorry, error occured this time sending your message.</div>
                <p id='submit'>
                  <input type='submit' id='send_message' value='Submit Form'>
                </p>
              </form>


        </div>

0 个答案:

没有答案