1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Laravel 11 not able to send simple Email regularly

Discussão em 'Outras Linguagens' iniciado por solo, Novembro 8, 2024 às 11:12.

  1. solo

    solo Guest

    I have developed a Laravel 11 application that is supposed to send an email upon user registration. The application rarely sends an email except for a few registrations.

    Here is my code:

    Route file:

    Route::get('/program/touching-lives-at-christmas/register', [PublicController::class, 'form_tlc']);

    Route::post('/program/touching-lives-at-christmas/register', [PublicController::class, 'register_save_tlc']);


    Controller file:

    class PublicController extends Controller
    {
    //
    public function register_save_tlc(Request $request){


    $tlc= new Tlc();
    $participant= new Participant();
    $part1=Participant::where('email', $request->email)->get();
    $check=Participant::where('email', $request->email)->count();

    $centerl= Tlc_leader::where('center', $request->center)->get();
    foreach($centerl as $center_loc){
    $data = [
    'title'=> $request->title,
    'name'=> $request->name,
    'package' => $request->tlc_package,
    'center' => $request->center,
    'city' => $request->city,
    'coordinator_name'=> $center_loc->coordinator_name,
    'phone_no'=> $center_loc->phone_no

    ];



    Mail::to($request->email)->send(new Signup($data));

    }


    Email template:

    <html>
    <head>
    <title>
    TKP Registration confirmation
    </title>
    </head>
    <body>


    TLC Registration Confirmation.
    <center><img src="https://forms.tkpmission.org/images/banner.png" style="width: 100%; height: auto" alt=""></center>

    Dear {{$data['title']}} {{$data['name']}},

    This to acknowledge your registration for TLC 2024.

    You have indicated indicate in {{$data['package']}}
    (the TLC Package)
    in
    @if($data['package'] !=null || $data['package']!="")
    {{$data['center']}} Center .

    @else
    {{$data['city']}} City .

    @endif


    Mailable class

    class Signup extends Mailable
    {
    use Queueable, SerializesModels;

    /**
    * Create a new message instance.
    */

    public $data;

    public function __construct($data)
    {
    //
    $this->data= $data;
    }

    /**
    * Get the message envelope.
    */
    public function envelope(): Envelope
    {
    return new Envelope(
    subject: 'Signup'
    );
    }

    /**
    * Get the message content definition.
    */
    public function content(): Content
    {
    return new Content(
    view: 'success',
    );
    }

    /**
    * Get the attachments for the message.
    *
    * @return array<int, \Illuminate\Mail\Mailables\Attachment>
    */
    public function attachments(): array
    {
    return [];
    }
    }


    .env file

    MAIL_MAILER=smtp
    MAIL_HOST=<email server>
    MAIL_PORT=587
    MAIL_USERNAME=<my email>
    MAIL_PASSWORD=<password>
    MAIL_ENCRYPTION=tls
    MAIL_FROM_ADDRESS=<my email>
    MAIL_FROM_NAME=App


    Please, I need help on how to figure this out.

    Continue reading...

Compartilhe esta Página