首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件

无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件
EN

Stack Overflow用户
提问于 2017-07-22 16:45:41
回答 7查看 78.2K关注 0票数 10

Iam使用codeigniter

我在实时服务器上激活了代码。使用print_debugger()时出现以下错误

无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。

代码语言:javascript
复制
public function sendEnquiry() {
            $this->load->library('email');
            $name = $this->input->post("fname");
            $cemail = $this->input->post("email");
            $pno = $this->input->post("phone");
            $message = $this->input->post("message");
            $config['protocol']    = 'smtp';
            $config['smtp_host']    = 'ssl://mail.gatewaykhobar.com';
            $config['smtp_port']    = '465';
            $config['smtp_timeout'] = '7';
            $config['smtp_user']    = '***********';
            $config['smtp_pass']    = '***********';
            $config['charset']    = 'utf-8';
            $config['newline']    = "\r\n";
            $config['mailtype'] = 'text'; // or html
            $config['validation'] = FALSE;

            $this->email->initialize($config);
            $this->email->from('info@gatewaykhobar.com','Gateway Restaurent Contact');
            $this->email->to($cemail); 
            $this->email->subject('Gateway Restaurent Contact Enquiry');

           $this->email->message($message);  
            $send = $this->email->send();
            if($send) {
                echo json_encode("send");
            } else {
                $error = $this->email->print_debugger(array('headers'));
                echo json_encode($error);
            }

        }
EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2017-08-14 23:13:01

smtp_port从465更改为587。

确保$config['newline'] = "\r\n";在双引号中,而不是单引号中。

票数 21
EN

Stack Overflow用户

发布于 2019-01-24 05:43:58

代码语言:javascript
复制
$mail_config['smtp_host'] = 'smtp.gmail.com';
$mail_config['smtp_port'] = '587';
$mail_config['smtp_user'] = 'user@example.com';
$mail_config['_smtp_auth'] = TRUE;
$mail_config['smtp_pass'] = 'password';
$mail_config['smtp_crypto'] = 'tls';
$mail_config['protocol'] = 'smtp';
$mail_config['mailtype'] = 'html';
$mail_config['send_multipart'] = FALSE;
$mail_config['charset'] = 'utf-8';
$mail_config['wordwrap'] = TRUE;
$this->email->initialize($mail_config);

$this->email->set_newline("\r\n");

我刚加了最后一行

票数 9
EN

Stack Overflow用户

发布于 2019-07-03 13:50:35

只需为'protocol‘数组项使用"mail“,就行了……

代码语言:javascript
复制
$config = array();
        $config['useragent']    = $system_name;
        $config['mailpath']     = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
        $config['protocol']     = "mail"; //use 'mail' instead of 'sendmail or smtp'
        $config['smtp_host']    = "your domain name";
        $config['smtp_user']    =  $from;
        $config['smtp_pass']    = "*************";
        $config['smtp_port']    =  465;
        $config['smtp_crypto']  = 'ssl';
        $config['smtp_timeout'] = "";
        $config['mailtype']     = "html";
        $config['charset']      = "utf-8";
        $config['newline']      = "\r\n";
        $config['wordwrap']     = TRUE;
        $config['validate']     = FALSE;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45252547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档