2

I am trying to setup a laravel website and i have been able to get a few things to work but i then experienced this error.

mail() has been disabled for security reasons

I have tried contacting my hosting providers to assist in activating that function, but they blew me off saying they cannot activate that and i should try modifying the header of the mailer so it does not require that.

Please how would I be able to do that as I am not an expert when it comes to mail php.

This is my error below:

ErrorException thrown with message "mail() has been disabled for security reasons"

Stacktrace:
#57 ErrorException in /home/zcashcom/public_html/invest/core/app/Http/helpers/helpers.php:19
#56 mail in /home/zcashcom/public_html/invest/core/app/Http/helpers/helpers.php:19

This is the full code of the file, helpers.php in question

<?php

use App\General;
use App\User;
use App\MemberExtra;

function send_email($to, $subject, $name, $message){
        $general = General::first();
        
    if ($general->email_nfy == 1){
         $headers = "From: ".$general->web_title." <".$general->esender."> \r\n";
        $headers .= "Reply-To: ".$general->web_title." <".$general->esender."> \r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        
        $template = $general->emessage;
        $mm = str_replace("{{name}}",$name,$template);
        $message = str_replace("{{message}}",$message,$mm);
         mail($to, $subject, $message, $headers);
        }else {
        return;
    }
}

function send_sms( $to, $message){
    $gnl = General::first();
    if($gnl->sms_nfy == 1) {
        $sendtext = urlencode("$message");
        $appi = $gnl->smsapi;
        $appi = str_replace("{{number}}",$to,$appi);
        $appi = str_replace("{{message}}",$sendtext,$appi);
        $result = file_get_contents($appi);
      }
      return;
}



function updateDepositBV($id, $deposit_amount)
{
    while($id !="" || $id != "0") {
        if(isMemberExists($id))
        {
            $posid = getParentId($id);
            if($posid == "0")
                break;
            $position = getPositionParent($id);
            $currentBV = MemberExtra::where('user_id', $posid)->first();

            if($position == "L"){
                $new_lbv = $currentBV->left_bv + $deposit_amount ;
                $new_rbv = $currentBV->right_bv;
            }else{
                $new_lbv = $currentBV->left_bv;
                $new_rbv = $currentBV->right_bv + $deposit_amount ;
            }

            MemberExtra::where('user_id', $posid)
                ->update([
                   'left_bv' => $new_lbv,
                   'right_bv' => $new_rbv,
                ]);

            $id = $posid;

        } else {
            break;
        }

    }//while
    return 0;
}



function updatePaid($id){
    while($id!=""||$id!="0"){
        if(isMemberExists($id)) {
            $posid=getParentId($id);
            if($posid  == "0")
                break;
            $position = getPositionParent($id);

            $currentCount = MemberExtra::where('user_id',$posid )->first();

            $new_lpaid = $currentCount->left_paid;
            $new_rpaid = $currentCount->right_paid;
            $new_lfree = $currentCount->left_free;
            $new_rfree = $currentCount->right_free;

            if($position == "L") {
                $new_lfree = $new_lfree-1;
                $new_lpaid = $new_lpaid+1;
            }else {
                $new_rfree = $new_rfree-1;
                $new_rpaid = $new_rpaid+1;
            }

            MemberExtra::where('user_id', $posid)
                ->update([
                   'left_paid' => $new_lpaid,
                   'right_paid' => $new_rpaid,
                   'left_free' => $new_lfree,
                   'right_free' => $new_rfree,
                ]);
            $id =$posid;

        } else {
            break;
        }
    }
    return 0;
}






function treeeee($id ='', $uid=''){

    while($id!=""||$id!="0") {
        if(isMemberExists($id)){
            $posid=getParentId($id);
            if($posid=="0")
                break;
            if($posid==$uid){
                return true;
            }
            $id =$posid;
        } else {
            break;
        }
    }//while
    return 0;
}

