我正在创建一个页面以发送电子邮件并将其存储到数据库中。我已经尝试过并设法保存到数据库中,但是无法发送到电子邮件。
我的控制器
public function create()
{
$data = array(
'email' => $this->input->post('email',TRUE),
'requestorname' => $this->input->post('requestorname',TRUE),
'namemess' => $this->input->post('namemess',TRUE),
'nomess' => $this->input->post('nomess',TRUE),
);
$this->load->model('mymodel');
$this->mymodel->insert($data);
$this->load->library('email');
$config = array();
$config['charset'] = 'iso-8859-1';
$config['useragent'] = 'Codeigniter';
$config['protocol']= "smtp";
$config['mailtype']= "html";
$config['smtp_host']= "sxxxxx.gridserver.com";
$config['smtp_port']= "465";
$config['smtp_user']= "[email protected]";
$config['smtp_pass']= "mypass";
$config['newline']="\r\n";
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$subject = "Confirmation";
$this->email->from($config['smtp_user']);
$this->email->to('email');
$this->email->subject($subject);
$this->email->message('.$data['requestorname'].','.$data['namemess'].','.$data['nomess'].');
$this->email->send();
echo $this->email->print_debugger();
redirect(site_url('page'));
}
}
和我的模特
public $table = 'mydatabase';
public $id = 'id';
public $order = 'DESC';
// insert data
function insert($data)
{
$this->db->insert($this->table, $data);
}
怎么解决呢?
试试我从一些免费教程中获得的代码
$config = Array(
'protocol' => 'smtp',
'mailpath' =>'/usr/sbin/sendmail',
'smtp_host' => 'sxxxxx.gridserver.com',
'smtp_port' => 25,
'smtp_timeout' =>7,
'smtp_user' => '[email protected]', // change it to yours
'smtp_pass' => '******', // change it to yours
'mailtype' => 'html',
'charset' => 'utf-8',
'crlf' => "\r\n",
'newline' => "\r\n",
'wordwrap' => TRUE
);
$this->email->initialize($config);
$this->email->from('[email protected]');
$this->email->to($data['email']);
$this->email->subject($subject); #change
$this->email->message($message); #change
if($this->email->send())
{
echo "mail send";
}
else
{
show_error($this->email->print_debugger());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句