gpt4 book ai didi

php - 使用 codeigniter php 插入数据后发送电子邮件

转载 作者:行者123 更新时间:2023-11-29 11:12:39 25 4
gpt4 key购买 nike

使用codeigniter PHP将数据插入数据库后发送电子邮件不起作用。数据插入成功,但MAIL功能不起作用获取 www.hostname.com 页面无法正常工作。任何人都可以帮助我吗?提前致谢。这是我的代码。

Controller :

class Blog extends CI_Controller 
{
function __construct()
{
parent::__construct();
//here we will autoload the pagination library
$this->load->model('blogs_model');
$this->load->library('email');
}
function addcomments()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
$this->form_validation->set_rules('first_name','First Name' , 'required');
$this->form_validation->set_rules('email','Email');
$this->form_validation->set_rules('location','Location');
$this->form_validation->set_rules('description','Description');
if($this->form_validation->run()== FALSE)
{
$data['mainpage']='blogs';
$this->load->view('templates/template',$data);
}
else
{

//insert the user registration details into database
$data=array(
'blog_id'=>$this->input->post('bl_id'),
'first_name'=>$this->input->post('first_name'),
'email'=>$this->input->post('email'),
'description'=>$this->input->post('description'),
'location'=>$this->input->post('location')
);
// insert form data into database
if ($this->blogs_model -> insertcomments($data))
{
// send email
if ($this->blogs_model->send_mail($this->input->post('email')))
{
// successfully sent mail
$this->flash->success('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
redirect("blog");
}
else
{
// error
$this->flash->success('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect("blog");
}
}
else
{
// error
$this->flash->success('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('blog');
}
}
}
}

型号:

function insertcomments($data)
{
return $this->db->insert('comments', $data);
//$this->db->insert('comments',$data);
//return $this->input->post('bl_id');
}

function sendEmail($to_email)
{

//configure email settings
$config=Array(
'protocol'=> 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com', //smtp host name
'smtp_port' => '465', //smtp port number
'smtp_user' => 'xxxx@gmail.com',
'smtp_pass' => '************', //$from_email password
'mailtype' =>'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);

//send mail
$this->load->library('email',$config);
$this->email->from('xxxx@gmail.com', 'Admin');
$this->email->to('yyy@gmail.com');
$this->email->subject('Comments');
$this->email->message('Testing');
$this->email->set_newline("\r\n");
return $this->email->send();
}

最佳答案

您在 Controller 中使用了错误的方法名称发送电子邮件:

$this->blogs_model->send_mail($this->input->post('email'))

正确的函数名称是sendEmail()

$this->blogs_model->sendEmail($this->input->post('email'))

关于php - 使用 codeigniter php 插入数据后发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40261243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com