function printBV($id){
    $cbv = MemberExtra::where('user_id', $id)->first();
    $rid = User::whereId($id)->first();
    $rnm = User::where('id', $rid->referrer_id)->first();
    echo "<b>Referred By:</b> $rnm->username <br>";
    echo "<b>Current BV:</b> L-$cbv->left_bv | R-$cbv->right_bv <br>";
}

function printBelowMember($id){
    $bmbr = MemberExtra::where('user_id', $id)->first() ;
    echo "<b>Paid Member Below:</b> L-$bmbr->left_paid | R-$bmbr->right_paid <br>";
    echo "<b>Free Member Below:</b> L-$bmbr->left_free | R-$bmbr->right_free <br>";
}

function updateMemberBelow($id='', $type=''){
    while($id!=""||$id!="0") {
        if(isMemberExists($id)) {
            $posid=getParentId($id);
            if($posid=="0")
                break;
            $position=getPositionParent($id);
            $currentCount = MemberExtra::where('user_id', $posid)->first() ;

            $new_lpaid = $currentCount->left_paid;
            $new_rpaid = $currentCount->right_paid;
            $new_lfree = $currentCount->left_free;
            $new_rfree = $currentCount->right_free;

            if($position=="L") {
                if($type=='FREE'){
                    $new_lfree = $new_lfree + 1;
                }else{
                    $new_lpaid = $new_lpaid+1;
                }
            }else {
                if($type=='FREE'){
                    $new_rfree = $new_rfree + 1;
                }else{
                    $new_rpaid = $new_rpaid+1;
                }
            }
            MemberExtra::where('user_id', $posid)
                ->update([
                   'left_paid' => $new_lpaid,
                   'right_paid' => $new_rpaid,
                   'left_free' => $new_lfree,
                   'right_free' => $new_rfree,
                ]);
            $id =$posid;
        } else{
            break;
        }
    }
    return 0;
}

function getParentId($id){

    $count = User::whereId($id)->count() ;
    $posid = User::whereId($id)->first();
    if ($count == 1){
        return $posid->posid;
    }else{
        return 0;
    }
}


function getPositionParent($id){

    $count = User::whereId($id)->count();
    $position = User::whereId($id)->first() ;
    if ($count == 1){
        return $position->position;
    }else{
        return 0;
    }
}


function getLastChildOfLR($parentid ,$position){

    $childid = getTreeChildId($parentid, $position);

    if($childid!="-1"){
        $id = $childid;
    } else {
        $id = $parentid;
    }
    while($id!=""||$id!="0") {
        if(isMemberExists($id)) {
            $nextchildid = getTreeChildId($id, $position);
            if($nextchildid == "-1"){
                break;
            }else{
                $id = $nextchildid;
            }
        }else break;
    }
    return $id;
}
function getTreeChildId($parentid ,$position){
    $cou = User::where('posid', $parentid)->where('position', $position)->count();
    $cid = User::where('posid', $parentid)->where('position', $position)->first();
    if ($cou == 1){
        return $cid->id;
    }else{
        return -1;
    }
}

function isMemberExists($id){
    $count = User::where('id', $id)->count();
    if ($count == 1){
        return true;
    }else{
        return false;
    }
}

function Short_Text($data,$length){
    $first_part = explode(" ",$data);
    $main_part = strip_tags(implode(' ',array_splice($first_part,0, $length)));
    return $main_part ."...." ;
}

function ImageCheck($ext){
    if($ext != 'jpg' && $ext != 'jpeg' && $ext != 'png' && $ext != 'bnp'){
        $ext = "";
    }
    return $ext;
}

function NewFile($name, $data){
    $fh = fopen($name, "w");
    fwrite($fh,$data);
    fclose($fh);
}

function ViewFile($name){
    $fh = fopen($name, "r");
    $data = fread($fh,filesize($name));
    fclose($fh);
    return $data;
}

