PHPackages                             cooperativecomputing/mailing-and-sms-template - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. cooperativecomputing/mailing-and-sms-template

ActivePackage[Mail &amp; Notifications](/categories/mail)

cooperativecomputing/mailing-and-sms-template
=============================================

A basic template for emailing and sms service

04Blade

Since Jan 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/CC-Areeb/CC_Package)[ Packagist](https://packagist.org/packages/cooperativecomputing/mailing-and-sms-template)[ RSS](/packages/cooperativecomputing-mailing-and-sms-template/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Cooperative Computing Mailing and SMS templates
===============================================

[](#cooperative-computing-mailing-and-sms-templates)

A basic template and implementation of the Laravel mailing and sms services.

**Minimum Laravel version support:** *laravel 7, laravel 8 and laravel 9*

### Installation command using composer

[](#installation-command-using-composer)

```
composer require cooperativecomputing/mailing-and-sms-template

```

The environment variables are provided in a text file called **keys.txt**

Use the @csrf keyword in your html form blade files as laravel uses it for protection against cross site request forgery and is a must before you send any requests from the forms.

app.php
-------

[](#appphp)

Add the service provider

```
/*
* Package Service Providers...
*/

CooperativeComputing\Services\EmailingServiceProvider::class,
CooperativeComputingSMS\Services\SmsServiceProvider::class,

```

Publish the SMS and Maling services
-----------------------------------

[](#publish-the-sms-and-maling-services)

```
php artisan vendor:publish --tag=CC-Emails
php artisan vendor:publish --tag=CC-SMS

```

composer.json
-------------

[](#composerjson)

For mailing template add these in your composer json file, inside `autoload` --&gt; `psr-4`

```
"CooperativeComputing\\Routes\\": "routes/",
"CooperativeComputing\\Controllers\\": "app/Http/Controllers/",
"CooperativeComputing\\Mail\\": "app/Mail/",

```

For sms template add these in your composer json file, inside `autoload` --&gt; `psr-4`

```
"CooperativeComputingSMS\\Routes\\": "routes/",
"CooperativeComputingSMS\\Controllers\\": "app/Http/Controllers/"

```

Run the `composer du` command in the terminal.

Next execute the commands below

```
php artisan install:email
php artisan install:sms

```

The above commands will install the files from the package folder into you main project files respectivly.

---

Sending Mails
=============

[](#sending-mails)

Add the environment variables in your `.env` file

```
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=YOUR_USERNAME_FROM_MAILTRAP
MAIL_PASSWORD=YOUR_PASSWORD_FROM_MAILTRAP
MAIL_ENCRYPTION=tls

```

### Send to a single user

[](#send-to-a-single-user)

```
public function sendEmail()
{
    $validator = [
        'sender' => 'sender@mail.com',
        'to' => 'receiver@mail.com',
        'subject' => 'some subject',
        'message' => 'A message from sender',
    ];
    Mail::queue((new MailEmails($validator))->onQueue('emails'));
    return "mail has been sent";
}

```

### Send to a multiple users

[](#send-to-a-multiple-users)

```
public function sendEmail()
{
    $validator = [
        'sender' => 'sender@mail.com',
        'to' => ['receiver_one@mail.com', 'receiver_two@mail.com', 'receiver_three@mail.com'],
        'subject' => 'some subject',
        'message' => 'A message from sender',
    ];
    Mail::queue((new MailEmails($validator))->onQueue('emails'));
    return "mail has been sent";
}

```

---

Mailable file
=============

[](#mailable-file)

### Sending a mail

[](#sending-a-mail)

```
public $validator;

/**
    * Create a new message instance.
    *
    * @return void
    */

public function __construct($validator)
{
    $this->validator = $validator;
}

/**
    * Build the message.
    *
    * @return $this
    */

public function build()
{
    return $this->from($this->validator['sender'])
                ->subject($this->validator['subject'])
                ->to($this->validator['to'])
                ->markdown('email-welcome');
}

```

### Sending a single attachment

[](#sending-a-single-attachment)

```
public function build()
{
    return $this->from($this->validator['sender'])
                ->subject($this->validator['subject'])
                ->to($this->validator['to'])
                ->attach(public_path(''))
                ->markdown('email-welcome');
}

```

### Sending multiple attachments

[](#sending-multiple-attachments)

```
public function sendEmail()
    {
        $attachments = [
            public_path(''),
            public_path(''),
            public_path(''),
        ];
        $validator = [
            'sender' => 'sender@mail.com',
            'to' => 'receiver@mail.com',
            'subject' => 'some subject',
            'message' => 'A message from sender',
            'attachments' => $attachments
        ];
        Mail::queue((new MailEmails($validator))->onQueue('emails'));
        return "mail has been sent";
    }

```

Inside the Emails file

```
public function build()
{
    $this->from($this->validator['sender'])
        ->subject($this->validator['subject'])
        ->to($this->validator['to'])
        ->markdown('email-welcome');
    foreach ($this->validator['attachments'] as $attachment) {
        $this->attach($attachment);
    }
    return $this;
}

```

Add more options in your mail

```
return $this->from($this->validator['sender'])
            ->subject($this->validator['subject'])
            ->to($this->validator['to'])
            ->cc($this->validator['people'])
            ->bcc($this->validator['private_people'])
            ->attach(base_path(''))
            ->markdown('email-welcome');

```

optionsdescriptionfromperson who is sending the mailsubjectpurpose of the emailtothe main recipientcccarbon copy for adding people publiclybccblind carbon copy for adding people privatlySending SMS
===========

[](#sending-sms)

Add the environment variables in your `.env` file

```
TWILIO_ACCOUNT_SID=YOUR_TWILIO_SID_FROM_TWILIO
TWILIO_AUTH_TOKEN=YOUR_TWILIO_AUTH_TOKEN_FROM_TWILIO
TWILIO_SENDER=YOUR_TWILIO_PHONE_NUMBER_FROM_TWILIO

```

For the Twilio template, I am using the form request method of Laravel as I cannot disclose my personal cell number.

*Note*

**To actually send an sms after resigistering your number, make sure to use the country code like for example in Pakistan we use `+92` otherwise the twilio cannot send sms.**

Sms controller

```
public function sendSMS()
{
    $otp = $this->generateOTP();

    $request = (object) [
        'sms_message' => 'Text message with OTP: '. $otp,
        'sms_receiver' => '',
    ];

    try {
        $sid = config('sms.sid', 'some_sid');
        $sender = config('sms.sender', 'some_sender');
        $authToken = config('sms.auth', 'some_token');
        $twilio = new Client($sid, $authToken);
        $twilio->messages->create(
            $request->sms_receiver,
            [
                "body" => $request->sms_message,
                "from" => $sender,
                "mediaUrl" => ["https://demo.twilio.com/owl.png"]
            ]
        );
        return 'SMS was sent';
    } catch (TwilioException $e) {
        throw $e;
    }
}

public function generateOTP()
{
    return random_int(0,99999);
}

```

`messages->create()` this is a method by twilio for creating the sms and sending it.

First argument takes in the recipient's cell number and the second argument is the main sms itself.

- `body` this is the main body of your sms or the text you write to send
- `from` this is the sender of the sms, for twilio you have to register your number
- `mediaUrl` this is an optional field, we can send some media URLs with this

optionsdescriptionbodythis is the main body of your sms or the text you write to sendfromthis is the sender of the sms, for twilio you have to register your numbermediaUrlthis is an optional field, we can send some media URLs with thisMore twilio examples with laravel

****

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8d36c6edd10184bb8b0eafdbf186b64980fe2373ad110728bcfbc0eeb560bfa?d=identicon)[Muhammad Areeb Malik](/maintainers/Muhammad%20Areeb%20Malik)

---

Top Contributors

[![CC-Areeb](https://avatars.githubusercontent.com/u/96907614?v=4)](https://github.com/CC-Areeb "CC-Areeb (31 commits)")[![areebmalikcc](https://avatars.githubusercontent.com/u/125564432?v=4)](https://github.com/areebmalikcc "areebmalikcc (10 commits)")

### Embed Badge

![Health badge](/badges/cooperativecomputing-mailing-and-sms-template/health.svg)

```
[![Health](https://phpackages.com/badges/cooperativecomputing-mailing-and-sms-template/health.svg)](https://phpackages.com/packages/cooperativecomputing-mailing-and-sms-template)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M228](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M52](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
