1
제 질문은 아마도 PHP 전문가를위한 것이지만 Yii 프레임 워크를 사용하고 있습니다. 웹 응용 프로그램에서 전자 메일을 보낼 수있는 컨트롤러를 만들었으므로 제대로 작동합니다.Yii php에서 도우미를 사용할 때 이메일을 보내지 않습니다.
내 app에서 여러 sontrollers에서 전자 메일을 사용하려는 경우 도우미를 만들고 싶지만 작동하지 않습니다. 이메일이 전송되지 않습니다.
<?php
class MailController extends Controller
{
/**
* Declares class-based actions.
*/
public function actionSendemail() {
// Plain text content
$plainTextContent = "This is my first line ;-)\nThis is my second row of text";
// Get mailer
$SM = Yii::app()->swiftMailer;
// New transport mailHost= localhost, mailPort = 25
$Transport = $SM->smtpTransport(Yii::app()->params['mailHost'], Yii::app()->params['mailPort']);
// Mailer
$Mailer = $SM->mailer($Transport);
// New message
$Message = $SM
->newMessage('My subject')
->setFrom(array('[email protected]' => 'Example Name'))
->setTo(array('[email protected]' => 'Recipient Name'))
// ->addPart($content, 'text/html')
->setBody($plainTextContent);
// Send mail
$result = $Mailer->send($Message);
}
}
도우미 코드는
을 따르고 내가 전화를 다음<?php
// protected/components/Email.php
class Email {
public static function sendEmail($subject, $from, $to, $body)
{
// Get mailer
$SM = Yii::app()->swiftMailer;
// New transport
$Transport = $SM->smtpTransport(Yii::app()->params['mailHost'], Yii::app()->params['mailPort']);
// Mailer
$Mailer = $SM->mailer($Transport);
// New message
$Message = $SM
->newMessage($subject)
->setFrom(array($from => 'Example Name'))
->setTo(array($to => 'Recipient Name'))
// ->addPart($content, 'text/html')
->setBody($body);
// Send mail
$result = $Mailer->send($Message);
}
}
방법입니다 :
작업 컨트롤러의 코드는 다음과 같다 (나는 swiftmailer을 사용하고 있습니다)
$subject= 'My subject';
$from = Yii::app()->params['adminEmail']; // adminEmai is a globalparam like above controller
$to='[email protected]';
$body='my body';
Email::sendEmail($subject, $from, $to, $body);
이 코드를 실행하면 오류가 발생하지 않지만 전자 메일은받지 못합니다.
도움 주셔서 감사합니다.