2016-08-27 16 views
1

PHP 및 로컬 메일 서버 인 hMailServer에서 SwiftMailer 패키지 사용. PHP 코드 :왜 Swift Mailer가 암호없이 메시지를 보냅니 까?

<?php 

require 'vendor/autoload.php'; 

$message=Swift_Message::newInstance(); 
$message->setFrom('[email protected]'); 
$message->setTo(array('[email protected]'=>'Ilqar Rasulov')); 
$message->setSubject('Delicious New Recipe'); 
//$message->setBody(<<<_TEXT_ 
//Dear James, 
//You should try this: puree 1 pound of chicken with two pounds 
//of asparagus in the blender, then drop small balls of the mixture 
//into a deep fryer. Yummy! 
//Love, 
//Julia 
//_TEXT_ 
//); 
$message->addPart(<<<_TEXT_ 
<p>Dear James,</p> 
<p>You should try this:</p> 
<ul> 
<li>puree 1 pound of chicken with two pounds 
of asparagus in the blender</li> 
<li>then drop small balls of the mixture into a deep fryer.</li> 
</ul>  
<p><em>Yummy!</em></p> 
<p>Love,</p> 
<p>Julia</p> 
_TEXT_ 
, "text/html"); 
try{ 
$transport= Swift_SmtpTransport::newInstance('localhost',25); 
$mailer= Swift_Mailer::newInstance($transport); 

$mailer->send($message); 
} catch (Exception $ex){ 
    print $ex->getMessage(); 
} 

내 hMailServer를 구성하고 암호 (관리자 및 계정 암호)를 지정했습니다. 따라서 swiftmailer가 호스트 이름과 암호만으로 작업을 수행하고 인증을 요구하지 않는 이유는 무엇입니까? 사촌 나는 모든 설정 파일에 사용자 이름과 패스워드를 저장했다는 것을 기억하지 못한다.

답변

2

hMailServer에서 이메일을 전송하기 위해, 당신은 (here을 설명)과 같은 전송 객체를 생성해야합니다

// Create the Transport the call setUsername() and setPassword() 
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25) 
    ->setUsername('username') 
    ->setPassword('password') 
    ; 

// Create the Mailer using your created Transport 
$mailer = Swift_Mailer::newInstance($transport); 

은 또한 당신이 당신의 대응과 smtp.example.org, usernamepasswort를 교체 할 필요가 있습니다 hMailServer의 설정.

현재 스크립트는 hMailServer를 통해 이메일을 보내지 않고 스크립트가있는 서버에서 php mail() function으로 이메일을 전송합니다. mail() 기능과 함께 FROM 주소를 사용할 수 있지만 많은 이메일 제공 업체는이를 스팸으로 인식합니다. 따라서 전송 객체를 만드는 것이 좋습니다.

+0

그래서이 시점까지 메일 서버에 들어 가지 않고 메일을 보냈습니까? 나는 "에서"어떤 unexisting 주소로 변경하고 일했습니다! 변형으로 변경 한 후 사용자 이름과 비밀번호를 확인하기 시작했습니다. 답변 주셔서 감사합니다. 이제 어떻게 작동하는지 알게되었습니다. –