问题描述
我正在开发一个具有新版本3.0的CakePHP框架的网站。我在localhost工作,并希望在用户填写表单后发送电子邮件。下面是我的控制器中发送电子邮件的代码。
I am developing a website with new version 3.0 of CakePHP Framework. I am working on localhost and would like to send an email after a user has filled a form. Below is the code in my controller to send the email.
public function index(){
if ($this->request->is('post'){
$email = new Email();
$email->from([$this->request->data["sender"] => "Sender"]
->to("[email protected]")
->subject($this->request->data["Subject"])
->send($this->request->data["message"]);
}
}
当这个代码执行没有什么发生,没有错误,没有消息在我的邮箱。我看到它存在于cakephp3.0一个类 DebugTransport
但我不知道如何使用它为了调试我的代码。有人已经使用它?
When this code is executed nothing happen, no error, no message in my mailbox. I have seen that it exist in cakephp3.0 a class called DebugTransport
but I don't know how to use it in order to debug my code. Someone has already use it ?
推荐答案
您必须使用smpt服务器在配置电子邮件中传递您的电子邮件。
You had to use a smpt server for delivery your email from your localhost in your config email.
2个选项:
从具有邮件配置的真实服务器使用它
Use it from a real server with a mail configuration
使用smpt服务器在本地主机上进行测试。有很多smpt服务器让你使用它。
请参阅mailjet.com
Use smpt server for your test on your localhost. there are a lot of smpt server with let you use it.see mailjet.com
这篇关于使用CakePHP 3.0发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!