我无法使用Codeigniter发送任何电子邮件 [英] I cannot send any emails using Codeigniter
问题描述
我创建了一个控制器,并在控制器中创建了测试功能,以测试是否发送了电子邮件。
I have created a controller and made a test function in the controller to test if the email is sent or not.
我检查了不同的电子邮件地址,但没有不成功。这是我的代码示例:
I checked with different email addresses, but didn't succeed. This is my code example:
public function sendmail() {
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$user_id = 1;
$name = 'Mark Alan';
$this->email->set_newline("\r\n");
$this->email->from('info@domainname.com', "Test Name");
$this->email->to('test@domainname.com');
$this->email->subject('Test Mail');
$this->email->message('This is a test message');
$this->email->send();
echo $this->email->print_debugger();
}
推荐答案
使用Codeigniter(假设您有自动加载电子邮件库),您可以在名为email.php的配置文件中设置电子邮件首选项,然后从此处自动自动加载这些首选项。看起来像这样:
With Codeigniter (assuming you have auto-loaded the email library) you can either set an email preference in a config file, named email.php and these preferences are loaded automatically from there. It could look like:
// Setting Email Preferences
$config['useragent'] = 'CodeIgniter'; // Mail engine switcher: 'CodeIgniter' or could be 'PHPMailer'
$config['protocol'] = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
或者像您的示例一样,您可以手动设置,但是需要初始化它,所以在定义您的$ config []数组后不要忘记这一行:
or like in your example, you can set them manually, but need to initialize it, so don't forget this line after defining your $config[] array:
$this->email->initialize($config);
这篇关于我无法使用Codeigniter发送任何电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!