退出状态代码1无法发送电子邮件

时间:2013-11-07 17:34:12

标签: php codeigniter

我正在尝试使用Codeigniter提供的电子邮件类为我的项目发送电子邮件给注册我网站的人员。我收到以下错误消息。

Exit status code: 1
Unable to open a socket to Sendmail. Please check settings.
Unable to send email using PHP Sendmail. Your server might not be configured to sendmail using this method.

$this->email->message('Welcome to '.$this->config->item('company_name').', "\r\n" Thank you for joining the '.$this->config->item('company_name').' team. We have listed your registration details below. Make sure you save this email. To verify this account please click the following link. "\r\n" '.anchor('register/verify/'.$registration_key, 'Click Here To Activate Your Account', '').' "\r\n" Please verfiy your account within 2 hours, otherwise your registration will become invalid and you will have to register again. "\r\n" Your email address: '.$post_email_address.' "\r\n" Your Password: '.$post_password.' "\r\n" Enjoy your stay here at '.$this->config->item('company_name').' "\r\n" The '.$this->config->item('company_name').' Team');

更新:

我正在更新我的代码,因为由于某种原因我仍然收到相同的错误,我无法弄清楚是什么给了我错误。

../application/configs/site_configs.php
<?php

$config['company_name'] = 'My Test Site';
$config['comapny_email'] = 'owner@testingsite.com';

我还想在此提及我正在自动加载我的网站配置文件。

$autoload['config'] = array('site_configs');

注册控制器

// 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($this->config->item('company_email'), $this->config->item('company_name'));
$this->email->to($post_email_address);
$this->email->subject($this->config->item('company_name').' Registration');
//$message = 'Welcome to '. $this->config->item('company_name') ."\r\n";
//$message .= 'Thank you for joining the ' . $this->config->item('company_name') . ' team.';
//$message .= 'We have listed your registration details below. Make sure you save this email.';
//$message .= 'To verify this account please click the following link.'."\r\n";
//$message .= anchor('register/verify/'.$registration_key, 'Click Here To Activate Your Account', '')."\r\n";
//$message .= 'Please verfiy your account within 2 hours, otherwise your registration will become invalid and you will have to register again.'."\r\n";
//$message .= 'Your email address: '.$post_email_address."\r\n";
//$message .= 'Your Password: '.$post_password."\r\n";
//$message .= 'Enjoy your stay here at '.$this->config->item('company_name')."\r\n";
//$message .= 'The '.$this->config->item('company_name').' Team';
$this->email->message('Great registration.' /*$message */);
$this->email->send();
echo $this->email->print_debugger();

3 个答案:

答案 0 :(得分:2)

还试着让你的代码更具可读性......我注意到,你的巨大字符串充满了继续进出动态变量。随着时间的推移将字符串链接在一起。

为什么不试试

$message = 'Welcome to '. $this->config->item('company_name') ."\r\n";
$message .= 'Thank you for joining the ' . $this->config->item('company_name') . ' team.';
$message .= 'We have listed your registration details below. Make sure you save this email.';
$message .= 'To verify this account please click the following link.'."\r\n";
$message .= .anchor('register/verify/'.$registration_key, 'Click Here To Activate Your Account', '')."\r\n";
$message .= 'Please verfiy your account within 2 hours, otherwise your registration will become invalid and you will have to register again.'."\r\n";
$message .= 'Your email address: '.$post_email_address."\r\n";
$message .= 'Your Password: '.$post_password."\r\n";
$message .= 'Enjoy your stay here at '.$this->config->item('company_name')."\r\n";
$message .= 'The '.$this->config->item('company_name').' Team';



$this->email->message($message);

它更易于管理和阅读。因此,您可以看到您丢失单引号或双引号的位置,或者您可能缺少将字符串链接到变量等的句点。

我唯一不确定的是一行.anchor()不确定这是一个功能还是别的什么但看起来不完整。

答案 1 :(得分:1)

确保您的服务器具有sendmail,并且已在服务器中正确设置或安装sendmail包

yum install sendmail

OR

sudo apt-get install sendmail

使您的用户电子邮件ID有效,如果发件人不存在则不会发送电子邮件

发送testmail echo "test sendmail" | sendmail xxx@yy.com

答案 2 :(得分:1)

    $this->load->library('email');

    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'smtp.googlemail.com',
        'smtp_port' => 587,
        'smtp_user' => 'example@gmail.com',
        'smtp_pass' => 'password',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );
    $this->email->set_newline("\r\n");


    $this->email->from('example@gmail.com', 'easyfact');
    $this->email->to('example@gmail.com');
    $this->email->cc('example@gmail.com');
    $this->email->bcc('example@gmail.com');

    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');

    $this->email->send();

    echo $this->email->print_debugger();