我正在使用php郵件發送我的聯繫表單。儘管我沒有收到電子郵件,但我能夠獲得正在發送的電子郵件的成功消息。 這裏是我的代碼:即使在調試PhpMailer之後,我仍然無法收到電子郵件
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->SMTPDebug = 2;
$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("[email protected]");//To address who will receive this email
$mail->AddCC("[email protected]");
$mail->AddReplyTo("[email protected]", "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-\.][email protected]([\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;
});
}
我有試圖設置$ mail-> SMTPDebug = 2;還包括error_reporting(E_ALL);希望我能得到任何錯誤,但沒有任何反應。
任何想法,請!
您是否有權訪問Web服務器中的郵件日誌?您可能會遇到本地郵件程序配置問題,這些郵件可能會被本地接受,但不會離開您的websrv。如果您正在Linux/UNIX服務器上工作,並且您可以訪問它的shell控制檯,請嘗試使用「mail」命令發送一個命令,並查看它是否到達目的地。 –
不幸的是,我沒有像在共享的Windows服務器上那樣訪問郵件日誌。有沒有辦法解決它? – Josealonso14
我已經與我的託管解決方案聯繫,他們說他們已經通過網絡郵件測試了該帳戶的郵件服務,並且工作正常,所以它必須與腳本有關。 – Josealonso14