2017-10-22 2 views
0

구성 파일에 내 smtp 메일러를 설정할 때 정상적으로 작동합니다. 하지만 수동으로 SMPT 메일러를 만들면 실패합니다 (Connection refused). 아무도 도와 줄 수 있니?yii2 mailer smtp connection refused

Yii2의 설정 파일 :

$mailer = new \yii\swiftmailer\Mailer(); 
$mailer->transport = new \Swift_SmtpTransport(); 
$mailer->transport 
    ->setHost('smtp.gmail.com') 
    ->setPort(587) 
    ->setEncryption('tls'); 
$mailer->transport->setUsername('[email protected]'); 
$mailer->transport->setPassword('password'); 

나는 오류 메시지가 나타납니다 :

'components'=[ 
     'mailer' => [ 
      'class' => 'yii\swiftmailer\Mailer', 
      'transport' => [ 
       'class' => 'Swift_SmtpTransport', 
       'host' => 'smtp.gmail.com', 
       'username' => '[email protected]', 
       'password' => 'password', 
       'port' => '587', 
       'encryption' => 'tls', 
      ], 

내 컨트롤러에서 다음 코드는 작동하지 않는 연결은 # 111

내가 시도 거부 ssl의 포트 465와 같은 메시지가 나타납니다.

내 주된 이유는 다른 고객 계정을 가지고 있기 때문입니다. 각 고객 계정에는 고유 한 smtp가 있습니다. 따라서 클라이언트 당 하나의 계정이 필요하며 config 파일을 통해 그렇게 할 수 없습니다.

많은 도움에 감사드립니다.

+0

$ mailer 개체를 만들 필요가 없습니다. 한번 설정이 완료되면 이메일 yii2 기능을 사용하여 메일을 설정합니다. –

+0

@RajeshPradhan 감사합니다 -하지만 각 SMTP 계정에 대해 하나씩 세 가지 구성이 필요합니다. 어떻게해야합니까? – DrBorrow

+0

이 링크를 확인하십시오 .https : //github.com/yiisoft/yii2/issues/2723 예를 들어, mailer2는 이제 Yii :: $ app-> mailer2-> compose() ...를 호출하여 새 메일러 구성 요소를 만듭니다. malier2는 다른 설정을 갖습니다. 내가 대답 해 주면 알려주세요. –

답변

1

난 그냥 사용자 정의 메일러 설정

Yii::$app->mailer2->compose() 
     ->setFrom('[email protected]') 
     ->setTo('[email protected]') 
     ->setSubject('Subject') 
     ->setTextBody('Plain text content') 
     ->setHtmlBody("Hello") 
     ->send(); 

구성 요소를 작성하여 다음과 같은 기본 설정

Yii::$app->mailer->compose() 
     ->setFrom('[email protected]') 
     ->setTo('[email protected]') 
     ->setSubject('Subject') 
     ->setTextBody('Plain text content') 
     ->setHtmlBody("Hello") 
     ->send(); 

위한 다음

'components'=[ 
    'mailer' => [ //Your default mailer 
     'class' => 'yii\swiftmailer\Mailer', 
     'transport' => [ 
      'class' => 'Swift_SmtpTransport', 
      'host' => 'smtp.gmail.com', 
      'username' => '[email protected]', 
      'password' => 'password', 
      'port' => '587', 
      'encryption' => 'tls', 
     ], 
    ], 
'mailer2' => [ //Your custom mailer 
     'class' => 'yii\swiftmailer\Mailer', 
     'transport' => [ 
      'class' => 'Swift_SmtpTransport', 
      'host' => 'smtp.gmail.com', 
      'username' => '[email protected]', 
      'password' => 'new_password', 
      'port' => 'new_port587', 
      'encryption' => 'new_tls', 
     ], 
    ] 

를 따를 때 내가 한, 그것은 나를 위해 일한 시도 가장 빠른 솔루션입니다. 그렇지 않은 경우 매개 변수를 사용하여 구성을 저장하고 필요합니다.

+0

Rajesh 정말 고마워요. 귀하의 게시물을 읽고, 나는 정말 간단한 실수를 한 것을 알았습니다! 나는 당신의 접근 방식을 복사했고 훌륭하게 작동합니다. 정말 고맙습니다! – DrBorrow

+0

기쁜 소식입니다. –