提问者:小点点

CodeIgniter上的SMTP显示成功,但电子邮件未发送到Gmail帐户


我正在尝试在CodeIgniter上设置SMTP。一切都很好,我在页面上收到了一条成功消息,这封邮件发送时没有错误。但是,电子邮件没有发送。

以下是我使用的代码:

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'my-email@gmail.com', 
'smtp_pass' => '***', 
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);

$this->email->from('my-email@gmail.com', 'Explendid Videos');
$this->email->to('my-email@gmail.com');
$this->email->reply_to('my-email@gmail.com', 'Explendid Videos');


$this->email->subject('Explendid Video - Contact form');

$message = "Contact form\n\n";
$message .= "Name: ". $_POST['name'] . "\n";
$message .= "Phone: ". $_POST['phone'] . "\n";
$message .= "Email: ". $_POST['email'] . "\n";

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

$this->email->send();

原因是什么,电子邮件实际上没有传递。


共3个答案

匿名用户

将其更改为以下内容:

$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "blablabla@gmail.com"; 
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$ci->email->initialize($config);

$ci->email->from('blablabla@gmail.com', 'Blabla');
$list = array('xxx@gmail.com');
$ci->email->to($list);
$this->email->reply_to('my-email@gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();

匿名用户

代替

$config['protocol'] = 'smtp';

$config['protocol'] = 'sendmail';

匿名用户

这是我在apache2服务器上的工作,ci 2.1.4:非常简单:首先在你的应用程序/配置目录下创建一个名为email.php的文件,然后在其中键入以下代码~

<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'u'r gmail account';
$config['smtp_pass'] = 'password of u'r account';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
?>

然后创建一个名为email的文件。然后在应用程序/控制器目录下键入以下代码~

    <?php
    class Email extends CI_Controller
    {

    function send()
    {
    // Loads the email library
    $this->load->library('email');
    // FCPATH refers to the CodeIgniter install directory
    // Specifying a file to be attached with the email
    // if u wish attach a file uncomment the script bellow:
    //$file = FCPATH . 'yourfilename.txt';
    // Defines the email details
    $this->email->from('some@of.mailaddress', 'ur Name');
    $this->email->to('email@detiny.your');
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');
    //also this script
    //$this->email->attach($file);
    // The email->send() statement will return a true or false
    // If true, the email will be sent
    if ($this->email->send()) {
    echo "you are luck!";
    } else {
    echo $this->email->print_debugger();
    }
    }

    }
    ?>