CodeIgniter unable to send email using PHP mail()

前端 未结 12 2112
孤街浪徒
孤街浪徒 2020-11-29 06:27

I\'m trying to send an e-mail with Codeigniter like this:

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

$this->email->from(\"myemail@email.com\");
$this->         


        
相关标签:
12条回答
  • 2020-11-29 06:40

    Had the same problem, Make sure your 'from' address is a valid email address.

    0 讨论(0)
  • 2020-11-29 06:40

    Its worth saying that if you're on WAMP (Windows) you will need to have sendmail installed otherwise there is no default SMTP method of sending. I wanted to use Gmail but couldn't because there is simply no default mail mechanism.

    0 讨论(0)
  • 2020-11-29 06:43

    Be sure domain name in

    $this->email->from("myemail@**email.com**");
    

    match to server domain name

    0 讨论(0)
  • 2020-11-29 06:43

    Add a protocol variable to the config array and assign it the value "sendmail". The email.php file in the config folder should read as shown below. Mine works like this:

    $config['protocol'] = 'sendmail';
    $config['mailtype'] = 'html';
    $config['charset']  = 'utf-8';
    $config['newline']  = "\r\n";
    
    0 讨论(0)
  • 2020-11-29 06:43

    Ensure that Apache can send emails.

    To check your current sendmail status: sestatus -b | grep httpd_can_sendmail

    Change it to this if it is off: sudo setsebool -P httpd_can_sendmail on

    0 讨论(0)
  • 2020-11-29 06:48

    I had the same problem and though it seems silly to me now, I had some of the config array options capitalized when they all need to be lowercase:

    was:

    $mail_config['smtp_host'] = 'mail.example.com';
    $mail_config['smtp_port'] = '587';
    $mail_config['smtp_user'] = 'email@example.com';
    $mail_config['smtp_pass'] = 'password';
    $mail_config['smtp_crypto'] = 'TLS'; //ERROR
    $mail_config['protocol'] = 'SMTP'; //ERROR
    $mail_config['mailtype'] = 'HTML'; //ERROR
    $mail_config['send_multipart'] = FALSE;
    $this->email->initialize($mail_config);
    

    Fixed:

    $mail_config['smtp_host'] = 'mail.example.com';
    $mail_config['smtp_port'] = '587';
    $mail_config['smtp_user'] = 'email@example.com';
    $mail_config['smtp_pass'] = 'password';
    $mail_config['smtp_crypto'] = 'tls'; //FIXED
    $mail_config['protocol'] = 'smtp'; //FIXED
    $mail_config['mailtype'] = 'html'; //FIXED
    $mail_config['send_multipart'] = FALSE;
    $this->email->initialize($mail_config);
    

    That worked for me

    0 讨论(0)
提交回复
热议问题