cakephp 2 CakeEmail无法发送电子邮件错误 [英] cakephp 2 CakeEmail Could not send email error

查看:650
本文介绍了cakephp 2 CakeEmail无法发送电子邮件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试让CakeEmail正常工作,并收到无法发送电子邮件内部错误。

  CORE / Cake / Network / Email / MailTransport.php line 47  - > MailTransport-> _mail(string,string,string,string,null)

在我的email.php config我有

  class EmailConfig {

public $ default = array(
'transport '=>'Mail',
'from'=>'no-reply@xxxxx.com.au'
);
}

我从表单收到我的电子邮件地址,用户。我的代码如下

  $ email_addr = $ subs_data ['Subscriber'] ['subscriber']; 

$ Email = new CakeEmail('default');

$ Email-> emailFormat('html')
- > template('welcome')
- > to($ email_addr)
- > ; subject('New Subscription')
- > send();

我做了一些测试,$ email_addr中的值正是来自表单,有效的电子邮件地址。



我在View / Emails / html / welcome.ctp中有一个模板,现在只是一个非常基本的消息



查看堆栈跟踪和MailTransport.php中的第47行我发现错误似乎与到电子邮件地址有关。我看不出有什么问题。我已经看了很多例子,据我可以告诉我没有做错什么。



我会感谢任何帮助,所以我可以得到这个应用程序完成。



种类问题



Richard

解决方案

您必须在EmailConfig中添加更多配置。



查看我的代码:

  class EmailConfig {
public $ fast = array(
'transport'=>'Smtp',
'from'=& test_mail@gmail.com'=>'测试邮件名称发件人'),
'host'=>'ssl://smtp.gmail.com',
'port'=> 465 ,
'username'=>'test_mail@gmail.com',
'password'=>'password');
}

并且在控制器中:

  CakeEmail :: deliver('to@gmail.com','Subject','Content'); 

就是这样!


I am trying to get CakeEmail working and I am getting a "Could not send email" Internal Error.

The last line of the stack trace is

CORE/Cake/Network/Email/MailTransport.php line 47 -> MailTransport->_mail(string,string,string,string,null)

In my email.php config I have

class EmailConfig {

    public $default = array(
        'transport' => 'Mail',
        'from' => 'no-reply@xxxxx.com.au'
        );
}

I receive my email address from a form and am trying to send an email to the subscriber. My code is as follows

$email_addr = $subs_data['Subscriber']['subscriber'];

$Email = new CakeEmail('default');

$Email->emailFormat('html')
      ->template('welcome')
      ->to($email_addr)
      ->subject('New Subscription')
      ->send();

I have done some testing and the value in $email_addr is exactly what is coming from the form and is a valid Email address.

I have a template in View/Emails/html/welcome.ctp that for now is just a very basic message

Looking at the stack trace and line 47 in MailTransport.php I have found the error appears to be to do with the "to" email address. I can not see what is wrong with it though. I have looked at a lot of examples and as far as I can tell I am not doing anything wrong.

I would appreciate any help so I could get this application finished.

Kind Regards

Richard

解决方案

You must add more configuration in EmailConfig.

Look at my code:

class EmailConfig {    
    public $fast = array(    
        'transport' => 'Smtp',    
        'from' => array('test_mail@gmail.com' => 'Test Mail name sender'),    
        'host' => 'ssl://smtp.gmail.com',    
        'port' => 465,    
        'username' => 'test_mail@gmail.com',    
        'password' => 'password');    
}

And in Controller:

CakeEmail::deliver('to@gmail.com', 'Subject', 'Content');

That's it!

这篇关于cakephp 2 CakeEmail无法发送电子邮件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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