ContactController.php
This handles the sending of a user's contact information to the Mapmama email.
sendContact
sendContactpublic function sendContact(Request $request)
{
// Subject for the contact email
$subject = "Someone contacted us!";
// Compose the body of the email using form input values
$body = "
<div style='display:block'>Name: " . $request->input('name') . "</div>
<div style='display:block'>Phone Number: " . $request->input('phone') . "</div>
<div style='display:block'>Email: " . $request->input('email') . "</div>
<div style='display:block'>Message: " . $request->input('message') . "</div>
";
// Use Laravel Mail facade to send an email using the EmailContent Mailable
Mail::to('[email protected]')->send(new EmailContent($subject, $body));
// Response indicating success
$response = [
'SUCCESS' => 1,
];
// Return the response
return $response;
}To explain what this sendContact method does:
Capture Request Data:
Receive a request object as a parameter, representing the user's input through a form.
Set Email Subject:
Define the email subject as "Someone contacted us!"
Compose Email Body:
Construct the body of the email using HTML formatting and the input values from the request.
Include the sender's name, phone number, email address, and the message they provided.
Initialize Email Content:
Create an HTML string containing the composed email body.
Send Email:
Use Laravel's
Mailfacade to send an email.The
EmailContentMailableis used to structure the email with the provided subject and body.
Specify Recipient:
Set the recipient email address to '[email protected]'.
Handle Email Sending:
Trigger the sending of the email by calling the
sendmethod on theMailfacade.
Prepare Success Response:
Create a success response array indicating that the email sending was successful.
The array includes a key
'SUCCESS'with a value of1.
Return Response:
Return the success response array to the client or calling code.
Last updated