function Find_fist_int($string){
    preg_match_all('!\d+!', $string, $matches);
    if($matches[0] != ""){
        foreach($matches[0] as $key => $value){
            $url = $value;
            return $url;
            break;
        }
    }
}

function Replace($data) {
    $data = str_replace("'", "", $data);
    $data = str_replace("!", "", $data);
    $data = str_replace("@", "", $data);
    $data = str_replace("#", "", $data);
    $data = str_replace("$", "", $data);
    $data = str_replace("%", "", $data);
    $data = str_replace("^", "", $data);
    $data = str_replace("&", "", $data);
    $data = str_replace("*", "", $data);
    $data = str_replace("(", "", $data);
    $data = str_replace(")", "", $data);
    $data = str_replace("+", "", $data);
    $data = str_replace("=", "", $data);
    $data = str_replace(",", "", $data);
    $data = str_replace(":", "", $data);
    $data = str_replace(";", "", $data);
    $data = str_replace("|", "", $data);
    $data = str_replace("'", "", $data);
    $data = str_replace('"', "", $data);
    $data = str_replace("?", "", $data);
    $data = str_replace("  ", "_", $data);
    $data = str_replace("'", "", $data);
    $data = str_replace(".", "-", $data);
    $data = strtolower(str_replace("  ", "-", $data));
    $data = strtolower(str_replace(" ", "-", $data));
    $data = strtolower(str_replace(" ", "-", $data));
    $data = strtolower(str_replace("__", "-", $data));
    return str_replace("_", "-", $data);
}

**Edited as regards the first response

I realized that the error is also calling a couple of other files

RegisterController.php: 104 & 141. I really do not know what this fully means**

<?php

namespace App\Http\Controllers\Auth;

use App\ChargeCommision;
use App\Income;
use App\MemberExtra;
use App\User;
use App\General;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            'referrer_id' => 'required',
            'position' => 'required',
            'first_name' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
            'last_name' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
            'birth_day' => 'required',
            'mobile' => 'required',
            'street_address' => 'required',
            'city' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
            'post_code' => 'required|numeric|min:0',
            'country' => 'required',
            'username' => 'required',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {

        $pin = substr(time(), 4);

        $ref_id = $data['referrer_id'];
        $poss = $data['position'];
        $posid =  getLastChildOfLR($ref_id,$poss);

        // $general = General::first();

         $message = '<tr>';
         $message .='<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">';
         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;color:green;">Our warmest congratulations on your new account opening! This only shows that you have grown your business well. I pray for your prosperous.</p>';
                       
         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">You have taken this path knowing that you can do it. Good luck with your new business. I wish you all the success and fulfillment towards your goal.</p>';
         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Your username is '.$data['username'].' .</p>';

         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Your password is '.$data['password'].' .</p>';

          $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px; color:red;">Remember, never share your password with otherone. And you are agree with our Terms and Policy.</p>';
          $message .='</td>';
          $message .='</tr>';

       send_email($data['email'], 'Account Created Successfully', $data['first_name'], $message);

        $sms =  'Congratulation, for registration. Your username is '.$data['username'].'. Your password is '.$data['password'].'';
        send_sms($data['mobile'], $sms);

        return User::create([
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'referrer_id' => $data['referrer_id'],
            'position' => $data['position'],
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'mobile' => $data['mobile'],
            'street_address' => $data['street_address'],
            'city' => $data['city'],
            'post_code' => $data['post_code'],
            'country' => $data['country'],
            'username' => $data['username'],
            'birth_day' =>  date('Y-m-d',strtotime($data['birth_day'])),
            'join_date' => Carbon::today(),
            'balance' => 0,
            'status' => 1,
            'paid_status' => 0,
            'ver_status' => 0,
            'ver_code' => $pin,
            'forget_code' => 0,
            'posid' => $posid,
            'tauth' => 0,
            'tfver' => 1,
            'emailv' => 0,
            'smsv' => 1,
        ]);
    }

    public function register(Request $request)
    {
        $this->validator($request->all())->validate();
        event(new Registered($user = $this->create($request->all())));
        $this->guard()->login($user);
        MemberExtra::create([
           'user_id' => $user['id'],
           'left_paid' => 0,
           'right_paid' => 0,
           'left_free' => 0,
           'right_free' => 0,
           'left_bv' => 0,
           'right_bv' => 0,
        ]);
        updateMemberBelow($user['id'], 'FREE');
        return $this->registered($request, $user)
            ?: redirect($this->redirectPath());
    }
}

