ContactController.php

This handles the sending of a user's contact information to the Mapmama email.

sendContact

public 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:&nbsp;" . $request->input('name') . "</div>
        <div style='display:block'>Phone Number:&nbsp;" . $request->input('phone') . "</div>
        <div style='display:block'>Email:&nbsp;" . $request->input('email') . "</div>
        <div style='display:block'>Message:&nbsp;" . $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:

  1. Capture Request Data:

    • Receive a request object as a parameter, representing the user's input through a form.

  2. Set Email Subject:

    • Define the email subject as "Someone contacted us!"

  3. 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.

  4. Initialize Email Content:

    • Create an HTML string containing the composed email body.

  5. Send Email:

    • Use Laravel's Mail facade to send an email.

    • The EmailContent Mailable is used to structure the email with the provided subject and body.

  6. Specify Recipient:

  7. Handle Email Sending:

    • Trigger the sending of the email by calling the send method on the Mail facade.

  8. Prepare Success Response:

    • Create a success response array indicating that the email sending was successful.

    • The array includes a key 'SUCCESS' with a value of 1.

  9. Return Response:

    • Return the success response array to the client or calling code.

Last updated