0

我正在尝试使用 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();
4

3 回答 3

3

还要尝试让您的代码更具可读性。我注意到,您用于消息的巨大字符串充满了进出动态变量的延续。随着它的进行,将字符串链接在一起。

为什么不试试

$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()不确定那是功能还是其他东西,但看起来并不完整。

于 2013-11-07T17:54:29.720 回答
1

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

yum install sendmail

或者

sudo apt-get install sendmail

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

发送测试邮件, echo "test sendmail" | sendmail xxx@yy.com

于 2013-11-07T17:41:12.420 回答
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();
于 2013-11-07T18:00:54.857 回答