我要发送电子邮件从cakephp 2.x在公司域电子邮件地址 [英] I Want to send email from cakephp 2.x in company domain email adress

查看:237
本文介绍了我要发送电子邮件从cakephp 2.x在公司域电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法发送mail.with下面的代码: - 如果我删除$ Email-> config('gmail')比我能够发送电子邮件id lke: - test@gmail.com,但无法发送电子邮件测试@ test-test @ gmail.com

I am not able to send mail.with below code:- if I remove $Email->config('gmail') than i am able to send email on id lke :- test@gmail.com but unable to send email on test@test-test@gmail.com

下面是我在AppController中添加的代码:

below is the code i have added in AppController:-

  function sendEmail($email, $subject, $body){
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
    $send=$Email->config('gmail')->from(array('support@test-apps.com'=>'test Apps'))
         ->to($email)
         ->subject($subject)
                    ->emailFormat('html')
            ->send($body);
 if($send){
    return "sent";
  }else {
    return "error";
    }
} 

my email config is :- 

class EmailConfig {

    public $gmail = array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'username' => 'my@gmail.com',
    'password' => 'secret',
    'transport' => 'Smtp'
   );
   }


推荐答案

配置也。尝试此

function sendEmail($to, $subject, $body){
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
    $Email->config('gmail') // gmail, smtp or any config you have created in email config
          ->emailFormat('html')
          ->from('tesst@gmail.com')              
          ->to($to)
          ->subject($subject);

 if($Email->send($body)){
    return "sent";
 }else {
    return "error";
 }

class EmailConfig {
    public $smtp = array( 
            'transport' => 'Smtp',
            'from' => array('info@domain.co.uk' => 'Company Name'),
            'host' => 'company host',
            'port' => 25,
            'timeout' => 30,
            'username' => 'email',
            'password' => 'password',
            'client' => null,
            'log' => false,                
    );

//add other email config e.g. gmail

    public $gmail = array(
            'host' => 'ssl://smtp.gmail.com',
            'port' => 465,
            'username' => 'my@gmail.com',
            'password' => 'secret',
            'transport' => 'Smtp'
        );
}

jut需要更改$ Email-> config('smtp' )到$ Email-> config('gmail')

并加载App :: uses('CakeEmail','Network / Email');在电流控制器或AppController的顶部

and load App::uses('CakeEmail', 'Network/Email'); on top of current controller or AppController

这篇关于我要发送电子邮件从cakephp 2.x在公司域电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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