Here's a guide on sending emails from your local server using CodeIgniter and connecting to Gmail

Greetings everyone, I am currently engrossed in developing a CodeIgniter application that empowers users to create their own accounts and more.

I am currently working on implementing a function for password recovery in case it is lost or forgotten. Check out my code snippet below:

    public function admin_recover(){

        $this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[7]|valid_email');

        if($this->form_validation->run() == FALSE){
        //Load View Into Template

        $this->template->load('admin', 'login', 'users/recover');

    } else {
        //Get Post Data
        $email = $this->input->post('email');
        $password = $this->input->post('password');

        $user_email = $this->User_model->get_list();

        if($user_email){
            $user_email_data = array(
                'email' => true
            );
        ///////// Sending email
        // Configure email library

        $config['wordwrap'] = FALSE;
        $config['mailtype'] = 'html';
        $config['crlf'] = '\r\n';
        $config['charset']='utf-8';
        $config['newline']="\r\n";
        $config['priority']=1;
        $config['protocol']='smtp';
        $config['smtp_host']='ssl://smtp.gmail.com';
        $config['smtp_port']='25';
        $config['smtp_timeout']='30';
        $config['smtp_user']='example@gmail.com';
        $config['smtp_pass']='mypassword';
        $config['newline']="\r\n";


        $this->load->library('email',$config);
        $this->email->set_newline("\r\n");

        $this->email->from('sender@example.com', 'Social Geek');
        $this->email->to('recipient@example.com');       
        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');
        $this->email->send();


        if($this->email->send()) 
        $this->session->set_flashdata("success","Email sent successfully."); 
        else 
        $this->session->set_flashdata("error","Error in sending Email.");

        echo $this->email->print_debugger();
        //////////////      
        }   
    }
}

I am utilizing gmail SMTP service to send emails from localhost, but facing challenges in getting it to work properly. Any suggestions on how to resolve this issue?

I have already made some modifications (using xampp) in the ini file located at xampp/PHP/php.ini

Upon visiting the view, I encounter the following error:

https://i.stack.imgur.com/fp7pO.png

Your assistance and guidance are greatly appreciated. Thank you.

Answer №1

If you want to test these setup parameters listed below, please give it a try and inform me about the outcome.

$configuration = array(
    'connectivity' => 'smtp',
    'host_address' => 'ssl://smtp.gmail.com',
    'port_number' => 465,
    'user_email' => '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5a0a6b0a795b2b8b4bcb9fbb6bab8">[email protected]</a>',
    'user_password' => 'yourpassword',
    'mail_format' => 'html',
    'character_set' => 'iso-8859-1'
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Accessing content from a text file and showcasing a designated line

Apologies if my wording was unclear... In this scenario, we will refer to the text file as example.txt. The value in question will be labeled as "Apple" My goal is to retrieve example.txt, search for Apple within it, and display the entire line where thi ...

Creating a PHP loop to identify the initial row of a result obtained from a MySQL query

I am trying to set a background color for the first row of each 'Dist' value in a MySQL data report that gets displayed as HTML. However, I am facing difficulty in determining which row is coming from MySQL. NO CALL First St, CO Di ...

json success function not being triggered

I am facing an issue with executing the success function in my code while trying to post the value of an input box and retrieve the value of a checked radio button. The objective is to perform a query based on which radio button is checked. Here is the HT ...

What is the solution for the issue of encountering an undefined key array email while attempting to log in through the form?

I encountered an issue while working on a login form that communicates with the database using PHP at the backend. Even though I have verified the correctness of my login credentials, I am facing an error related to undefined array keys 'email and pas ...

Issue with Ajax communication to PHP script causing data not to be sent

I am developing a web application that functions as an extensive form which will later be converted into a PDF document. Upon submission of the form, all input data is sent to a PHP file where they are stored as variables to be included in the PDF. Some of ...

Unravel the JSON data array and seamlessly add it to a MySQL database

Looking for some help here as I am struggling with extracting Json data and inserting it into a MySQL database using PHP. Any assistance would be greatly appreciated. {"CityInfo":[{"CityCode":"5599","Name":"DRUSKININKAI"},{"CityCode":"2003","Name":"KAUNAS ...

Can someone assist me with navigating through my SQL database?

Struggling with a script that searches multiple fields in the same table, I need it to return results even if one or three parameters are left blank. My attempts using PHP and MySql have been fruitless so far, which is why I am reaching out to the experts ...

WordPress CSS Styling Issue: HTML Element Display Problem

I recently converted my static HTML site to WordPress, but I'm facing an issue where the site is always aligned to the left. Despite trying different solutions like the one below: body{ margin: auto; } The original HTML page was centered perfectly ...

Query regarding conversion of JSON objects

I am having an issue with converting JSON to object and then from object to array. The result is not what I expected. Can someone help me understand why? $json = '{"0" : "a"}'; $obj = json_decode($json); $a = (array) $obj; print_r($a); echo("a0: ...

Announcing the outcomes I received from JSON notifications

Hey there, I need some assistance. Here's the deal - whenever a user enters something into a text field and then clicks out of it, an ajax request is triggered. $(document).ready(function() { //On Focus lose get content of the first input field $(&ap ...

tips on extracting php date format from a provided string

I need help with getting the date format of a given string that contains a valid date. Currently, I am trying to import data from a CSV file which serves as a backup. However, the CSV files have various different types of date formats. When I attempt to co ...

Guide on obtaining JSON data in an android application through a PHP file?

I am a beginner in Android development and I have recently created a simple data fetching application. However, I am facing an issue where I am only able to retrieve the value of one variable from my PHP file, even though both variables are present in the ...

Tips for presenting JSON date in JavaScript using Google Chart

I am in urgent need of assistance with this issue. I am trying to display the date from PHP JSON data retrieved from my database in a Google Chart using JavaScript. Below is the PHP code snippet: $data_points = array(); while($row = mysqli_fetch_array($r ...

Monitor changes in the select tag to display the updated value and output

I am new to using jQuery. While I have practiced using native PHP Ajax in the past, I now recognize the need to learn jQuery due to current technological advancements and demands. When the select tag changes, I send the "types" value via POST method to a ...

Unexpected response from ajax request

I am struggling to properly handle error messages in my jQuery ajax code. When the fetch array result from my ajax page contains data, I want to display an error message; however, when the array result is empty, I want nothing to happen. Unfortunately, my ...

PHP - Issue with JSON formatting when removing a value

Whenever a user clicks on a button, the videoId of the clicked video gets added to an array. If the same button is clicked again, the code checks if the videoId is already in the array and removes it if found. The array is then saved to a JSON file in th ...

Is the input box failing to show up on your screen?

I recently tackled the task of creating a commenting feature for RSS articles Throughout my journey with PHP coding, I encountered an issue where the input box for comments was not displaying. https://i.stack.imgur.com/gJIlu.png Check out the snippet fr ...

PHP Quick Tip: How to effortlessly update a JSON array with new data

{ "messages": [ { "sender": "x", "message": "Placeholder", "date": "May 8, 2016 11:47:45 PM" } { "sender": "y", "mess ...

PHP Ajax Image Uploading and Storage

Is there a way to effortlessly upload an image and save it in the uploads folder without any page refresh? Not only that, but can we also have the uploaded image displayed on the screen within a designated div section? Unfortunately, I seem to encounter a ...

Avoid Refreshing Form in Codeigniter

In order to avoid receiving the 'confirm form resubmission' warning, it is commonly advised to use GET method. However, in Codeigniter, the preferred method is often POST due to compatibility issues with form helper functions and other features. ...