Im phalcon中的新功能需要一個phpmailer的工作示例,該示例從我的站點發送電子郵件。目前我只是想這樣。我只是按照這個鏈接:github.com/asyamedya/phalcon-phpmailer。如何在phalcon中使用phpmailer發送郵件php
[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
[有你甚至試着用搜索引擎這個(https://github.com/asyamedya/phalcon-phpmailer)?你有什麼嘗試?你得到什麼樣的錯誤? – Timothy
你應該嘗試一些,如果你失敗了,然後問我們。 StackOverflow不是我們爲您編寫代碼的服務。請多加努力。 –
Niki Mihaylov&Timothy!我更新了我的問題。並無法發送郵件。請!告訴我的錯是什麼?我得到致命錯誤:在第177行的C:\ xampp \ htdocs \ demo \ app \ config \ services.php中找不到類「Phalcon \ PHPMailer」 –