And RedirectifAuthenticated.php:24

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/home');
        }

        return $next($request);
    }
}

Image of the Error Message

This Was The Actually Error Message

And this is the mail.php file

<?php

return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    'port' => env('MAIL_PORT', 587),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

After the configuring from the response in the comment, I got a new error message

Call to undefined function App\Http\Controllers\Auth\getLastChildOfLR()

RegisterControllers.php:87

<?php

namespace App\Http\Controllers\Auth;

use App\ChargeCommision;
use App\Income;
use App\MemberExtra;
use App\User;
use App\General;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            'referrer_id' => 'required',
            'position' => 'required',
            'first_name' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
            'last_name' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
            'birth_day' => 'required',
            'mobile' => 'required',
            'street_address' => 'required',
            'city' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
            'post_code' => 'required|numeric|min:0',
            'country' => 'required',
            'username' => 'required',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {

        $pin = substr(time(), 4);

        $ref_id = $data['referrer_id'];
        $poss = $data['position'];
        $posid =  getLastChildOfLR($ref_id,$poss);

        // $general = General::first();

         $message = '<tr>';
         $message .='<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;">';
         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;color:green;">Our warmest congratulations on your new account opening! This only shows that you have grown your business well. I pray for your prosperous.</p>';
                       
         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">You have taken this path knowing that you can do it. Good luck with your new business. I wish you all the success and fulfillment towards your goal.</p>';
         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Your username is '.$data['username'].' .</p>';

         $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;">Your password is '.$data['password'].' .</p>';

          $message .='<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px; color:red;">Remember, never share your password with otherone. And you are agree with our Terms and Policy.</p>';
          $message .='</td>';
          $message .='</tr>';

       send_email($data['email'], 'Account Created Successfully', $data['first_name'], $message);

        $sms =  'Congratulation, for registration. Your username is '.$data['username'].'. Your password is '.$data['password'].'';
        send_sms($data['mobile'], $sms);

        return User::create([
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'referrer_id' => $data['referrer_id'],
            'position' => $data['position'],
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'mobile' => $data['mobile'],
            'street_address' => $data['street_address'],
            'city' => $data['city'],
            'post_code' => $data['post_code'],
            'country' => $data['country'],
            'username' => $data['username'],
            'birth_day' =>  date('Y-m-d',strtotime($data['birth_day'])),
            'join_date' => Carbon::today(),
            'balance' => 0,
            'status' => 1,
            'paid_status' => 0,
            'ver_status' => 0,
            'ver_code' => $pin,
            'forget_code' => 0,
            'posid' => $posid,
            'tauth' => 0,
            'tfver' => 1,
            'emailv' => 0,
            'smsv' => 1,
        ]);
    }

    public function register(Request $request)
    {
        $this->validator($request->all())->validate();
        event(new Registered($user = $this->create($request->all())));
        $this->guard()->login($user);
        MemberExtra::create([
           'user_id' => $user['id'],
           'left_paid' => 0,
           'right_paid' => 0,
           'left_free' => 0,
           'right_free' => 0,
           'left_bv' => 0,
           'right_bv' => 0,
        ]);
        updateMemberBelow($user['id'], 'FREE');
        return $this->registered($request, $user)
            ?: redirect($this->redirectPath());
    }
}

2 Answers2

1

