我正在努力找出如何使用CakeEmail。为此,我使用页面控制器创建了一个名为email-tester.ctp的视图。我通过直接调用页面来访问它(mydomain/mypath/ page /email-tester)。
视图本身只保存文档中的标准代码,大致如下:
<?php
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->from(array('myaccount@gmail.com' => 'My Gmail Address'))
->to('my@email-address')
->subject('About')
->send('My message');
?>
<p>Email sent...</p>我还创建了一个电子邮件配置文件(email.php),如下所示:
class EmailConfig {
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myaccount@gmail.com',
'password' => 'mypassword-for-gmail',
'transport' => 'Smtp',
);
}当我运行这个页面时,我只得到一个内部服务器错误:
错误:发生了内部错误。堆栈跟踪
CORE/Cake/Network/Email/MailTransport.php line 51 → MailTransport->_mail(string, string, string, string, null)
CORE/Cake/Network/Email/CakeEmail.php line 1158 → MailTransport->send(CakeEmail)
APP/View/Pages/email-tester.ctp line 8 → CakeEmail->send(string)
CORE/Cake/View/View.php line 948 → include(string)
CORE/Cake/View/View.php line 910 → View->_evaluate(string, array)
CORE/Cake/View/View.php line 471 → View->_render(string)
CORE/Cake/Controller/Controller.php line 954 → View->render(string, null)
APP/Controller/PagesController.php line 69 → Controller->render(string)
[internal function] → PagesController->display(string)
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(PagesController, array)
CORE/Cake/Routing/Dispatcher.php line 191 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 165 → Dispatcher->_invoke(PagesController, CakeRequest)
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)有人能指出我哪里出了问题吗?我是否需要在我工作的本地开发机器上运行一个邮件服务器?还是这个问题更基本?
从其他研究中,我看到了一些建议,即php.ini文件应该包含扩展名php_openssl的一行,但是这只会导致出现一条错误消息,表示没有找到扩展名:可能是因为它是通过gnutls包含的(我在Ubuntu14.10上)。
任何帮助都将不胜感激。
彼得
发布于 2014-11-18 00:32:40
如果您是从本地服务器(如wampp、xampp等)工作,则此功能将无法工作,您确实需要有一个邮件服务器设置才能使其工作。一旦打开,或者如果您可以在真正的服务器上进行测试,这可能会有所帮助:
在:
Views->Layouts->Emails->html我的电子邮件有一个html模板,名为“客户报告”:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title><?php echo $title_for_layout;?></title>
</head>
<body>
<?php echo $content_for_layout;?>
</body>
</html>另外,您在EmailConfig文件中的var应该命名smtp以使其工作,检查我的文件是如何设置的。
class EmailConfig {
public $smtp = array(
'transport' => 'Smtp',
'from' => array('myaddress@gmail.com' => 'Senders name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'myaddress@gmail.com',
'password' => 'mypassword',
'client' => null,
'log' => false
);
}最后,这是我如何发送电子邮件的一个简单例子:
$email = new CakeEmail('smtp');
$email->template('clientsreport', 'clientsreport');
$email->emailFormat('html');
$email->viewVars(array('message' => "This is the body of the message"));
$email->from(array('from@gmail.com' => 'Senders name'));
$email->to('whoisthemailfor@gmail.com');
//Only if neccesary this is how to carbon copy someone
$email->cc(array('carbon@one.com','carbon@two.com'));
$email->subject('Subject for the email');
$email->send(); 我希望这有帮助,祝你好运!
https://stackoverflow.com/questions/26755685
复制相似问题