2015-01-21 2 views
2

나는 블루 칼라 근로자가 인트라넷을 통해 안전 관련 고지를 제출할 수있는 매우 간단한 문의 양식을 작성하고 있습니다. 연락처 양식은 HTML 형식으로 표시되며 이름, 보낸 사람 전자 메일 및 보낼 메시지를 묻습니다. 항상 Google의 안전 이메일로 전송됩니다.오류 : PHP + Swiftmailer를 사용하여 전자 메일을 보내려고 할 때 "501 5.5.4 잘못된 도메인 이름"이 표시됨

서버와 포트가 정확합니다. Exchange 2010 서버이며 TSL을 사용하고 있습니다. 서버는 익명으로 전자 메일을 수신 할 수 있도록 구성됩니다. 텔넷 명령을 통해 연결할 수 있지만 설명 상자를 통해 메일을 보내려고하면 "501 5.5.4 잘못된 도메인 이름"오류가 발생합니다. 메일 호스트 필드에 정의 된 FQDN (xx.yy.com) 대신 IP 주소가있는 경우

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"); 
+0

포트가 TSL의 경우 25입니까? – SuckerForMayhem

+0

나중에 포트에서 시스템 관리자에게 다시 확인하겠습니다. 그러나 포트 587을 사용하여 다시 테스트했으며 동일한 결과가 나타납니다. 나는 그것이 이전에 포트 25 였다고 들었습니다. – Joshua

+0

은 인트라넷에 액세스 할 수있는 어딘가에서 호스팅되는 코드입니까? 그게 서버와 포트가 정확하다고 말하는 경우 내가 생각할 수있는 유일한 것입니다. – SuckerForMayhem

답변

0

대답은 서버 FQDN을 확인할 수 있어야합니다, 간단합니다. 그렇지 않으면 잘못된 도메인 이름이라는 오류가 발생합니다.

희망이 도움이됩니다.