diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9986dee --- /dev/null +++ b/.gitignore @@ -0,0 +1,198 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/windows,linux,macos,phpstorm,netbeans,composer +# Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,macos,phpstorm,netbeans,composer + +### Composer ### +composer.phar +/lib_ext/ + +# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### NetBeans ### +**/nbproject/private/ +**/nbproject/Makefile-*.mk +**/nbproject/Package-*.bash +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +### PhpStorm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ +.idea +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PhpStorm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos,phpstorm,netbeans,composer \ No newline at end of file diff --git a/README.md b/README.md index beca008..809fc08 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,44 @@ -# notification -This is a library that uses composer as the basis for generating email notifications +# Notification library via email using phpMailer + +This library has the function of sending e-mail using the phpmailer library. Doing this in an uncomplicated way is essential for any system. + +To install the library, run the following command: + +``` sh +composer require gustavoweb/composer_teste +``` + +To use the library, simply require the composer to autoload, invoke the class and call the method: + +``` sh + sendEmail ("Subject", "Content", "reply@email.com", "Replay Name", "address@email.com", "Address Name"); +``` + +Note that the entire configuration of sending the email is using the magic method builder! Once the builder method has been invoked within your application, your system will be able to take the shots. + +### Developers +* [Gustavo Web] - Developer of this library and tutor of the Composer na PrĂ¡tica course! +* [Robson V. Leite] - CEO and Founder UpInside Trainamentos +* [UpInside Treinamentos] - Official website of your digital marketing and programming school +* [phpMailer] - Lib to send E-mail + +License +---- + +MIT + +** Another UpInside Training course, make good use of it! ** + +[//]: # +[Gustavo Web]: +[Robson V. Leite]: +[UpInside Treinamentos]: +[phpMailer]: \ No newline at end of file diff --git a/_app/Email.php b/_app/Email.php new file mode 100644 index 0000000..b4471e2 --- /dev/null +++ b/_app/Email.php @@ -0,0 +1,43 @@ +mail = new PHPMailer(true); + $this->mail->SMTPDebug = $smtpDebug; // Enable verbose debug output + $this->mail->isSMTP(); // Send using SMTP + $this->mail->Host = $host; // Set the SMTP server to send through + $this->mail->SMTPAuth = true; // Enable SMTP authentication + $this->mail->Username = $user; // SMTP username + $this->mail->Password = $pass; // SMTP password + $this->mail->SMTPSecure = $smtpSecure; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged + $this->mail->Port = $port; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above + $this->mail->CharSet = 'utf-8'; + $this->mail->setLanguage('br'); + $this->mail->isHTML(true); + $this->mail->setFrom($setFromEmail, $setFromName); + } + + public function sendMail($subject, $body, $replyEmail, $replyName, $addressEmail, $addressName) + { + $this->mail->Subject = (string)$subject; + $this->mail->Body = $body; + + $this->mail->addReplyTo($replyEmail, $replyName); + $this->mail->addAddress($addressEmail, $addressName); + + try { + $this->mail->send(); + } catch (Exception $e) { + echo "Erro ao enviar o e-mail: {$this->mail->ErrorInfo} {$e->getMessage()}"; + } + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..723d599 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "rogarfil/notification", + "description": "This is a library that uses composer as the basis for generating email notifications", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "rogarfil", + "email": "rogarfil@yahoo.com.br", + "homepage": "http://www.rogarfil.com.br", + "role": "Developer" + } + ], + "minimum-stability": "dev", + "require": { + "phpmailer/phpmailer": "6.1.4" + }, + "config": { + "vendor-dir": "lib_ext" + }, + "autoload": { + "psr-4": { + "Notification\\": "_app" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..da8fef3 --- /dev/null +++ b/composer.lock @@ -0,0 +1,85 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "e529c1e23b142ce0daa64236a726a272", + "packages": [ + { + "name": "phpmailer/phpmailer", + "version": "v6.1.4", + "source": { + "type": "git", + "url": "https://github.com/PHPMailer/PHPMailer.git", + "reference": "c5e61d0729507049cec9673aa1a679f9adefd683" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/c5e61d0729507049cec9673aa1a679f9adefd683", + "reference": "c5e61d0729507049cec9673aa1a679f9adefd683", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-filter": "*", + "php": ">=5.5.0" + }, + "require-dev": { + "doctrine/annotations": "^1.2", + "friendsofphp/php-cs-fixer": "^2.2", + "phpunit/phpunit": "^4.8 || ^5.7" + }, + "suggest": { + "ext-mbstring": "Needed to send email in multibyte encoding charset", + "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", + "league/oauth2-google": "Needed for Google XOAUTH2 authentication", + "psr/log": "For optional PSR-3 debug logging", + "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication", + "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPMailer\\PHPMailer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-only" + ], + "authors": [ + { + "name": "Marcus Bointon", + "email": "phpmailer@synchromedia.co.uk" + }, + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, + { + "name": "Andy Prevost", + "email": "codeworxtech@users.sourceforge.net" + }, + { + "name": "Brent R. Matzelle" + } + ], + "description": "PHPMailer is a full-featured email creation and transfer class for PHP", + "support": { + "issues": "https://github.com/PHPMailer/PHPMailer/issues", + "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.1.4" + }, + "time": "2019-12-10T11:17:38+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.0.0" +} diff --git a/test/index.php b/test/index.php new file mode 100644 index 0000000..19389b4 --- /dev/null +++ b/test/index.php @@ -0,0 +1,11 @@ +sendEmail("Subject", "Content", "reply@email.com", "Replay Name", "address@email.com", "Address Name"); + +var_dump($email); \ No newline at end of file