简体   繁体   English

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

[英]Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

Iam using codeigniter我正在使用 codeigniter

I exicuted the code on live server.我在实时服务器上执行了代码。 got the following error using print_debugger()使用 print_debugger() 得到以下错误

Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.无法使用 PHP SMTP 发送 email。您的服务器可能未配置为使用此方法发送邮件。

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);
            }

        }

Change smtp_port from 465 to 587.smtp_port从 465 更改为 587。

Make sure $config['newline'] = "\\r\\n";确保$config['newline'] = "\\r\\n"; is in double quotes not single quotes.是双引号而不是单引号。

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

I just added the last line我刚刚添加了最后一行

Just use "mail" for the 'protocol' array item, and that's all...只需将“邮件”用于“协议”数组项,仅此而已...

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

A common cause of this is the way that CodeIgniter interacts with the SMTP server with regards to line breaks.造成这种情况的一个常见原因是 CodeIgniter 与 SMTP 服务器在换行方面的交互方式。 Your SMTP server might require \\r\\n and CodeIgniter is using \\n .您的 SMTP 服务器可能需要\\r\\n而 CodeIgniter 正在使用\\n

There is an easy fix: after your $this->email->initialize() , add the following:有一个简单的解决方法:在您的$this->email->initialize() ,添加以下内容:

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

That should get it working for you.那应该让它为你工作。

It looks like the mail server is hosted by yourself as well, try sending email from any e-mail client.看起来邮件服务器也是由您自己托管的,请尝试从任何电子邮件客户端发送电子邮件。 If it fails - there's a problem with your mailserver config, not the code you pasted - check the server logs.如果失败 - 您的邮件服务器配置有问题,而不是您粘贴的代码 - 检查服务器日志。

I am using much time Run my configure code in localhost but it always gives me an error (Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.)我花了很多时间在localhost 中运行我的配置代码,但它总是给我一个错误(无法使用 PHP SMTP 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。)

But when run this Below code in my server it works for me.但是当在我的服务器中运行下面的代码时,它对我有用。

application>controller>Sendingemail_Controller.php应用程序>控制器>Sendingemail_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
    }
}

and my view page where I defined f_email and email comes through post method.和我定义f_email电子邮件的视图页面来自 post 方法。 application>view>emailtesting.php应用程序>查看>emailtesting.php

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

if some error comes again please visit official documentation below:如果再次出现错误,请访问以下官方文档:

https://codeigniter.com/user_guide/libraries/email.html https://codeigniter.com/user_guide/libraries/email.html

For anyone else who finds this error, has set the settings mentioned elsewhere (even Codeigniter 4) but still getting tht error, one way to test what is going on is from the server console and using telnet.对于发现此错误的其他人,已经设置了其他地方提到的设置(甚至是 Codeigniter 4)但仍然出现错误,测试正在发生的事情的一种方法是从服务器控制台并使用 telnet。 For example:例如:

telnet smtp.yourprovider.com 587

Then test against a different provider and see if that works.然后针对不同的提供者进行测试,看看是否可行。 If your provider doesn't but another does then the problem is with your provider and you should contact them.如果您的提供者没有,但另一个提供者有,那么问题出在您的提供者身上,您应该联系他们。 If both can't connect then you should speak with your webhost.如果两者都无法连接,那么您应该与您的虚拟主机交谈。

I've found another solution.我找到了另一个解决方案。 I had the same problem: (Codeigniter 4 and the issue with php smtp), and the reason was 2-step verification of my gmail account, from which I wanted to send emails in my app.我有同样的问题:(Codeigniter 4 和 php smtp 的问题),原因是我的 gmail 帐户的两步验证,我想从我的应用程序中发送电子邮件。 I fixed it by getting from my gmail account, password for my app.我通过从我的 gmail 帐户获取我的应用程序的密码来修复它。 It works, at last.它终于起作用了。

please i have the same error on codeigniter 4, i need your help :请我在 codeigniter 4 上有同样的错误,我需要你的帮助:

$email = \Config\Services::email();
$config['SMTPHost'] = 'mail.bluemountainsolutions.tech ';
$config['SMTPPort'] = '587';
$config['SMTPUser'] = 'tech@bluemountainsolutions.tech';
$config['SMTPPass'] = '**********;
$config['SMTPCrypto'] = 'tls';
$config['protocol'] = 'mail';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
                
$email->initialize($config);
$email->setNewline("\r\n");
$email->setFrom('tech@bluemountainsolutions.tech', 'BMS admin');
$email->setTo('bluefreesolutions@gmail.com');
$email->setSubject('Validation');
$email->setMessage($message);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Codeigniter 3 无法使用 PHP ZC2239A92BDE29F0A00F9173193CC2FE 发送 email。 您的服务器可能未配置为使用此方法发送邮件 - Codeigniter 3 Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method 无法使用 PHP SMTP 发送电子邮件。 您的服务器可能未配置为使用此方法发送邮件 - Unable to send email using PHP SMTP. Your server might not be configured to send mail using this methods CodeIgniter中的AWS SMTP邮件错误(无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。) - AWS SMTP mail error in CodeIgniter (Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.) 无法发送AUTH LOGIN命令。 错误:无法使用PHP SMTP发送电子邮件。 您的服务器可能未配置为使用此方法发送邮件 - Failed to send AUTH LOGIN command. Error: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method Codeigniter:您的服务器可能未配置为使用此方法发送邮件。 无法使用 PHP SMTP 发送电子邮件 - Codeigniter: Your server might not be configured to send mail using this method. Unable to send email using PHP SMTP SMTP错误:220 smtpauth.net4india.com准备就绪无法使用PHP SMTP发送电子邮件。 您的服务器可能未配置 - SMTP error: 220 smtpauth.net4india.com ready Unable to send email using PHP SMTP. Your server might not be configured 无法使用 PHP mail() 发送电子邮件。 您的服务器可能未配置为使用此方法发送邮件 - Unable to send email using PHP mail(). Your server might not be configured to send mail using this method 遇到错误无法使用 PHP mail() 发送 email。 您的服务器可能未配置为使用此方法发送邮件 - An Error Was Encountered Unable to send email using PHP mail(). Your server might not be configured to send mail using this method 无法使用 PHP Sendmail 发送电子邮件。 您的服务器可能未配置为使用此方法发送邮件 - Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method 无法使用codeigniter发送电子邮件-错误:您的服务器可能未配置为使用此方法发送邮件 - Unable to send email using codeigniter-Error:Your server might not be configured to send mail using this method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM