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

无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件,php,codeigniter,email,Php,Codeigniter,Email,Iam使用codeigniter 我退出了live server上的代码。 使用print_debugger()时出现以下错误 无法使用PHP SMTP发送电子邮件。您的服务器可能不可用 配置为使用此方法发送邮件 将smtp_端口从465更改为587 确保$config['newline']=“\r\n”是双引号而不是单引号。邮件服务器似乎也是由您自己托管的,请尝试从任何电子邮件客户端发送电子邮件。如果失败-mailserver配置有问题,而不是粘贴的代码有问题-请检查服务器日志。常见原因是Co

Iam使用codeigniter

我退出了live server上的代码。 使用print_debugger()时出现以下错误

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


将smtp_端口从465更改为587


确保
$config['newline']=“\r\n”
是双引号而不是单引号。

邮件服务器似乎也是由您自己托管的,请尝试从任何电子邮件客户端发送电子邮件。如果失败-mailserver配置有问题,而不是粘贴的代码有问题-请检查服务器日志。

常见原因是CodeIgniter与SMTP服务器就换行进行交互。您的SMTP服务器可能需要
\r\n
,而CodeIgniter正在使用
\n

有一个简单的解决方法:在
$this->email->initialize()之后添加以下内容:

$this->email->set_newline("\r\n");  
这应该会让它为你工作

$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");
我刚刚添加了最后一行

仅使用“邮件”作为“协议”数组项,就这样

$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;

我在localhost中运行配置代码花费了很多时间,但它总是给我一个错误(无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。)

但是,当在我的服务器中运行下面的代码时,它对我有效

应用程序>控制器>发送电子邮件\u controller.php

public function send_mail() {
    $this->load->library('email');   
    $config = array();
    $config['protocol']     = "smtp"; // you can use 'mail' instead of 'sendmail or smtp'
    $config['smtp_host']    = "ssl://smtp.googlemail.com";// you can use 'smtp.googlemail.com' or 'smtp.gmail.com' instead of 'ssl://smtp.googlemail.com'
    $config['smtp_user']    = "my@gmail.com"; // client email gmail id
    $config['smtp_pass']    = "******"; // client password
    $config['smtp_port']    =  465;
    $config['smtp_crypto']  = 'ssl';
    $config['smtp_timeout'] = "";
    $config['mailtype']     = "html";
    $config['charset']      = "iso-8859-1";
    $config['newline']      = "\r\n";
    $config['wordwrap']     = TRUE;
    $config['validate']     = FALSE;
    $this->load->library('email', $config); // intializing email library, whitch is defiend in system

    $this->email->set_newline("\r\n"); // comuplsory line attechment because codeIgniter interacts with the SMTP server with regards to line break

    $from_email = $this->input->post('f_email'); // sender email, coming from my view page 
    $to_email = $this->input->post('email'); // reciever email, coming from my view page
    //Load email library

    $this->email->from($from_email);
    $this->email->to($to_email);
    $this->email->subject('Send Email Codeigniter'); 
    $this->email->message('The email send using codeigniter library');  // we can use html tag also beacause use $config['mailtype'] = 'HTML'
    //Send mail
    if($this->email->send()){
        $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
        echo "email_sent";
    }
    else{
        echo "email_not_sent";
        echo $this->email->print_debugger();  // If any error come, its run
    }
}
<html>
<head>    
    <title> Send Email Codeigniter </title>
</head>
<body>
<?php
echo $this->session->flashdata('email_sent');
echo form_open('/Sendingemail_Controller/send_mail');
?>
<input type = "email" name = "f_email" placeholder="sender email id (from)"  required />
<input type = "email" name = "email"  placeholder="reciever email id (to)" required />
<input type = "submit" value = "SEND MAIL">
<?php
echo form_close();
?>
</body>
在我的查看页面中,我定义了f_emailemail,这是通过post方法实现的。 应用程序>视图>emailtesting.php

public function send_mail() {
    $this->load->library('email');   
    $config = array();
    $config['protocol']     = "smtp"; // you can use 'mail' instead of 'sendmail or smtp'
    $config['smtp_host']    = "ssl://smtp.googlemail.com";// you can use 'smtp.googlemail.com' or 'smtp.gmail.com' instead of 'ssl://smtp.googlemail.com'
    $config['smtp_user']    = "my@gmail.com"; // client email gmail id
    $config['smtp_pass']    = "******"; // client password
    $config['smtp_port']    =  465;
    $config['smtp_crypto']  = 'ssl';
    $config['smtp_timeout'] = "";
    $config['mailtype']     = "html";
    $config['charset']      = "iso-8859-1";
    $config['newline']      = "\r\n";
    $config['wordwrap']     = TRUE;
    $config['validate']     = FALSE;
    $this->load->library('email', $config); // intializing email library, whitch is defiend in system

    $this->email->set_newline("\r\n"); // comuplsory line attechment because codeIgniter interacts with the SMTP server with regards to line break

    $from_email = $this->input->post('f_email'); // sender email, coming from my view page 
    $to_email = $this->input->post('email'); // reciever email, coming from my view page
    //Load email library

    $this->email->from($from_email);
    $this->email->to($to_email);
    $this->email->subject('Send Email Codeigniter'); 
    $this->email->message('The email send using codeigniter library');  // we can use html tag also beacause use $config['mailtype'] = 'HTML'
    //Send mail
    if($this->email->send()){
        $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
        echo "email_sent";
    }
    else{
        echo "email_not_sent";
        echo $this->email->print_debugger();  // If any error come, its run
    }
}
<html>
<head>    
    <title> Send Email Codeigniter </title>
</head>
<body>
<?php
echo $this->session->flashdata('email_sent');
echo form_open('/Sendingemail_Controller/send_mail');
?>
<input type = "email" name = "f_email" placeholder="sender email id (from)"  required />
<input type = "email" name = "email"  placeholder="reciever email id (to)" required />
<input type = "submit" value = "SEND MAIL">
<?php
echo form_close();
?>
</body>

发送电子邮件代码点火器
如果再次出现错误,请访问以下官方文档:


或据我所知,主机不应在其中包含协议(例如,
ssl://
)。我删除了ssl://但发生了smae错误@apokryfosi读取了所有链接,但没有发生错误@AlivetoDieIs此实时服务器是Linux服务器吗?如果是,您是否在live server上安装了mailutils?谢谢!真奇怪。。。为什么465端口不能在codeigniter上工作?o、 o,我总是使用Swift-4.*php发送电子邮件,使用465端口没有任何问题……对我来说,将$config['newline']=“\r\n”更改为$config['newline']=“\r”仍然有效。在这之前是“\r\n”,但这会导致电子邮件主题显示一些奇怪的编码内容。实际上,我发现,通过将其更改为mail,电子邮件是从服务器邮件本身发送的。所以这不起作用。您可以查看收到的电子邮件的发件人详细信息。