Description
when i am testing the api from postman from this add : http://localhost:8000/api/send-course-registration-email , 200 ok result is coming but postman is just showing html code of the welcome.blade.php file and the email is not receiving in info@saltuspc.ca , How to solve the problem , email should be received in the mail ?
View Code
.env code : MAIL_MAILER=smtp
MAIL_HOST=mail.saltuspc.ca
MAIL_PORT=2525
MAIL_USERNAME=info@saltuspc.ca
MAIL_PASSWORD=1Ej^lu@Go2AyefH7
MAIL_ENCRYPTION=smtp
MAIL_FROM_ADDRESS="site@saltuspc.ca"
MAIL_FROM_NAME="${APP_NAME}"
api.php file code : <?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\EmailController;
use App\Mail\CourseRegistrationMail;
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth:sanctum');
Route::post('/send-course-registration-email', [EmailController::class, 'sendCourseRegistrationEmail'])->name('course.registration.email');
, EmailController file code : <?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Mail;
use App\Mail\CourseRegistrationMail;
use Illuminate\Http\Request;
class EmailController extends Controller
{
public function sendCourseRegistrationEmail(Request $request)
{
// Validate the incoming data
$validatedData = $request->validate([
'CourseName' => 'required|string',
'CourseDuration' => 'required|string',
'CourseFees' => 'required|numeric',
'FirstName' => 'required|string',
'LastName' => 'required|string',
'DOB' => 'required|date',
'PhoneNumber' => 'required|string',
'Email' => 'required|email',
'Address' => 'required|string',
'City' => 'required|string',
'Province' => 'required|string',
'PostalCode' => 'required|string',
'GovernmentID' => 'required|string',
]);
// Create the email details array
$emailDetails = [
'CourseName' => $validatedData['CourseName'],
'CourseDuration' => $validatedData['CourseDuration'],
'CourseFees' => $validatedData['CourseFees'],
'FirstName' => $validatedData['FirstName'],
'LastName' => $validatedData['LastName'],
'DOB' => $validatedData['DOB'],
'PhoneNumber' => $validatedData['PhoneNumber'],
'Email' => $validatedData['Email'],
'Address' => $validatedData['Address'],
'City' => $validatedData['City'],
'Province' => $validatedData['Province'],
'PostalCode' => $validatedData['PostalCode'],
'GovernmentID' => $validatedData['GovernmentID'],
];
// Mail::to('info@saltuspc.ca')->send(new \Illuminate\Mail\Message());
// Send the email using the CourseRegistrationMail Mailable
Mail::to('info@saltuspc.ca')->send(new CourseRegistrationMail($emailDetails));
// Check if the email failed to send
if (Mail::failures()) {
return response()->json(['message' => 'Email sending failed!'], 500);
}
// Return a response to the frontend
return response()->json(['message' => 'Email sent successfully.'], 200);
}
}
0 Likes 0 Comments