2016-07-25 2 views
0

phalcon에 새로운 내용이 있음 내 사이트에서 이메일을 보내는 phpmailer의 작동 예제가 필요합니다. 현재 나는 이걸 알아 냈어. 나는 단지이 링크를 따라 간다 : github.com/asyamedya/phalcon-phpmailer.팔콘 phpmailer로 phalailer로 이메일을 보내는 방법

[config.php를]

$config = new Phalcon\Config(array(
"app"    => array(
"controllersDir"=> "app/controllers/", 
"modelsDir"  => "app/models/", 
"viewsDir"  => "app/views/", 
"pluginsDir" => "app/plugins/", 
"libraryDir" => "app/library/", 
"helpersDir" => "app/helpers/", 
"formsDir"  => "app/forms/", 
"cacheDir"  => "cache/volt/", 
"logsDir"  => "cache/logs/", 
"encryptKey" => "", 
"baseUri"  => "/demo/", 
"StaticBaseUri" => "http://localhost/demo/", 
"debug"   => '0', 
), 
"mail"    => array(
    "driver"  => "smtp", 
    "host"   => "smtp.gmail.co",       
    "username"  => "[email protected]",    
    "password"  => "*****",       
    "security"  => "tls", //ssl:465, tls:587      
    "port"   => 587, 
    "charset"  => "UTF-8", 
    "email"   => "[email protected]", 
    "name"   => "webmaster", 
), 
)); 

[loader.php]

use Phalcon\Loader; 
$loader = new Loader(); 
$loader->registerDirs(
    array(
     APP_PATH . $config->app->controllersDir, 
     APP_PATH . $config->app->modelsDir, 
     APP_PATH . $config->app->pluginsDir, 
     APP_PATH . $config->app->libraryDir, 
     APP_PATH . $config->app->helpersDir, 
     APP_PATH . $config->app->formsDir, 
     APP_PATH . $config->app->cacheDir, 
    ) 
)->register(); 

[service.php]

use Phalcon\DI\FactoryDefault; 
use Phalcon\Mvc\View; 
use Phalcon\Mvc\Dispatcher; 
use Phalcon\Mvc\Url as UrlResolver; 
use Phalcon\Mvc\Router; 
use Phalcon\Security; 
use \PHPMailer as PHPMailer; 
use Phalcon\Mvc\View\Engine\Volt; 
use Phalcon\Events\Manager as EventsManager; 
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; 
use Phalcon\Flash\Session as FlashSession; 
use Phalcon\Logger\Adapter\File as Logger; 
use Phalcon\Mvc\Model\Metadata\Apc as ApcMetaData; 
use Phalcon\Session\Adapter\Files as SessionAdapter; 

    require(APP_PATH . $config->app->libraryDir . 'PHPMailer/PHPMailerAutoload.php'); 
    $di->set('pmailer', function() use ($config){ 
    $pmailer = new PHPMailer(); 
    //$mail->setLanguage('fr', '/optional/path/to/language/directory/'); 
    $pmailer->isSMTP(true); 
    $pmailer->SMTPDebug = 2; // Enable verbose debug output 
    $pmailer->SMTPOptions = array(
    'ssl' => array(
    'verify_peer' => false, 
    'verify_peer_name' => false, 
    'allow_self_signed' => true 
    ) 
    ); 
    $pmailer->Charset = $config->mail->charset; 
    $pmailer->Host = $config->mail->host; 
    $pmailer->SMTPAuth = true; 
    $pmailer->Username = $config->mail->username; 
    $pmailer->Password = $config->mail->password; 
    $pmailer->SMTPSecure = $config->mail->security; 
    $pmailer->Port = $config->mail->port; 
    $pmailer->addAddress($config->mail->email,$config->mail->name); 
    $pmailer->isHTML(true); 
    return $pmailer; 
}); 

[컨트롤러 인덱스]

public function SendmailAction() 
{ 
    $this->pmailer->From = "[email protected]"; 
    $this->pmailer->FromName = "user"; 
    $this->pmailer->addReplyTo("[email protected]", "user"); 
    $this->pmailer->addAddress('[email protected]'); 
    $this->pmailer->Subject = "email test !"; 
    $this->pmailer->Body = "success!"; 
    $this->pmailer->WordWrap = 70; 
    if(!$this->pmailer->send()){echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $this->pmailer->ErrorInfo; 
    } else { 
    echo 'Message has been sent'; 
    } 
} 
,

내 라이브러리에이 파일이 있습니다.

[라이브러리/PHPMailer /]

class.phpmailer.php 
class.pop3.php 
class.smtp.php 
PHPMailerAutoload.php 
class.phpmaileroauthgoogle.php 
+1

[당신도이 인터넷 검색을 봤어 (https://github.com/asyamedya/phalcon-phpmailer)? 너 뭐 해봤 니? 어떤 종류의 오류가 있습니까? – Timothy

+2

뭔가를 시도하고 실패하면 우리에게 물어보십시오. StackOverflow는 코드를 작성하는 서비스가 아닙니다. 더 노력하십시오. –

+0

Niki Mihaylov & Timothy! 내 질문을 업데이트했습니다. 메일을 보낼 수 없습니다. 부디! 내 잘못은 뭐니? 나는 치명적인 오류가 발생한다 : 'Phalcon \ PHPMailer'클래스가 177 행의 C : \ xampp \ htdocs \ demo \ app \ config \ services.php에 없다. –

답변

0

잘 모르겠지만, 내가이 당신의 service.php

use Phalcon\PHPMailer;

변경을 잘못 생각 ~

use \PHPMailer as PHPMailer;

+0

받기 : 경고 : 비 복합 명 ' PHPMailer '는 11 행의 C : \ xampp \ htdocs \ demo \ app \ config \ services.php에 아무런 영향을 미치지 않습니다. 치명적인 오류 : C : \ xampp \ htdocs \ demo \ app \ config \ services.php on line 177 –

+0

업데이트, 놓친 \ – Borjante

+0

여전히 같은 문제! 실례를 줄 수있는 사람이 여기 있습니까? 또한 테스트를 거쳤습니다. –