PHP code example of shieldon / messenger

1. Go to this page and download the library: Download shieldon/messenger 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/ */

    

shieldon / messenger example snippets


composer 



$apiKey = 'your_api_key';
$channel = '@your_channel';

$telegram = new \Shieldon\Messenger\Telegram($apiKey, $channel);

if ($telegram->send('say something!')) {
    echo 'Message has been sent to your Telegram group.';
} else {
    echo 'Failed to send message.' . "\n";
    echo $telegram->printResult();
}

$accessToken = 'your_access_token';

$line = new \Shieldon\Messenger\LineNotify($accessToken);

if ($line->send('say something!')) {
    echo 'Message has been sent to your Line group.';
} else {
    echo 'Failed to send message.' . "\n";
    echo $line->printResult();
}

$accessToken = 'your_auth_token';
$userId = 'your_user_id';
$serverUrl = 'https://your_rocket_chat.com:3000';
$channel = '#general';

$rocketChat = new \Shieldon\Messenger\RocketChat($accessToken, $userId, $serverUrl, $channel);

if ($rocketChat->send('say something!')) {
    echo 'Message has been sent to your RocketChat channel.';
} else {
    echo 'Failed to send message.' . "\n";
    echo $rocketChat->printResult();
}

$botToken = 'xoxb-551837935968-920623655894-TI1zWtaDLCkTzZaFFuyfzL56';
$channel = '#general';

$slack = new \Shieldon\Messenger\Slack($botToken, $channel);

if ($slack->send('say something!')) {
    echo 'Message has been sent to your Slack channel.';
} else {
    echo 'Failed to send message.' . "\n";
    echo $slack->printResult();
}

$webhook = 'https://hooks.slack.com/services/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';

$slack = new \Shieldon\Messenger\SlackWebhook($webhook);

if ($slack->send('say something!')) {
    echo 'Message has been sent to your Slack channel.';
} else {
    echo 'Failed to send message.' . "\n";
    echo $slack->printResult();
}


$mail = new \Shieldon\Messenger\Mail();
$mail->addSender('[email protected]');
$mail->addRecipient('[email protected]');
$mail->setSubject('Foo, bar.');

if ($mail->send('say something!')) {
    echo 'Email has been delivered via PHP\'s native mail function.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $maingun->printResult();
}


$user = 'email@your_domain.com';
$pass = '12345678';
$host = '127.0.0.1';
$port = '25';

$mail = new \Shieldon\Messenger\Smtp($user, $pass, $host, $port);

$mail->addSender('email@your_domain.com');
$mail->addRecipient('[email protected]');
$mail->setSubject('Foo, bar.');

if ($mail->send('say something!')) {
    echo 'Email has been delivered via SMTP.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $maingun->printResult();
}

$host = 'ssl://smtp.gmail.com'; // SMTPS
$host = 'tls://smtp.gmail.com'; // STARTTLS

$apiKey = 'your_api_key';

$sendgrid = new \Shieldon\Messenger\Sendgrid($apiKey);
$sendgrid->addSender('[email protected]');
$sendgrid->addRecipient('[email protected]');
$sendgrid->setSubject('Foo, bar.');

if ($sendgrid->send('say something!')) {
    echo 'Email has been delivered via SendGrid API.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $maingun->printResult();
}

$apiKey = 'your_api_key';
$domain = 'your_domain_name';

$maingun = new \Shieldon\Messenger\Mailgun($apiKey, $domain);
$maingun->addSender('[email protected]');
$maingun->addRecipient('[email protected]');
$maingun->setSubject('Foo, bar.');

if ($maingun->send('say something!')) {
    echo 'Email has been delivered via MailGun API.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $maingun->printResult();
}

$user = '[email protected]';
$pass = 'your_password';

$maingun = new \Shieldon\Messenger\Smtp\Mailgun($user, $pass);

$maingun->addSender('[email protected]');
$maingun->addRecipient('[email protected]');
$maingun->setSubject('Foo, bar.');

if ($maingun->send('say something!')) {
    echo 'Email has been delivered via MainGun SMTP server.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $maingun->printResult();
}

$user = '[email protected]';
$pass = 'your_password';

$gmail = new \Shieldon\Messenger\Smtp\Gmail($user, $pass);

$gmail->addSender('[email protected]');
$gmail->addRecipient('[email protected]');
$gmail->setSubject('Foo, bar.');

if ($gmail->send('say something!')) {
    echo 'Email has been delivered via Gmail SMTP server.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $gmail->printResult();
}

$user = '[email protected]';
$pass = 'your_password';

$yahooMail = new \Shieldon\Messenger\Smtp\Yahoo($user, $pass);

$yahooMail->addSender('[email protected]');
$yahooMail->addRecipient('[email protected]');
$yahooMail->setSubject('Foo, bar.');

if ($yahooMail->send('say something!')) {
    echo 'Email has been delivered via Yahoo SMTP server.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $yahooMail->printResult();
}

$user = '[email protected]';
$pass = 'your_password';

$outlook = new \Shieldon\Messenger\Smtp\Outlook($user, $pass);

$outlook->addSender('[email protected]');
$outlook->addRecipient('[email protected]');
$outlook->setSubject('Foo, bar.');

if ($outlook->send('say something!')) {
    echo 'Email has been delivered via Office365 SMTP server.';
} else {
    echo 'Failed to send email.' . "\n";
    echo $yahooMail->printResult();
}

$mail = new \Shieldon\Messenger\Smtp($user, $pass, $host, $port);

$mail->debugMode(true);

$mail->addSender('email@your_domain.com');
$mail->addRecipient('[email protected]');
$mail->setSubject('Foo, bar.');

try {
    $mail->send('say something!');

} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}


$mail = new \Shieldon\Messenger\Smtp($user, $pass, $host, $port);
$mail->addSender('email@your_domain.com');
$mail->addRecipient('[email protected]');
$mail->setSubject('Foo, bar.');
$mail->send('say something!');

echo $mail->printResult();