使用 CakePHP 3.0 发送邮件 [英] Sending Mail using CakePHP 3.0
问题描述
我正在使用 CakePHP Framework 的新版本 3.0 开发一个网站.我在 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("myEmail@hotmail.com")
->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 ?
推荐答案
您必须使用 SMTP 服务器在配置电子邮件中从本地主机发送电子邮件.
You had to use a SMTP server for delivery your email from your localhost in your config email.
有两种方法可以实现:
在带有邮件配置的真实服务器上使用它
Use it from a real server with a mail configuration
使用 SMTP 服务器在本地主机上进行测试.有很多SMTP服务器让你使用它.请参阅 mailjet.com
Use SMTP server for your test on your localhost. there are a lot of SMTP server with let you use it. see mailjet.com
这篇关于使用 CakePHP 3.0 发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!