If mail is deactivated for security reasons then you shouldn't use it. Indeed if you google the subject you find some serious results why you shouldn't use it.

I'd expect you have an email account with your hoster, right? So any reason why you don't want to use laravel's mailing capabilities?

In your .env file you set the correct parameters for your email account:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=name@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl

Sometimes you also need to define the MAIL_FROM_ADDRESS parameter. If you are unsure you find all possible config options in the config's mail.php file.

Then to send an email with Laravel, you can do the following

Mail::raw('your message', function ($message) use ($request) {

    $message->to('email@receiver.com');
    $message->from('youremail@sender.com');
    $message->subject("Email subject");
});

I don't know what you are trying to achieve, but if you only want to send some simple information, maybe you should go with a laravel notifications.

<?php
//edited
use App\General;
use App\User;
use App\MemberExtra;

function send_email($to, $subject, $name, $message){
        $general = General::first();
        
    if ($general->email_nfy == 1){
         $headers = "From: ".$general->web_title." <".$general->esender."> \r\n";
        $headers .= "Reply-To: ".$general->web_title." <".$general->esender."> \r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        
        $template = $general->emessage;
        $mm = str_replace("{{name}}",$name,$template);
        $message = str_replace("{{message}}",$message,$mm);
        //mail($to, $subject, $message, $headers);
        }else {
        return;
    }
}

function send_sms( $to, $message){
    $gnl = General::first();
    if($gnl->sms_nfy == 1) {
        $sendtext = urlencode("$message");
        $appi = $gnl->smsapi;
        $appi = str_replace("{{number}}",$to,$appi);
        $appi = str_replace("{{message}}",$sendtext,$appi);
        $result = file_get_contents($appi);
      }
      return;
}



function updateDepositBV($id, $deposit_amount)
{
    while($id !="" || $id != "0") {
        if(isMemberExists($id))
        {
            $posid = getParentId($id);
            if($posid == "0")
                break;
            $position = getPositionParent($id);
            $currentBV = MemberExtra::where('user_id', $posid)->first();

            if($position == "L"){
                $new_lbv = $currentBV->left_bv + $deposit_amount ;
                $new_rbv = $currentBV->right_bv;
            }else{
                $new_lbv = $currentBV->left_bv;
                $new_rbv = $currentBV->right_bv + $deposit_amount ;
            }

            MemberExtra::where('user_id', $posid)
                ->update([
                   'left_bv' => $new_lbv,
                   'right_bv' => $new_rbv,
                ]);

            $id = $posid;

        } else {
            break;
        }

    }//while
    return 0;
}



function updatePaid($id){
    while($id!=""||$id!="0"){
        if(isMemberExists($id)) {
            $posid=getParentId($id);
            if($posid  == "0")
                break;
            $position = getPositionParent($id);

            $currentCount = MemberExtra::where('user_id',$posid )->first();

            $new_lpaid = $currentCount->left_paid;
            $new_rpaid = $currentCount->right_paid;
            $new_lfree = $currentCount->left_free;
            $new_rfree = $currentCount->right_free;

            if($position == "L") {
                $new_lfree = $new_lfree-1;
                $new_lpaid = $new_lpaid+1;
            }else {
                $new_rfree = $new_rfree-1;
                $new_rpaid = $new_rpaid+1;
            }

            MemberExtra::where('user_id', $posid)
                ->update([
                   'left_paid' => $new_lpaid,
                   'right_paid' => $new_rpaid,
                   'left_free' => $new_lfree,
                   'right_free' => $new_rfree,
                ]);
            $id =$posid;

        } else {
            break;
        }
    }
    return 0;
}






function treeeee($id ='', $uid=''){

    while($id!=""||$id!="0") {
        if(isMemberExists($id)){
            $posid=getParentId($id);
            if($posid=="0")
                break;
            if($posid==$uid){
                return true;
            }
            $id =$posid;
        } else {
            break;
        }
    }//while
    return 0;
}

