Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MrRobot21's avatar

Maximum function nesting level of '100' reached, aborting! (L5.2)

Hi Awesome People

I'm very new to Laravel, i'm trying to send mail from a contact page but i'm getting the following error

FatalErrorException in ClassLoader.php line 347:
Maximum function nesting level of '100' reached, aborting!

And i did gone through the following discussion https://laracasts.com/discuss/channels/general-discussion/l5-maximum-function-nesting-level-of-100-reached-aborting but they all say about something called "Xdebug" and incrementing "Level" which i don't know how to do. "i'm using WAMP for developing" once every thing works i got to deploy the project in godaddy hosting

Let me tell you what i did exactly

I have created a contact page where user fill the form and submit the form "contact.blade.php"

                  <form method="POST" action="contact" id="contact_form" class="contact-form custm-form" 
role="form" enctype="multipart/form-data">
                    {!! csrf_field() !!}
                    <div class="row">
                      <div class="col-md-6">
                        <ul class="row">
                          <li class="col-sm-12">
                            <label>
                              <input type="text" class="form-control" name="name" id="name" placeholder="Your Name" required>
                            </label>
                          </li>
                          <li class="col-sm-12">
                            <label>
                              <input type="email" class="form-control" name="email" id="email" placeholder="E-Mail" required>
                            </label>
                          </li>
                          <li class="col-sm-12">
                            <label>
                              <input type="number" class="form-control" name="phone" id="phone" placeholder="Phone" required>
                            </label>
                          </li>
                          <li class="col-sm-12">
                            <label>
                              <input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" required>
                            </label>
                          </li>
                        </ul>
                      </div>
                      <div class="col-md-6">
                        <ul class="row">
                          <li class="col-sm-12">
                            <label>
                              <textarea class="form-control" name="message" id="message" rows="5" placeholder="Your Message"></textarea>
                            </label>
                          </li>
                          <li class="col-sm-12">
                            <button type="submit" value="submit" class="btn" id="btn_submit">Send Message</button>
                          </li>
                        </ul>
                      </div>
                    </div>
                  </form>

And I created a Controller called "AvoContactController.php"

<?php

namespace App\Http\Controllers;

use View;
Use Mail;
use App\AvoContact;
use App\Http\Requests;
use App\Http\Requests\ContactFormRequest;
use Illuminate\Routing\Controller as BaseController;


class AvoContactController extends BaseController {

    public function contactpage()
    {
        $contact = AvoContact::all();

        return view('pages.contact')->with(['contact' => $contact]);
    }

    public function store(ContactFormRequest $request)
    {
      //this is the part throwing the error  
      Mail::send('emails.contact', [], function ($m) {
            $m
              ->from($request->get('email'))
              ->to(env('CONTACT_MAIL'))
              ->subject('Your Reminder!');
        }); 

        return 'Email Sent';

    }  

}

And I created a Requestes/ContactFormRequest.php and set the "authrization to true"

The In the ".env" file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=2525
MAIL_USERNAME=sanjiarya2112@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null

CONTACT_MAIL=sanjiarya2112@gmail.com

And The Routes

Route::get('contact', 'AvoContactController@contactpage');
Route::post('contact', 'AvoContactController@store');

Every thing seems working fine, but when i fill the form and submit i'm getting that error i'm really stuck i just couldn't figure out what the problem is..

Looking forward for much needed help

Thank You

0 likes
13 replies
petrit's avatar

Issue is caused by default xdebug.max_nesting_level which is 100.

Change you settings to php.ini

xdebug.max_nesting_level = 200

restart your server and the error should not appear anymore

Or, you can add this line to your code

ini_set('xdebug.max_nesting_level', 200);
2 likes
MrRobot21's avatar

@petrit Thanks a lot for your time

i forgot mention i was using wamp but now i'm using "localhost:8000" the laravel server so can you please point me where exactly the "php.ini" is

or

Can You please tell me where to add the code, is it in "AvoContactController.php" or in the "contact.blade.php"

Thank You

petrit's avatar
petrit
Best Answer
Level 20

Add the below line to bootstrap/autoload.php

ini_set('xdebug.max_nesting_level', 120);
define('LARAVEL_START', microtime(true));
2 likes
MrRobot21's avatar

@petrit Thank You very much you are super cool

I'm not getting that error anymore but i'm getting the following

ErrorException in AvoContactController.php line 26:
Undefined variable: request

And The controller is "AvoContactController.php"

<?php

namespace App\Http\Controllers;

use View;
Use Mail;
use App\AvoContact;
use App\Http\Requests;
use App\Http\Requests\ContactFormRequest;
use Illuminate\Routing\Controller as BaseController;


class AvoContactController extends BaseController {

    public function contactpage()
    {
        $contact = AvoContact::all();

        return view('pages.contact')->with(['contact' => $contact]);
    }

    public function store(ContactFormRequest $request)
    {
        Mail::send('emails.contact', [], function ($m) {
            $m
              ->from($request->get('email')) //i'm trying to get the email which user enters
              ->to(env('CONTACT_MAIL'))
              ->subject('Your Reminder!');
        });

        return 'Email Sent';

    }  

}

I think i'm missing something

Thanks for your time i really appreciate it

Thank you

clay's avatar

Pass the $request to your function with the "use" keyword. eg.

Mail::send('emails.contact', [], function ($m) use($request){
            $m
              ->from($request->get('email')) //i'm trying to get the email which user enters
              ->to(env('CONTACT_MAIL'))
              ->subject('Your Reminder!');
        });
1 like
clay's avatar

@petrit He's using a form request object in this case. He's handling that correctly. It'll work either way.

1 like
MrRobot21's avatar

@clay @petrit Thank you very much for your time and help

@clay it's working just fine thank's a lot

And i'm getting the following error

Swift_TransportException in StreamBuffer.php line 269:
Connection could not be established with host smtp.gmail.com [A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
#10060]

Is there any settings to be changed in my gmail account or something

Thank You

clay's avatar

Did you install guzzle? Add this to your dependencies in composer.json

"guzzlehttp/guzzle": "~5.3|~6.0"

Then run composer update

1 like
MrRobot21's avatar

@clay Thank You

i added the guzzle

    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "laravelcollective/html": "5.2.*",
        "guzzlehttp/guzzle": "~5.3|~6.0"

    },

after running composer update,

C:\wamp\www\Laravel\Project>composer update
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Loading composer repositories with package information
Updating dependencies (including require-dev)

from last 15 minutes is stuck there there is no response

what i'm suppose to do is there any way to do this

Thank You

MrRobot21's avatar

@clay Thank God it finally got installed and reloaded the project but after filling and submitting i'm getting the same error

Swift_TransportException in StreamBuffer.php line 269:
Connection could not be established with host smtp.gmail.com [A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
#10060]

Thank You

Please or to participate in this conversation.