Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么不是';Codeigniter电子邮件类是否使用sendmail发送邮件?_Php_Codeigniter - Fatal编程技术网

Php 为什么不是';Codeigniter电子邮件类是否使用sendmail发送邮件?

Php 为什么不是';Codeigniter电子邮件类是否使用sendmail发送邮件?,php,codeigniter,Php,Codeigniter,我正在尝试向注册我的网站的注册者发送电子邮件地址,但是我的代码的这一部分没有运行。我正试图找出原因。我遵循了所有必要的文档。我用php的mail函数替换了这一部分,以进行调试,看看它是否会在我的服务器上发送电子邮件,并且会。有没有人想过会是什么 // User was successfully created and the user needs to verify their account. // Send registered an email informing them how to

我正在尝试向注册我的网站的注册者发送电子邮件地址,但是我的代码的这一部分没有运行。我正试图找出原因。我遵循了所有必要的文档。我用php的mail函数替换了这一部分,以进行调试,看看它是否会在我的服务器上发送电子邮件,并且会。有没有人想过会是什么

// User was successfully created and the user needs to verify their account.
// Send registered an email informing them how to validate their account.
$this->load->library('email');
$this->email->from('owner@owner.com', 'Owner Name');
$this->email->to($post_email_address);
$this->email->subject('Site Name Here Registration');
$this->email->message('Thank you for registering for our site. Here is your registration key to activate your account: '.$registration_key.' Please click on the following link to activate your account.<br />'.anchor('project-manager/login/verify/'.$registration_key, 'Click Here To Activate Your Account', ''));

$this->email->send();
//用户已成功创建,用户需要验证其帐户。
//发送注册电子邮件,通知他们如何验证其帐户。
$this->load->library('email');
$this->email->from($this)owner@owner.com“,”所有者名称“);
$this->email->to($post\u email\u address);
$this->email->subject('Site Name Here Registration');
$this->email->message('感谢您注册我们的网站。这是您激活帐户的注册码:'.$registration\u key'。请单击以下链接激活您的帐户。
。'anchor('项目经理/登录/验证/'。$registration\u key,'单击此处激活您的帐户',''); $this->email->send();
下面是application/config目录中email.com的配置

<?php 
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

我知道这似乎是不必要的,但我通常总是在mail类中使用SMTP。服务器配置问题太多,可能导致邮件无法发送。有时,匿名(例如“nobody”或“www data”)用户被限制使用sendmail—如果服务器未正确配置suexec,这是一个非常常见的问题

此外,使用SMTP依赖于已知工作邮件服务器的已知良好DNS/SPF设置-在您使用的单个应用服务器上可能不是这种情况

你可能需要进一步挖掘问题的根源,甚至可能纠正它——但是如果你需要移动你的应用程序,或者启动更多的服务器,那么同样的问题就会再次出现

只需按照以下步骤使用SMTP,这实际上只是相应地更改
$config['protocol']
的问题,然后添加SMTP主机/user/pass变量。建立一个电子邮件帐户,并尝试一下。邮件转发设置也可以更优雅地处理
noreply
之类的事情

要尝试,只需覆盖控制器中的
$config
数组,例如:

$myTempConfig['protocol']  = 'smtp'; 
$myTempConfig['smtp_host'] = 'mail.somedomain.com';
$myTempConfig['smtp_user'] = 'username';
$myTempConfig['smtp_pass'] = 'swordfish';
$myTempConfig['smtp_port'] = 25;
$myTempConfig['smtp_timeout'] = 30; // adjust as needed for busy mail servers
然后打电话:

 $this->email->initialize($myTempConfig)
因此,它加载设置。如果你愿意的话,你可以把它叫做
$config
,我只是想清楚我在做什么

其实最好是摆脱这个问题,一劳永逸地解决它。一旦你有了SMTP设置,你的代码就可以工作了,不管你把它放在哪里


大多数体面的主机都正确地利用了suexec,这意味着邮件类将使用sendmail“正常工作”。但是,如果您倾向于在平台即服务提供商或您自己的服务器上部署大量内容,那么使用SMTP并节省一些麻烦和工作就更有意义了。

尝试
echo$this->email->print_debugger()查看是否有任何错误消息。我没有收到任何错误。它说它已成功发送。您是否在
/config/
目录中配置了email.php?是的,很抱歉,我最初没有包含它。我会更新我的帖子。