无法使用codeigniter从localhost发送电子邮件(空白页)

时间:2023-01-07 18:16:06

I'm about new at sending email using CodeIgniter. I have searched any tutorial and forum to handle send email using CodeIgniter, but none of them works for me. Hope someone can help.

我是关于使用CodeIgniter发送电子邮件的新手。我搜索过任何教程和论坛来处理使用CodeIgniter发送电子邮件,但它们都不适合我。希望有人能提供帮助。

This is the controller I use:

这是我使用的控制器:

function send_email() {
        $config = array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'xxxx@gmail.com',
            'smtp_pass' => '****',
            'mailtype' => 'text',
            'charset' => 'iso-8859-1',
            'wordwrap' => TRUE
        );

        $message = '';
        $this->load->library('email');
        $this->email->initialize($config);
        $this->email->set_newline("\r\n");
        $this->email->from('xxxx@gmail.com');
        $this->email->to('xxxx@gmail.com');
        $this->email->subjects('Email Testing');
        $this->email->message($message);

        if($this->email->send()) {
            echo 'Email sent!';
        } else {
            show_error($this->email->print_debugger());
        }
    }

I have edited php.ini as forum said, such as:

我已经编辑了php.ini作为论坛说,如:

;For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail

; ... or under UNIX:
;
;   extension=msql.so
extension=php_openssl.dll

I work Apache/2.2.22 (Ubuntu) Server.

我使用Apache / 2.2.22(Ubuntu)服务器。

And it shows blank page when I try to call the function. Is there any config to edit? Please give your suggestion. Thank you.

当我尝试调用该函数时它显示空白页面。有编辑的配置吗?请给出你的建议。谢谢。

Updated:

This is the display_errors and error_reporting I edited in php.ini :

这是我在php.ini中编辑的display_errors和error_reporting:

; display_errors
   Default Value: On
   Development Value: On
   Production Value: On

; error_reporting
   Default Value: E_ALL & ~E_NOTICE
   Development Value: E_ALL | E_STRICT
   Production Value: E_ALL & ~E_DEPRECATED

2 个解决方案

#1


0  

try this in codeigniter!!

在codeigniter尝试这个!!

public function sendEmail($email,$subject,$message)
    {
   $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'xyz@gmail.com', 
  'smtp_pass' => 'password', 
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);


      $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('xyz@gmail.com');
      $this->email->to($email);
      $this->email->subject($subject);
      $this->email->message($message);
      if($this->email->send())
     {
      echo 'Email send.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }

}

public function send_email() 
    {
    $email="abc@gmail.com";
    $subject="Your subject";
    $message="You can write html tags in this message";
    $this->sendEmail($email,$subject,$message);
    }

#2


0  

use PHPMailer its easy

使用PHPMailer很容易

$this->load->library('PHPMailer/PHPMailer');
    $mail=new PHPMailer(); //creat PHPMailer object
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPAuth = true; //needs login information
    $mail->SMTPSecure = "tls"; //specifies tls security
    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port = 587; //gmail smtp port

    $dd3=$this->db->query("select * from email where eid=1")->row_array();;
    /******************* Set Your Credentials********************/
    $mail->Username = 'xxxx'; //SMTP gmail address
    $mail->Password = 'xxx'; // SMTP account password
    $mail->From = 'xxx'; //sender's gmail address


    $mail->FromName = "from";
    $mail->AddAddress("to");//receiver's e-mail address
    $mail->Subject = $subject;//e-mail subject
    $mail->Body ="message";//e-mail message



    $mail->WordWrap = 50;
    if(!$mail->Send())
    {
      $status='Message was not sent.';

    }
    else
    {
      $status='Message has been sent.';
     //  echo $status;
    }

#1


0  

try this in codeigniter!!

在codeigniter尝试这个!!

public function sendEmail($email,$subject,$message)
    {
   $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'xyz@gmail.com', 
  'smtp_pass' => 'password', 
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);


      $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('xyz@gmail.com');
      $this->email->to($email);
      $this->email->subject($subject);
      $this->email->message($message);
      if($this->email->send())
     {
      echo 'Email send.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }

}

public function send_email() 
    {
    $email="abc@gmail.com";
    $subject="Your subject";
    $message="You can write html tags in this message";
    $this->sendEmail($email,$subject,$message);
    }

#2


0  

use PHPMailer its easy

使用PHPMailer很容易

$this->load->library('PHPMailer/PHPMailer');
    $mail=new PHPMailer(); //creat PHPMailer object
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPAuth = true; //needs login information
    $mail->SMTPSecure = "tls"; //specifies tls security
    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port = 587; //gmail smtp port

    $dd3=$this->db->query("select * from email where eid=1")->row_array();;
    /******************* Set Your Credentials********************/
    $mail->Username = 'xxxx'; //SMTP gmail address
    $mail->Password = 'xxx'; // SMTP account password
    $mail->From = 'xxx'; //sender's gmail address


    $mail->FromName = "from";
    $mail->AddAddress("to");//receiver's e-mail address
    $mail->Subject = $subject;//e-mail subject
    $mail->Body ="message";//e-mail message



    $mail->WordWrap = 50;
    if(!$mail->Send())
    {
      $status='Message was not sent.';

    }
    else
    {
      $status='Message has been sent.';
     //  echo $status;
    }