使用 CakePHP 3.0 发送邮件 [英] Sending Mail using CakePHP 3.0

查看:19
本文介绍了使用 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.

有两种方法可以实现:

  1. 在带有邮件配置的真实服务器上使用它

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