{"id":21850321,"url":"https://github.com/terrylinooo/messenger","last_synced_at":"2025-04-14T14:56:13.549Z","repository":{"id":57049330,"uuid":"217857545","full_name":"terrylinooo/messenger","owner":"terrylinooo","description":"Sending messages and emails made easy for PHP.","archived":false,"fork":false,"pushed_at":"2020-07-11T18:20:55.000Z","size":170,"stargazers_count":20,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-26T06:21:18.343Z","etag":null,"topics":["gmail-smtp","php-mailer","php-messenger","smtp-client"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/terrylinooo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-27T13:16:27.000Z","updated_at":"2024-03-14T10:21:55.000Z","dependencies_parsed_at":"2022-08-23T17:50:29.710Z","dependency_job_id":null,"html_url":"https://github.com/terrylinooo/messenger","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fmessenger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fmessenger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fmessenger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fmessenger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terrylinooo","download_url":"https://codeload.github.com/terrylinooo/messenger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248902028,"owners_count":21180553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gmail-smtp","php-mailer","php-messenger","smtp-client"],"created_at":"2024-11-28T00:17:03.903Z","updated_at":"2025-04-14T14:56:13.524Z","avatar_url":"https://github.com/terrylinooo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Messenger\n\nSending messages to the third-party services made easy for PHP.\n\n*Supported modules:*\n\n- Telegram\n- Line Notify\n- Rocket Chat\n- Slack\n- Slack Webhook\n- Mail\n- SMTP\n- SendGrid\n- MailGun\n- MailGun (SMTP)\n- Gmail (SMTP)\n- Yahoo (SMTP)\n- Outlook (SMTP)\n\nMore modules will come in the future...\n\n## Installation\n\nUse PHP Composer:\n\n```php\ncomposer require shieldon/messenger\n```\n\nOr, download it and include the Messenger autoloader.\n```php\nrequire './autoload.php';\n```\n\n## Basic Usage\n\nPublic API methods:\n\n- send\n- debugMode\n- printResult\n\nOther than the Mailer classes, the only one public API is `send()`. The only thing you need to do is to assign the required data fields into constructor when initializing instance.\n\n### Telegram\n\nOpen your Telegram App, add `BotFather` to start a new conversation. Type command `/newbot` to obtain your API key.\n\nRemember, make sure your channel type is public. If you want to send messages to your private channel, googling will find solutions.\n\n```php\n$apiKey = 'your_api_key';\n$channel = '@your_channel';\n\n$telegram = new \\Shieldon\\Messenger\\Telegram($apiKey, $channel);\n\nif ($telegram-\u003esend('say something!')) {\n    echo 'Message has been sent to your Telegram group.';\n} else {\n    echo 'Failed to send message.' . \"\\n\";\n    echo $telegram-\u003eprintResult();\n}\n```\n\n### Line Notify\n\nThe access token can be obtained by clicking `Generate token` button at this [signup page](https://notify-bot.line.me/my/).\n\nOnce you have obtained your developer access token for the chat group you choose, invite `Line Notify` bot join your Line group, then the following code will work as expected.\n\n```php\n$accessToken = 'your_access_token';\n\n$line = new \\Shieldon\\Messenger\\LineNotify($accessToken);\n\nif ($line-\u003esend('say something!')) {\n    echo 'Message has been sent to your Line group.';\n} else {\n    echo 'Failed to send message.' . \"\\n\";\n    echo $line-\u003eprintResult();\n}\n```\n\n### RocketChat\n\n```php\n$accessToken = 'your_auth_token';\n$userId = 'your_user_id';\n$serverUrl = 'https://your_rocket_chat.com:3000';\n$channel = '#general';\n\n$rocketChat = new \\Shieldon\\Messenger\\RocketChat($accessToken, $userId, $serverUrl, $channel);\n\nif ($rocketChat-\u003esend('say something!')) {\n    echo 'Message has been sent to your RocketChat channel.';\n} else {\n    echo 'Failed to send message.' . \"\\n\";\n    echo $rocketChat-\u003eprintResult();\n}\n```\n\n### Slack\n\nPlease clearfully read Slack's official [API docs](https://api.slack.com/messaging/sending) to find out things you need.\n\nGuide:\n\n- Create a App\n- Assign `channels:read` and `chat:write:bot` permissions to your App.\n- Assign your APP to your workspace.\n- Obtain bot's access token.\n- Add your App to the channel you would like to send messages.\n\n```php\n$botToken = 'xoxb-551837935968-920623655894-TI1zWtaDLCkTzZaFFuyfzL56';\n$channel = '#general';\n\n$slack = new \\Shieldon\\Messenger\\Slack($botToken, $channel);\n\nif ($slack-\u003esend('say something!')) {\n    echo 'Message has been sent to your Slack channel.';\n} else {\n    echo 'Failed to send message.' . \"\\n\";\n    echo $slack-\u003eprintResult();\n}\n```\n\n### Slack Webhook\n\nThis would be the simplest way for messaging. Please clearfully read Slack's official [API docs](https://api.slack.com/messaging/webhooks) to find out things you need.\n\n```php\n$webhook = 'https://hooks.slack.com/services/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';\n\n$slack = new \\Shieldon\\Messenger\\SlackWebhook($webhook);\n\nif ($slack-\u003esend('say something!')) {\n    echo 'Message has been sent to your Slack channel.';\n} else {\n    echo 'Failed to send message.' . \"\\n\";\n    echo $slack-\u003eprintResult();\n}\n\n```\n\nok.\n\n---\n\n## Mailer Usage\n\nPublic API methods:\n\n- send\n- addTo\n- addCc\n- addBcc\n- addReplyTo\n- addRecipient\n- setRecipients\n- setSubject\n- setSender\n- debugMode\n- printResult\n\nThere is no need to metion content type when using Mailer, the content type is automatically detected.\n\n### Mail\n\nNative PHP mail function. To use this class, be sure you have set the settings right in your `php.ini`.\n\n```php\n$mail = new \\Shieldon\\Messenger\\Mail();\n$mail-\u003eaddSender('example.sender@gmail.com');\n$mail-\u003eaddRecipient('example.recipient@gmail.com');\n$mail-\u003esetSubject('Foo, bar.');\n\nif ($mail-\u003esend('say something!')) {\n    echo 'Email has been delivered via PHP\\'s native mail function.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $maingun-\u003eprintResult();\n}\n```\n\n### SMTP\n\nA very simple SMTP client.\n\n```php\n\n$user = 'email@your_domain.com';\n$pass = '12345678';\n$host = '127.0.0.1';\n$port = '25';\n\n$mail = new \\Shieldon\\Messenger\\Smtp($user, $pass, $host, $port);\n\n$mail-\u003eaddSender('email@your_domain.com');\n$mail-\u003eaddRecipient('do-not-reply@gmail.com');\n$mail-\u003esetSubject('Foo, bar.');\n\nif ($mail-\u003esend('say something!')) {\n    echo 'Email has been delivered via SMTP.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $maingun-\u003eprintResult();\n}\n```\n\nNote:\n\nIf you would like to use **SMTPS** or **STARTTLS**, the `$host` should have a prefix. \n\nFor example:\n\n```php\n$host = 'ssl://smtp.gmail.com'; // SMTPS\n$host = 'tls://smtp.gmail.com'; // STARTTLS\n```\n\n### SendGrid\n\nIf you have SendGrid API key, you can also send messages via SendGrid easily.\n\n```php\n$apiKey = 'your_api_key';\n\n$sendgrid = new \\Shieldon\\Messenger\\Sendgrid($apiKey);\n$sendgrid-\u003eaddSender('example.sender@gmail.com');\n$sendgrid-\u003eaddRecipient('example.recipient@gmail.com');\n$sendgrid-\u003esetSubject('Foo, bar.');\n\nif ($sendgrid-\u003esend('say something!')) {\n    echo 'Email has been delivered via SendGrid API.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $maingun-\u003eprintResult();\n}\n```\n\n### MailGun\n\n```php\n$apiKey = 'your_api_key';\n$domain = 'your_domain_name';\n\n$maingun = new \\Shieldon\\Messenger\\Mailgun($apiKey, $domain);\n$maingun-\u003eaddSender('example.sender@gmail.com');\n$maingun-\u003eaddRecipient('example.recipient@gmail.com');\n$maingun-\u003esetSubject('Foo, bar.');\n\nif ($maingun-\u003esend('say something!')) {\n    echo 'Email has been delivered via MailGun API.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $maingun-\u003eprintResult();\n}\n```\n\n### MailGun SMTP\n\nExtended from `Smtp`, a ready-to-use MailGun SMTP client.\n\n```php\n$user = 'your@gmail.com';\n$pass = 'your_password';\n\n$maingun = new \\Shieldon\\Messenger\\Smtp\\Mailgun($user, $pass);\n\n$maingun-\u003eaddSender('example.sender@gmail.com');\n$maingun-\u003eaddRecipient('example.recipient@gmail.com');\n$maingun-\u003esetSubject('Foo, bar.');\n\nif ($maingun-\u003esend('say something!')) {\n    echo 'Email has been delivered via MainGun SMTP server.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $maingun-\u003eprintResult();\n}\n```\n\n### Gmail\n\nExtended from `Smtp`, a ready-to-use Gmail SMTP client.\n\n```php\n$user = 'your@gmail.com';\n$pass = 'your_password';\n\n$gmail = new \\Shieldon\\Messenger\\Smtp\\Gmail($user, $pass);\n\n$gmail-\u003eaddSender('your@gmail.com');\n$gmail-\u003eaddRecipient('test@gmail.com');\n$gmail-\u003esetSubject('Foo, bar.');\n\nif ($gmail-\u003esend('say something!')) {\n    echo 'Email has been delivered via Gmail SMTP server.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $gmail-\u003eprintResult();\n}\n```\n\nNote:\n\nGoogle doesn't like people use their SMTP server to sending email by scripts, to make sure it can work without problems, you have to set the settings right:\n\n- Check your Google Accounts -\u003e Access for less secure apps -\u003e Turn on\n- Use your host where you use to send email with your Google account and confirm that you have trusted the device on.\n\n### Yahoo Mail\n\nExtended from `Smtp`, a ready-to-use Yahoo SMTP client.\n\n\n```php\n$user = 'your@yahoo.com';\n$pass = 'your_password';\n\n$yahooMail = new \\Shieldon\\Messenger\\Smtp\\Yahoo($user, $pass);\n\n$yahooMail-\u003eaddSender('your@yahoo.com');\n$yahooMail-\u003eaddRecipient('test@gmail.com');\n$yahooMail-\u003esetSubject('Foo, bar.');\n\nif ($yahooMail-\u003esend('say something!')) {\n    echo 'Email has been delivered via Yahoo SMTP server.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $yahooMail-\u003eprintResult();\n}\n```\n\nNote: You can use your account password but if you are facing the following error:\n\n```\n(#AUTH005) Too many bad auth attempts error when trying to send email.\n```\n\nThat is because that Yahoo might not allow 3rd-party products access the SMTP server by default. To resolve this problem:\n\n- Go to [Account Security](https://login.yahoo.com/account/security), \n- Under **Manage App password** section, create a password for that App.\n- Use your App password instead of your account password.\n\n\n### Outlook Mail (Office365)\n\nExtended from `Smtp`, a ready-to-use Yahoo SMTP client.\n\n\n```php\n$user = 'your@outlook.com';\n$pass = 'your_password';\n\n$outlook = new \\Shieldon\\Messenger\\Smtp\\Outlook($user, $pass);\n\n$outlook-\u003eaddSender('your@outlook.com');\n$outlook-\u003eaddRecipient('test@gmail.com');\n$outlook-\u003esetSubject('Foo, bar.');\n\nif ($outlook-\u003esend('say something!')) {\n    echo 'Email has been delivered via Office365 SMTP server.';\n} else {\n    echo 'Failed to send email.' . \"\\n\";\n    echo $yahooMail-\u003eprintResult();\n}\n```\n\nNote:\n\nWhen sending email via Office365 SMTP server at the first time, you will receive a notification email from *Outlook.com Team* to confirm your activity.\n\n![](https://i.imgur.com/F4YlKkg.png)\n\nOnce you have completed the validation, you will be able to send email via Office365 SMTP server.\n\n\n---\n\n## Debug\n\n### debugMode()\n\nIf you would like to catch exceptions, you use turn `debugMode` on. This option will throw exceptions when error occurred.\n\nFor example:\n\n```php\n$mail = new \\Shieldon\\Messenger\\Smtp($user, $pass, $host, $port);\n\n$mail-\u003edebugMode(true);\n\n$mail-\u003eaddSender('email@your_domain.com');\n$mail-\u003eaddRecipient('do-not-reply@gmail.com');\n$mail-\u003esetSubject('Foo, bar.');\n\ntry {\n    $mail-\u003esend('say something!');\n\n} catch (Exception $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n\n```\n\n### printResult()\n\nIf you would like to print the executed results, you can use `printResult()`.\n\nFor example:\n\n```php\n$mail = new \\Shieldon\\Messenger\\Smtp($user, $pass, $host, $port);\n$mail-\u003eaddSender('email@your_domain.com');\n$mail-\u003eaddRecipient('do-not-reply@gmail.com');\n$mail-\u003esetSubject('Foo, bar.');\n$mail-\u003esend('say something!');\n\necho $mail-\u003eprintResult();\n```\n\nIf the email is sent successfully, the result will look like the text below:\n\n```\nsuccess: true\nmessage: Email is sent.\n--- result ---\nconnection: 220 smtp.gmail.com ESMTP x11sm6715821pfn.53 - gsmtp\nhello: 250 smtp.gmail.com at your service\nauth_type: 334 VXNlcm5hbWU6\nuser: 334 UGFzc3dvcmQ6\npass: 235 2.7.0 Accepted\nfrom: 250 2.1.0 OK x11sm6715821pfn.53 - gsmtp\nto: 250 2.1.5 OK x11sm6715821pfn.53 - gsmtp\ncc: 250 2.1.5 OK x11sm6715821pfn.53 - gsmtp\nbcc: 250 2.1.5 OK x11sm6715821pfn.53 - gsmtp\ndata: 354 Go ahead x11sm6715821pfn.53 - gsmtp\nsend: 250 2.0.0 OK 1579887885 x11sm6715821pfn.53 - gsmtp\nquit: 221 2.0.0 closing connection x11sm6715821pfn.53 - gsmtp\n```\n\n---\n\n## Author\n\nMessenger library is brought to you by [Terry L.](https://terryl.in) from Taiwan.\n\nShieldon Messenger is initially designed for a part of the [Shieldon Firewall](https://github.com/terrylinooo/shieldon), sending notifications to webmasters or developers when their web applications are possibly under attacks. If you are looking for a web security library to protect your website, Shieldon [Firewall](https://shieldon.io) might be a good choice for you.\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrylinooo%2Fmessenger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterrylinooo%2Fmessenger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrylinooo%2Fmessenger/lists"}