Я пишу очень простую форму контакта, которая позволит работникам синих воротничков отправлять уведомления о безопасности в нашу интрасеть. Контактная форма отображается в HTML и запрашивает имя, адрес электронной почты и отправленное сообщение. Он всегда отправляется на нашу электронную почту безопасности.Ошибка: «501 5.5.4 Недопустимое доменное имя» при попытке отправить электронное письмо с помощью PHP + Swiftmailer
Сервер и порт указаны правильно. Это сервер Exchange 2010, и мы используем TSL. Сервер настроен так, чтобы получать электронную почту «анонимно». Я могу подключиться через команду telnet, но при попытке отправить почту через поле комментариев я получаю сообщение об ошибке «501 5.5.4 Недопустимое имя домена».
define("EMAIL_SUBJECT", "Safety Concerns");
define("EMAIL_TO", "email");
// SMTP Configuration
define("SMTP_SERVER", 'server');
define("SMTP_PORT", 25);
// define("UPLOAD_DIR", '/var/www/tmp/'); // Default php upload dir
// main method. It's the first method called
function main($contactForm) {
// Checks if something was sent to the contact form, if not, do nothing
if (!$contactForm->isDataSent()) {
return;
}
// validates the contact form and initialize the errors
$contactForm->validate();
$errors = array();
// If the contact form is not valid:
if (!$contactForm->isValid()) {
// gets the error in the array $errors
$errors = $contactForm->getErrors();
} else {
// If the contact form is valid:
try {
// send the email created with the contact form
$result = sendEmail($contactForm);
// after the email is sent, redirect and "die".
// We redirect to prevent refreshing the page which would resend the form
header("Location: ./success.php");
die();
} catch (Exception $e) {
// an error occured while sending the email.
// Log the error and add an error message to display to the user.
error_log('An error happened while sending email contact form: ' . $e->getMessage());
$errors['oops'] = 'Ooops! an error occured while sending your email! Please try again later!';
}
}
return $errors;
}
// Sends the email based on the information contained in the contact form
function sendEmail($contactForm) {
// Email part will create the email information needed to send an email based on
// what was inserted inside the contact form
$emailParts = new EmailParts($contactForm);
// This is the part where we initialize Swiftmailer with
// all the info initialized by the EmailParts class
$emailMessage = Swift_Message::newInstance()
->setSubject($emailParts->getSubject())
->setFrom($emailParts->getFrom())
->setTo($emailParts->getTo())
->setBody($emailParts->getBodyMessage());
// If an attachment was included, add it to the email
// if ($contactForm->hasAttachment()) {
// $attachmentPath = $contactForm->getAttachmentPath();
// $emailMessage->attach(Swift_Attachment::fromPath($attachmentPath));
//}
// Another Swiftmailer configuration..
$transport = Swift_SmtpTransport::newInstance(SMTP_SERVER, SMTP_PORT, 'tls');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($emailMessage);
return $result;
}
// Initialize the ContactForm with the information of the form and the possible uploaded file.
$contactForm = new ContactForm($_POST, $_FILES);
// Call the "main" method. It will return a list of errors.
$errors = main($contactForm);
require_once("./views/contactForm.php");
У вас есть порт 25 для TSL? – SuckerForMayhem
Я позже проведу проверку с системным администратором порта, но я только что проверил его снова с портом 587, и я получил тот же результат. Мне сказали ранее, что это определенно порт 25. – Joshua
- это код, размещенный где-то, у которого есть доступ к интрасети? это единственное, о чем я могу думать, если вы говорите, что сервер и порты правильные – SuckerForMayhem