繁体   English   中英

使用Codeigniter发送电子邮件需要花费大量时间

[英]Sending Email with Codeigniter Taking So much time

这是我的代码,其中在用户注册时发送电子邮件。 每封邮件需要5分钟或更长时间才能到达用户电子邮件。 我不知道为什么电子邮件要花这么多时间才能到达。 如果我要发送具有相同功能的电子邮件sendEmail()而不是仅带有简单文本的验证码。 现在需要1分钟或1 n半分钟才能到达用户电子邮件。

有时,当我在链接末尾发送验证码时,它甚至不发送任何电子邮件。

我不知道如何使用SMTP发送电子邮件。 我找到了一些示例,他们在其中将域名添加到smtp_host,电子邮件,密码,该电子邮件是使用域创建的。 我做了同样的事情,但是我的电子邮件发送没有任何反应。 无论我是否使用SMTP,都与此几乎相同。

这是我创建的用于发送电子邮件的模型的函数名称sendEmail( )。 之所以在模型中创建此功能,是因为我也必须从其他控制器发送电子邮件。 我不认为这可能是发送电子邮件时遇到的问题

请在我做错的地方查看此功能。 或者如果还有其他方法,请告诉我该怎么做。否则任何建议对我都非常有帮助。

调节器

function index() {
        //my validation rules are here  
        if ($this->form_validation->run() == TRUE) {

            $data = $this->fetch_data_from_post();
            $user_email = $data['email'];
            $code =  random_string('unique');
            $verification_link = base_url('Home/verify/').$code;
            $subject = "Confirmation Message";
            $message = "Dear User,\n\n\nPlease click on Given below URL  to verify your Email Address ".$verification_link." \n\n Once you click on the above link then your account will be verified and you will get an opportunity to login. See you soon,Thank You...!\n";
            $email_sent = $this->Perfect_mdl->sendEmail($user_email,$subject,$message);

            if($email_sent != 1){
                $flash = '<div class="alert alert-danger">Opppssss Somthing went Wrong...</div>';
                $this->session->set_flashdata('user_registration',$flash);
                redirect('Home/signup');

            }else{
                $this->Perfect_mdl->_insert($data);
                $flash = '<div class="alert alert-success">You are Successfully Registered... Please Check Your Email <b>'.$user_email.'</b> For Verification</div>';
                $this->session->set_flashdata('user_registration',$flash);
                redirect('Home/signup');
            }
        }

        $data['meta_title']  = "Signup";
        $data['services_name'] = $this->Perfect_mdl->getServices_home();
        $dat['flash'] = $this->session->flashdata('user_registration');
        $this->load->view('signup',$data);
    }

模型:-

function sendEmail($useremail,$subject,$message) {


     $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'smtp.mydomainname.com',
    'smtp_port' => 25,
    'smtp_user' => 'vishal@mydomainname.com', // change it to yours
    'smtp_pass' => 'vishal123456', // change it to yours
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'crlf' => "\r\n",
    'newline' => "\r\n",
    'wordwrap' => TRUE
    );
    $this->load->library('email', $config); 
    $this->email->from('vishal@mydomainname.com', 'Company Name');
    $this->email->to($useremail);   


    $this->email->subject($subject);
    $this->email->message($message);
    if($this->email->send()){
        return "1";
    }else{
        return "0";
    }
}

不会是速度较慢的类,它将是您尝试连接到的SMTP邮件服务器,该服务器发送造成页面滞后的电子邮件。 这是我的一些建议。

首先,在application/config内创建一个自定义配置文件email.ph p。请确保此配置已自动Autoload.phpapplication/config内打开您的Autoload.php并写入$autoload['config'] = array('email');

就我而言,我是通过Webmail ID发送电子邮件,所以这是我的email.php

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'SMTP_HOST_NAME',
    'smtp_port' => 25,
    'smtp_user' => 'SMTP_USER_NAME', // change it to your user name
    'smtp_pass' => 'SMTP_PASSWORD', // change it to your password
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
);

使用这样的父结构:

function __construct()
{
  parent::__construct();          
  $this->load->library('email', $config);
}

然后,您可以像这样轻松地发送电子邮件:

$this->email->from('info@example.net', 'Account');
$this->email->to('johndoe@example.com');
$this->email->cc('johndoe@example.com');
$this->email->bcc('johndoe@example.com');
$this->email->subject('Account Confirmation');
$message = "any message body you want to send";
$this->email->message($message);
$this->email->send();

如果您遵循此过程,则可能可以节省几秒钟。

在您的控制器中尝试这样。

公共函数sendResetEmail($ params){

        $params['body'] = 'emails/password_reset';
        $params['title'] = 'Forgot Password';
        $params['subject'] = 'Mail From Admin - Reset Password ';
        $params['reset_url'] = base_url() . 'login/reset/?key=' . $params['reset_key'] . '&email=' . $params['email_user'];
        $params['mailtype'] = 'html';
        $this->email->set_mailtype("html");
        $this->email->from('info@example.co.in', 'admin');
        $this->email->to($params['email_user']);
        $this->email->subject($params['subject']);
        $this->email->message($this->load->view('emails/main', $params, true)); 
        $this->email->send();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM