下面的代码是为我的其他项目工作,但当我把这个上传到服务器,那么它不工作,请任何人帮助我解决这个问题。
我已经创建了一个发送电子邮件的帮助文件
$ci =& get_instance();
$config = Array(
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'validate' => TRUE ,
'newline' => "'r'n",
'wordwrap' => TRUE
);
$ci->load->library('email');
$ci->email->initialize($config);
$ci->email->from($fromemail, $fromname);
$ci->email->reply_to(APPLICATION_EMAIL, SITENAME);
$ci->email->to($toemail);
$template_msg=str_replace($replace_array,$new_array,$tempmsg);
$ci->email->subject(sprintf($subject, $data['site_name']));
$ci->email->message($template_msg);
$ci->email->send();
首先创建一个自定义配置文件
email.php inside application/config
在我的情况下,我通过webmail id发送电子邮件,所以这里是我的email。php
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'SMTP_HOST_NAME',
'smtp_port' => 25,
'smtp_user' => 'SMTP_USER_NAME', // change it to yours
'smtp_pass' => 'SMTP_PASSWORD', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
然后确保此配置是自动加载的。在application/config中打开autolload .php并写入
$autoload['config'] = array('email');
现在,每当你创建一个控制器,有许多方法使用电子邮件库。使用父结构
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();
当通过CI邮件库发送邮件时,这是最好的。你可以得到更多的信息。关于CI的邮件。由于