PHP code example of ahmedwaleed / mailmerge

1. Go to this page and download the library: Download ahmedwaleed/mailmerge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ahmedwaleed / mailmerge example snippets



return [
    /*
    |--------------------------------------------------------------------------
    | MailMerge Path
    |--------------------------------------------------------------------------
    |
    | This is the URI prefix where Wink will be accessible from. Feel free to
    | change this path to anything you like.
    |
    */
    'path' => env('MAILMERGE_PATH', 'mailmerge'),

    /*
    |--------------------------------------------------------------------------
    | MailMerge Services Credentials
    |--------------------------------------------------------------------------
    |
    */
    'services' => [
        'default' => env('DEFAULT_SERVICE', 'mailgun'),
        'mailgun' => [
            'api_key' => env('MAILGUN_API_KEY'),
            'api_domain' => env('MAILGUN_API_DOMAIN'),
            'api_endpoint' => env('MAILGUN_API_ENDPOINT', 'https://api.mailgun.net'),
            'api_base_url' => env('MAILGUN_API_BASE_URL'),
        ],
        'pepipost' => [
            'api_key' => env('PEPIPOST_API_KEY'),
            'api_endpoint' => env('PEPIPOST_API_ENDPOINT'),
        ],
        'sendgrid' => [
            'api_key' => env('SENDGRID_API_KEY'),
            'api_endpoint' => env('SENDGRID_API_ENDPOINT'),
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | MailMerge Middleware Group
    |--------------------------------------------------------------------------
    |
    | This is the middleware group that mailmerge uses for package web routes.
    |
    */
    'middleware_group' => env('MAILMERGE_MIDDLEWARE_GROUP', 'web'),
];

$payload = [
    'from' => '[email protected]',
    'to' => '[email protected]',
    'subject' => 'Hi John',
    'body' => 'The winters is comming...'
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://domain.com/api/mails/message");
        
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "signature: 80PhN7Q3bQFSDFDSF333fYo7y6DLSSDDKKDK885dvFO4EFksA=" // your auth signature here
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch)

$payload = [
    'from' => '[email protected]',
    'recipients' => [
            [
                'email' => '[email protected]',
                'attributes' => [
                'first' => 'john',
                'last' => 'doe'
            ],
            [
                'email' => '[email protected]',
                'attributes' => [
                'first' => 'jane',
                'last' => 'doe'
            ]
        ]
    ],
    'subject' => 'Hi <%attribute.first%>',
    'body' => 'This this test body with last name <%attribute.last%>.'
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://domain.com/api/mails/batch");
        
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "signature: 80PhN7Q3bQFSDFDSF333fYo7y6DLSSDDKKDK885dvFO4EFksA="
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch)

curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "API-SERVICE: sendgrid", // suported (mailgun, pepipost, sendgrid)
]);

$payload = [
    // ...
    "cc": "[email protected],[email protected]",
    "bcc": "[email protected],[email protected]",
    // ...
];

$payload = [
    // ...
    'attachments' = [
        'https://site.com/uploads/sample1.pdf',
        'https://site.com/uploads/sample2.pdf'
    ],
    // ...
];
sh
php artisan mailmerge:migrate
bash
php artisan vendor:publish --tag="mailmerge-config"
bash
php artisan vendor:publish --tag='mailmerge-views' --force

/api/logs?items=100

/api/logs?service=mailgun