function printBV($id){
    $cbv = MemberExtra::where('user_id', $id)->first();
    $rid = User::whereId($id)->first();
    $rnm = User::where('id', $rid->referrer_id)->first();
    echo "<b>Referred By:</b> $rnm->username <br>";
    echo "<b>Current BV:</b> L-$cbv->left_bv | R-$cbv->right_bv <br>";
}

function printBelowMember($id){
    $bmbr = MemberExtra::where('user_id', $id)->first() ;
    echo "<b>Paid Member Below:</b> L-$bmbr->left_paid | R-$bmbr->right_paid <br>";
    echo "<b>Free Member Below:</b> L-$bmbr->left_free | R-$bmbr->right_free <br>";
}

function updateMemberBelow($id='', $type=''){
    while($id!=""||$id!="0") {
        if(isMemberExists($id)) {
            $posid=getParentId($id);
            if($posid=="0")
                break;
            $position=getPositionParent($id);
            $currentCount = MemberExtra::where('user_id', $posid)->first() ;

            $new_lpaid = $currentCount->left_paid;
            $new_rpaid = $currentCount->right_paid;
            $new_lfree = $currentCount->left_free;
            $new_rfree = $currentCount->right_free;

            if($position=="L") {
                if($type=='FREE'){
                    $new_lfree = $new_lfree + 1;
                }else{
                    $new_lpaid = $new_lpaid+1;
                }
            }else {
                if($type=='FREE'){
                    $new_rfree = $new_rfree + 1;
                }else{
                    $new_rpaid = $new_rpaid+1;
                }
            }
            MemberExtra::where('user_id', $posid)
                ->update([
                   'left_paid' => $new_lpaid,
                   'right_paid' => $new_rpaid,
                   'left_free' => $new_lfree,
                   'right_free' => $new_rfree,
                ]);
            $id =$posid;
        } else{
            break;
        }
    }
    return 0;
}

function getParentId($id){

    $count = User::whereId($id)->count() ;
    $posid = User::whereId($id)->first();
    if ($count == 1){
        return $posid->posid;
    }else{
        return 0;
    }
}


function getPositionParent($id){

    $count = User::whereId($id)->count();
    $position = User::whereId($id)->first() ;
    if ($count == 1){
        return $position->position;
    }else{
        return 0;
    }
}


function getLastChildOfLR($parentid ,$position){

    $childid = getTreeChildId($parentid, $position);

    if($childid!="-1"){
        $id = $childid;
    } else {
        $id = $parentid;
    }
    while($id!=""||$id!="0") {
        if(isMemberExists($id)) {
            $nextchildid = getTreeChildId($id, $position);
            if($nextchildid == "-1"){
                break;
            }else{
                $id = $nextchildid;
            }
        }else break;
    }
    return $id;
}
function getTreeChildId($parentid ,$position){
    $cou = User::where('posid', $parentid)->where('position', $position)->count();
    $cid = User::where('posid', $parentid)->where('position', $position)->first();
    if ($cou == 1){
        return $cid->id;
    }else{
        return -1;
    }
}

function isMemberExists($id){
    $count = User::where('id', $id)->count();
    if ($count == 1){
        return true;
    }else{
        return false;
    }
}

function Short_Text($data,$length){
    $first_part = explode(" ",$data);
    $main_part = strip_tags(implode(' ',array_splice($first_part,0, $length)));
    return $main_part ."...." ;
}

function ImageCheck($ext){
    if($ext != 'jpg' && $ext != 'jpeg' && $ext != 'png' && $ext != 'bnp'){
        $ext = "";
    }
    return $ext;
}

function NewFile($name, $data){
    $fh = fopen($name, "w");
    fwrite($fh,$data);
    fclose($fh);
}

function ViewFile($name){
    $fh = fopen($name, "r");
    $data = fread($fh,filesize($name));
    fclose($fh);
    return $data;
}

