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

shahr's avatar
Level 10

How to create a newsletter?

I want to send an email to Laravel.

blade

<form method="post" action="{{ route('subscribe') }}" class="input-group rounded-pill" style="width: 228px;">
    @csrf
    <input type="text" class="form-control fs-14" name="email" placeholder="Enter your E-Maiil." aria-label="email">
    <button class="btn btn-warning" type="submit">send </button>
</form>

web.php

Route::post('/subscribe', [App\Http\Controllers\NewsLetterController::class, 'subscribe'])->name('subscribe');

NewsLetterController.php

class NewsLetterController extends Controller
{
    public function subscribe(Request $request)
    {
        $request->validate([
            'email' => 'required|email|unique:news_letters,email',
        ]);

        NewsLetter::query()->create([
            'email' => $request->post('email')
        ]);

        $notifiable = (object)['email' => $request->input('email')];
        Notification::route('mail', $notifiable)
                    ->notify(new NewsLetterNotification());

        alert()->success('greeting', 'You have successfully subscribed to Selda newsletter.')->showConfirmButton('ok');
        return back();
    }
}

NewsLetterNotification.php

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class NewsLetterNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
        ->subject('New newsletter subscriber')
        ->view('emails.newsletter', ['user' => $notifiable]);
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

emails.blade.php

<h1>Thanks </h1>

I get this error.

Email "email" does not comply with addr-spec of RFC 2822.

0 likes
1 reply

Please or to participate in this conversation.