Php 使用Codeigniter发送电子邮件花费了太多时间
这是我的代码,在用户注册时发送电子邮件。每封邮件到达用户电子邮件需要5分钟或更长时间。我不知道为什么电子邮件要花这么多时间才能到达。如果我正在发送一封具有相同功能的电子邮件sendmail(),而不是仅带有简单文本的验证码。现在需要1分钟或1 n半分钟才能到达用户电子邮件 有时,当我在链接末尾发送验证码时,它甚至不发送任何电子邮件。 我不知道如何用SMTP发送电子邮件。我发现了一些例子,他们将自己的域名添加到smtp_主机、电子邮件、密码,这封电子邮件是用该域创建的。我也这么做了,但我的电子邮件发送没有发生任何变化。无论我是否使用SMTP,这几乎与此相同 这是我的函数名发送电子邮件(),我创建了发送电子邮件的模型。我之所以在模型中创建此函数,是因为我也必须从其他控制器发送电子邮件。 我不知道这是否是一个问题,在发送电子邮件 请查看我做错的函数。或者如果有其他方法,请告诉我怎么做。或者任何类型的建议都会对我很有帮助 控制器Php 使用Codeigniter发送电子邮件花费了太多时间,php,codeigniter,email,Php,Codeigniter,Email,这是我的代码,在用户注册时发送电子邮件。每封邮件到达用户电子邮件需要5分钟或更长时间。我不知道为什么电子邮件要花这么多时间才能到达。如果我正在发送一封具有相同功能的电子邮件sendmail(),而不是仅带有简单文本的验证码。现在需要1分钟或1 n半分钟才能到达用户电子邮件 有时,当我在链接末尾发送验证码时,它甚至不发送任何电子邮件。 我不知道如何用SMTP发送电子邮件。我发现了一些例子,他们将自己的域名添加到smtp_主机、电子邮件、密码,这封电子邮件是用该域创建的。我也这么做了,但我的电子邮件
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);
}
在您的控制器中尝试这样做
public function 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();
}
不是类速度慢,而是您尝试连接的SMTP邮件服务器发送的邮件造成页面延迟。 以下是我的一些建议 首先,在
application/config
请确保此配置是自动加载的。在应用程序/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();
然后你可以很容易地像这样:
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();
如果您遵循此过程,那么可能可以节省一些时间。为什么要使用SMTP
您是否从另一台服务器发送代码?如果都在本地主机上,那么就不需要SMTP
我不知道SMTP是如何工作的。原因是我使用smtp发送尽可能快地到达用户电子邮件。不,我正在将此用于服务器。删除该smpt配置数组..在live host中删除此配置后,无需使用此smtp配置..@Mahesh。条件是一样的。为什么要花这么长时间才能到达?只需在控制器中编写电子邮件代码并检查一下……它可能工作得更快……有时电子邮件会在2分钟内到达。但是如果它没有到达,那就需要五分钟。是否可以更快地发送电子邮件(不到一分钟)。将其添加到我的构造$this->load->library('email',$config)后
为什么会抛出错误:未定义$config,但我已经在我的config文件夹中创建了一个文件名email.php
,还添加了$autoload['config']=array('email')
进入我的autoload.php
。你创建的和我在回答中创建的一样吗@Vishalkumaron在构造函数中初始化电子邮件配置后,仅当在控制器中调用时,才不需要调用$config
@vishalkumar@vishalkumar如果我建议的答案有帮助,那么你可以接受我的答案。