Я попытался использовать этот PHP-код для веб-сайта, чтобы связаться с нами. Сообщения об ошибках для проверки поля работают нормально. Однако он неправильно обрабатывает сообщения $ result, отправляя неверное сообщение.
<?php
if (isset($_POST["submit"]) && $_POST["submit"] == 'Send')
{
$name = isset($_POST['name']) ? $_POST['name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$subject = isset($_POST['subject']) ? $_POST['subject'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$human = isset($_POST['human']) ? intval($_POST['human']) : '';
$error = array();
// Check if name has been entered
if (empty($name)) {
$error['name'] = 'Please enter your name';
}
// Check if email has been entered and is valid
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error['email'] = 'Please enter a valid email address';
}
//Check if message has been entered
if (empty($message)) {
$error['message'] = 'Please enter your message';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$error['human'] = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (empty($error)) {
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'User');
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['message'];
// From here the code is not working properly
if ($mail->send()) {
$result = '<div class="alert alert-success">Sorry there is a problem by sending your message. Please try again later.</div>';
} else {
//echo 'Mailer Error: ' . $mail->ErrorInfo;exit;
$result = '<div class="alert alert-success">Thank you for your message and we will get back to you as soon as possible.</div>';
}
}
}
?>
Вы можете определить ошибку этого кода?
Заранее спасибо.
http://importblogkit.com/2015/ 07/does-not-work/ – Biffen
'send()' и 'Send()' являются двумя разными животными в PHPMailer –
ваше сообщение об успешном завершении $ result извиняется, а $ result sorry message thank you. dicy – vishwakarma09