Where should the mail sending functionality be implemented in a PHP MVC architecture, in the Model or in the Controller?

In a PHP MVC architecture, the mail sending functionality should ideally be implemented in the Controller. This is because the Controller is responsible for handling user input, making decisions based on that input, and interacting with the Model to update data. Sending emails is usually a response to a specific user action or event, making it a logical task for the Controller to handle.

// Controller code snippet for sending an email
public function sendEmailAction() {
    // Code to process user input and determine email content
    $recipient = $_POST['recipient'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    
    // Code to send the email
    $result = mail($recipient, $subject, $message);
    
    // Code to handle the result of the email sending operation
    if($result) {
        echo "Email sent successfully!";
    } else {
        echo "Failed to send email.";
    }
}