function Find_fist_int($string){
    preg_match_all('!\d+!', $string, $matches);
    if($matches[0] != ""){
        foreach($matches[0] as $key => $value){
            $url = $value;
            return $url;
            break;
        }
    }
}

function Replace($data) {
    $data = str_replace("'", "", $data);
    $data = str_replace("!", "", $data);
    $data = str_replace("@", "", $data);
    $data = str_replace("#", "", $data);
    $data = str_replace("$", "", $data);
    $data = str_replace("%", "", $data);
    $data = str_replace("^", "", $data);
    $data = str_replace("&", "", $data);
    $data = str_replace("*", "", $data);
    $data = str_replace("(", "", $data);
    $data = str_replace(")", "", $data);
    $data = str_replace("+", "", $data);
    $data = str_replace("=", "", $data);
    $data = str_replace(",", "", $data);
    $data = str_replace(":", "", $data);
    $data = str_replace(";", "", $data);
    $data = str_replace("|", "", $data);
    $data = str_replace("'", "", $data);
    $data = str_replace('"', "", $data);
    $data = str_replace("?", "", $data);
    $data = str_replace("  ", "_", $data);
    $data = str_replace("'", "", $data);
    $data = str_replace(".", "-", $data);
    $data = strtolower(str_replace("  ", "-", $data));
    $data = strtolower(str_replace(" ", "-", $data));
    $data = strtolower(str_replace(" ", "-", $data));
    $data = strtolower(str_replace("__", "-", $data));
    return str_replace("_", "-", $data);
}

This only works tough, if you configured your email account in your .env file.

Snake
  • 121
  • 2
  • 9
  • Thank you for you response, I have updated the question and have included both the error message as well as my mail.php file. The error is gotten when a user is trying to register on the website. It is meant to send a mail for verification. Please kindly assist in clarifying what you mean please. Thank you – Francis Ugorji Jun 28 '20 at 21:18
  • you need to use the Mail Facade of Laravel... so you import that facade by adding "use Mail;" at the top of the page - okay? And then you put the mail you want to send in the respective Mail::to()... and I also don't understand where do you send it from, from a Controller? – Snake Jun 28 '20 at 21:25
  • Yes I guess it is calling a Controller file. I have added a couple of files that i guess it was calling. And where would I add that line of code please. If possible kindly edit the sent code to assist in the modifications, I would be very glad. Thanks for your time – Francis Ugorji Jun 28 '20 at 21:40
  • I updated my answer, also notice the comments I made in the snippet. Hope it helps. – Snake Jun 28 '20 at 21:41
  • Thank you. I would give it a try now. One last thing, I can use the email account created from my cpanel right? – Francis Ugorji Jun 28 '20 at 21:43
  • Yes, and take care of the port as sometimes it differes from provider to provider. If you d go with mail(), you d have to actually configure your email in your php.ini - so there is no way around it. If you struggle, see the following question: https://stackoverflow.com/questions/52511262/how-to-configure-env-file-in-laravel-for-sending-mail - but in general you should do all your configurations in your .env file. – Snake Jun 28 '20 at 21:45
  • Okay understood and done. But I got a new error. `Call to undefined function App\Http\Controllers\Auth\getLastChildOfLR()`. I have updated the question. Thank you so much for your time – Francis Ugorji Jun 28 '20 at 21:50
1

Well, that's actually another question for itself. Where is the helpers.php file located at? Is it under the app folder? And how is it included? You see from the error that php namespace the function under the current namespace, so I guess something is wrong with how the file is included/autoloaded? My helpers.php file is in the app folder and I then load it through composer (in composer.json). It would look like this:

"autoload": {
    "files": [
        "app/helpers.php"
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ]
},

If you change that file you have to run composer dump-autoload

...and if the file looks already like this, it does not hurt to run the command as maybe something went wrong.

Snake
  • 121
  • 2
  • 9