简体   繁体   中英

Error while sending email in codeigniter with Wamp

I am trying to send email from my gmail id to another email id from codeigniter using WAMP localhost.

I am getting the following error

hello: F

The following SMTP error was encountered: F

Unable to send email using PHP SMTP.

Your server might not be configured to send mail using this method.

This is the email sending code in my controller function

        $config['useragent']    = 'CodeIgniter';
        $config['protocol']     = 'smtp';
        $config['smtp_host']    = 'smtp.gmail.com';
        $config['smtp_user']    = 'myemail@gmail.com'; // Your gmail id
        $config['smtp_pass']    = '****'; // Your gmail Password
        $config['smtp_port']    = 465;
     //   $config['mailpath'] = 'D:\wamp64\sendmail';
       // $config['smtp_timeout']='30';
        $config['wordwrap']     = TRUE;
        $config['wrapchars']    = 76;
        $config['mailtype']     = 'html';
        $config['charset']      = 'iso-8859-1';
        $config['validate']     = FALSE;
        $config['priority']     = 3;
        $config['newline']      = "\r\n";
        $config['crlf']         = "\r\n";
      //  $config['smtp_crypto']      = 'ssl';

        $this->load->library('email');
        $this->email->initialize($config);

        $this->email->from('myemail@gmail.com', 'Sana Riaz');
        $this->email->to('myemail@gmail.com');

        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');

        //$this->email->send();

        if($this->email->send()){
            echo "sent";

        }else
            show_error($this->email->print_debugger());

these are the settings i did in php.ini file which were suggested in old posts.

extension=php_openssl.dll

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo ="D:\wamp64\bin\mariadb\mariadb10.2.8\mysql-test\std_data\cacert.pem"

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile="D:\wamp64\bin\mariadb\mariadb10.2.8\mysql-test\std_data\cacert.pem"


[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from ="myemail@gmail.com"

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

These are the other things i tried that also didnt work

  1. using sendmail and mail instead of $config['protocol'] = 'smtp'; which produced following error respectively

    (mail)

    Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

    (sendmail)

    Exit status code: 1 Unable to open a socket to Sendmail. Please check settings. Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.

  2. changing port 465 to 25 and 587 which produce the following error

    220 smtp.gmail.com ESMTP v78sm12109697wmv.27 - gsmtp

  3. Adding $config['smtp_crypto'] = 'ssl'; which produces the following error

    fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

  4. Disabling firewall, antivrus etc

  5. Enabling IMAP and POP from Gmail account

I have no idea what am i doing wrong or what am i missing. Any suggestions would be extremly helpful

These are the some previous posts that i came across and tried but didnt work

Sending mail localy like from localhost requires a mail server, such as Fake SendMail .

Since Google Mail has changed its SSL security and removed support for v2 which is used by Sendmail.exe, those who will be configuring their GMail account will need to configured the Stunnel as well.

What you'll need:

  • WAMP Server 64Bits
  • Fake Sendmail for Windows
  • An email account with any email providers, I'm using GMail account.
  • Stunnel (if Fake Sendmail itselft doesn't work)

sendmail.ini settings would be done as following:

smtp_server=smtp.gmail.com # if gmail, if configured with stunnel use localhost
smtp_port=465 # if gmail, if configured with stunnel use 25
smtp_ssl=auto # if gmail, if configured with stunnel use none
auth_username=youremail@gmail.com
auth_password=yourpassword

for Stunnel configuration and further information, see CONFIGURE SENDMAIL WITH WAMP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM