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

MyBrainMightexplode()'s avatar

API POST working sporadically after go live

I just pushed the application live to EC2 Amazon Linux 2. One view of the application posts back to the server via an api route to perform a controller function. The problem is that about 80% of the time the request body shows empty and the other times it works... On one route that also wasn't working I changed it to use a closure instead of the Class function array which seemed to fix that one, but no luck with this one.

I've run each of the functions each time I change something: php artisan route:clear php artisan route:cache php artisan cache:clear

My Vue function is:

		sendEmail(data) {
			Inertia.post('/api/send-email', {
				id: data.id,
				action: data.action,
				subject: data.subject,
				body: data.body,
				attachments: data.attachments,
				status: this.data.status,
				page: this.data.page,
				userEmail: this.data.userEmail,
			});
			this.selectedForm.email = false;
			this.selectedForm.message = 'Email has been sent.';
			this.clearMessage();
	        Inertia.reload();
		},

My api.php route is

Route::post('/send-email', function(Request $request) {
    $data = $request->all();
    Storage::disk('local')->put('complete3.txt', print_r($data, true));
    $form = new FormManager();
    $form->send_email($data);
    return Redirect::route('forms-manager', ['status' => $data['status'], 'page' => $data['page']]);
})->name('send-email');

My successful attempts will write the request body to the log file:

Array
(
    [id] => 3
    [action] => send
    [subject] => 12333321
    [body] => 2213414
    [attachments] => 1
    [status] => active
    [page] => 1
    [userEmail] => ***@****.com
)

The unsuccessful attempts all show:

Array
(
)

The network tab of the dev console always shows the correct json body:

{
    "id": 3,
    "action": "send",
    "subject": "12333321",
    "body": " 2213414",
    "attachments": true,
    "status": "active",
    "page": 1,
    "userEmail": "***@****.com"
}

The POST in the network tab always shows a (cancelled) status whether it is successful or not

0 likes
2 replies
martinbean's avatar

@mybrainmightexplode() I’d seriously implore you to add validation to that route, especially if it’s doing something as sensitive as sending actual emails.

MyBrainMightexplode()'s avatar

@martinbean I removed the validation so that I couldn't be affecting the current situation and I wouldn't have to explain what was also in that middleware 👍

Please or to participate in this conversation.