Я создал PHP-скрипт для отправки электронных писем со своего веб-сайта на мой адрес электронной почты службы поддержки.Скрипт использует PHPMailer, но, похоже, при отправке электронного письма возникает ошибка, так как он возвращает ложь, как будто он не смог отправить электронное письмо, но отправляет его без проблем, вот мой PHP-код ...
<?php
header('application/json');
require_once('phpmailer.php');
// Retreive all the required fields
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$timestamp = date("dmYhms", mktime(date(h), date(m), date(s), date(m), date(d), date(y)));
// Get users ip address
if ($_SERVER['HTTP_X_FORWARD_FOR'] != '') {
$ipaddress = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ipaddress = $_SERVER['REMOTE_ADDR'];
}
// Check a name was specified
if ($name == ''){
$output = json_encode(array('status'=>'invalid','message'=>'Please enter your full name.'));
die($output);
}
// Check a email address was specified
if ($email == ''){
$output = json_encode(array('status'=>'invalid','message'=>'Please enter your email address.'));
die($output);
}
// Check a subject was specified
if ($subject == ''){
$output = json_encode(array('status'=>'invalid','message'=>'Please enter a subject for your message.'));
die($output);
}
// Check a message was specified
if ($message == ''){
$output = json_encode(array('status'=>'invalid','message'=>'A message without a message, interesting...'));
die($output);
}
// Double check all the fields are not blank and prepare the message
if ($name != '' && $email != '' && $subject != '' && $message != ''){
// Check the email address specified is valid
if (preg_match("/^(\w+((-\w+)|(\w.\w+))*)\@(\w+((\.|-)\w+)*\.\w+$)/", $email)){
$mail = new phpmailer;
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress("support@idify.me", "IDify Ltd");
$mail->AddReplyTo("support@idify.me", "IDify Ltd");
$mail->WordWrap = 500;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = "<strong>Ip Address: </strong>".$ipaddress."<br/><strong>Timestamp: </strong>".$timestamp."<br/><strong>Fullname: </strong>".$name."<br/><strong>Email Address: </strong>".$email."<br/><strong>Subject: </strong>".$subject."<br/><p>".$message."</p>";
if($mail->Send()){
$output = json_encode(array('status'=>'valid','message'=>'Your message is on its way, we will be in touch with you soon.'));
die($output);
} else {
$output = json_encode(array('status'=>'invalid','message'=>'We were unable to send your message, please try again later.'));
die($output);
}
}else{
$output = json_encode(array('status'=>'invalid','message'=>'Please enter a valid email address.'));
die($output);
}
}
?>
Спасибо за любую предоставленную помощь, это очень странно, но я уверен, что мы можем решить это.