Php 一个简单的电子邮件客户端/联系人表单返回“5.5.4无效域错误”,我已用尽所有资源试图解决它
在过去的两天里,我已经发布了两次这个问题,我真的已经没有解决方案了。我正在创建一个非常简单的评论框,填写后会将评论发送到我公司的安全部门。在过去的几天里,我一直收到这个5.5.4无效域错误 它是SMTP和TLS。端口和服务器名称正确。服务器允许匿名电子邮件,不进行验证。我正在使用Swiftmailer库,所以我不需要编写ELHO/HELO脚本。电子邮件唯一未定义/硬编码的属性是邮件正文。这是我的控制器index.php的代码Php 一个简单的电子邮件客户端/联系人表单返回“5.5.4无效域错误”,我已用尽所有资源试图解决它,php,email,swiftmailer,Php,Email,Swiftmailer,在过去的两天里,我已经发布了两次这个问题,我真的已经没有解决方案了。我正在创建一个非常简单的评论框,填写后会将评论发送到我公司的安全部门。在过去的几天里,我一直收到这个5.5.4无效域错误 它是SMTP和TLS。端口和服务器名称正确。服务器允许匿名电子邮件,不进行验证。我正在使用Swiftmailer库,所以我不需要编写ELHO/HELO脚本。电子邮件唯一未定义/硬编码的属性是邮件正文。这是我的控制器index.php的代码 我已将我的全部代码发布在。没有太多,但我认为问题一定在于索引。你能解
我已将我的全部代码发布在。没有太多,但我认为问题一定在于索引。你能解决exchange.company.local吗?是的,我可以通过PHP解决。我试着用IP而不是FQDN来运行代码,这没有什么区别。你能用smtptest或telnet之类的工具从该服务器向给定的收件人/发送者发送邮件吗?是的。我已经通过telnet向服务器发送了一封电子邮件。好的,所以唯一不清楚的是那些EmailPart的内容。创建emailMessage后,var_dump会给您带来什么?
// Initialize Swiftmailer Library
require_once("./swiftmailer/lib/swift_required.php");
// Class that contains the information of the email that will be sent (from, to, etc.)
require_once("./classes/EmailParts.php");
// The class that "breaks" the data sent with the HTML form to a more "usable" format.
require_once("./classes/ContactForm.php");
// =====================
// Main Configuration
// =====================
define("EMAIL_SUBJECT", "Safety Concerns");
define("EMAIL_TO", "safetydepartment@company.com");
define("EMAIL_FROM", "safetydepartment@company.com");
// SMTP Configuration
define("SMTP_SERVER", 'exchange.company.local');
define("SMTP_PORT", 25);
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 checks for 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());
// 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);
// Call the "contactForm" view to display the HTML contact form.
require_once("./views/contactForm.php");