PHP邮件程序提交电子邮件,虽然我没有收到它们

时间:2014-07-03 23:59:06

标签: php html ajax phpmailer contact

我正在使用php邮件程序填写联系表单。虽然我没有收到电子邮件,但我能够收到发送电子邮件的成功消息。 这是我的代码:

contact.php

<form method="post" id="contactForm" action="contactProcess.php">
    <div class="clearfix">
        <div class="grid_6 alpha fll"><input type="text" name="senderName" id="senderName" placeholder="Name *" class="requiredField" /></div>
        <div class="grid_6 omega flr"><input type="text" name="senderEmail" id="senderEmail" placeholder="Email Address *" class="requiredField email" /></div>
    </div>
    <div><textarea name="message" id="message" placeholder="Message *" class="requiredField" rows="8"></textarea></div>
    <input type="submit" id="sendMessage" name="sendMessage" value="Send Email" />
    <span>  </span>
</form>

contactProcess.php

<?php
include 'library.php'; // include the library file
include "classes/class.phpmailer.php"; // include the class name
if(isset($_POST["sendMessage"])){
    $name = $_POST['senderName'];
    $email = $_POST['senderEmail'];
    $message = $_POST['message'];

    $mail   = new PHPMailer; // call the class 
    $mail->IsSMTP(); 
    $mail->Host = SMTP_HOST; //Hostname of the mail server
    $mail->Port = SMTP_PORT; //Port of the SMTP like to be 25, 80, 465 or 587
    $mail->SMTPAuth = true; //Whether to use SMTP authentication
    $mail->Username = SMTP_UNAME; //Username for SMTP authentication any valid email created in your domain
    $mail->Password = SMTP_PWORD; //Password for SMTP authentication
    $mail->From = $email;  //From address of the mail
    $mail->FromName = $name;
    $mail->Subject = ("Mail From Contact Form"); //Subject of your mail

    $mail->IsHTML(true);
    $mail->AddAddress("me@add.com");//To address who will receive this email
    $mail->AddCC("add@add.com");
    $mail->AddReplyTo("add2@add.com", "Me");
    $mail->Body = $message;
    $mail->AltBody = $message;

    $send = $mail->Send(); //Send the mails
    if($send){ ?>
        <script language="javascript" type="text/javascript">
        alert('sent');
        window.location = 'contact.php';
    </script>
    <?php
    }
    else{ ?>
        <script language="javascript" type="text/javascript">
        alert('Message failed');
        window.location = 'contact.php';
    </script>
    <?php
    }
}
?>

最后是ajax验证脚本: main.js

// Ajax Contact
if ($("#contactForm")[0]) {
    $('#contactForm').submit(function () {
        $('#contactForm .error').remove();
        $('.requiredField').removeClass('fielderror');
        $('.requiredField').addClass('fieldtrue');
        $('#contactForm span strong').remove();
        var hasError = false;
        $('#contactForm .requiredField').each(function () {
            if (jQuery.trim($(this).val()) === '') {
                var labelText = $(this).prev('label').text();
                $(this).addClass('fielderror');
                $('#contactForm span').html('<strong>*Please fill out all fields.</strong>');
                hasError = true;
            } else if ($(this).hasClass('email')) {
                var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                if (!emailReg.test(jQuery.trim($(this).val()))) {
                    var labelText = $(this).prev('label').text();
                    $(this).addClass('fielderror');
                    $('#contactForm span').html('<strong>Your email address is incorrect</strong>');
                    hasError = true;
                }
            }
        });
        if (!hasError) {
            $('#contactForm').slideDown('normal', function () {
                $("#contactForm #sendMessage").addClass('load-color');
                $("#contactForm #sendMessage").attr("disabled", "disabled").val('Sending message. Please wait...');
            });
            var formInput = $(this).serialize();
            $.post($(this).attr('action'), formInput, function (data) {
                $('#contactForm').slideUp("normal", function () {
                    $(this).before('<div class="notification-box notification-box-success"><p><i class="icon-ok"></i>Thanks!</strong> Your email was successfully sent. We will get back to you soonest!.</p></div>');
                });
            });
        }
        return false;
    });
}

我真的无法弄清问题是什么。

0 个答案:

没有答案