From 8ed2db3d6d9112a85f8fdbb6687b5a32d0e88a99 Mon Sep 17 00:00:00 2001 From: Miguel N Date: Sun, 15 Sep 2019 18:08:44 +0100 Subject: [PATCH] Add files --- .idea/.gitignore | 2 + .idea/misc.xml | 6 ++ .idea/modules.xml | 8 +++ .idea/phpmailer-test.iml | 8 +++ .idea/vcs.xml | 6 ++ composer.json | 11 ++++ composer.lock | 84 ++++++++++++++++++++++++++ index.php | 40 ++++++++++++ src/MailWrapper.php | 127 +++++++++++++++++++++++++++++++++++++++ 9 files changed, 292 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/phpmailer-test.iml create mode 100644 .idea/vcs.xml create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 index.php create mode 100644 src/MailWrapper.php diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3248ba0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/phpmailer-test.iml b/.idea/phpmailer-test.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/phpmailer-test.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e4c08e5 --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "require": { + "phpmailer/phpmailer": "^6.0" + }, + + "autoload": { + "classmap": [ + "src/" + ] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..c6a0e55 --- /dev/null +++ b/composer.lock @@ -0,0 +1,84 @@ +{ + "_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": "6d67203b6e9fc952ae681c538683a497", + "packages": [ + { + "name": "phpmailer/phpmailer", + "version": "v6.0.7", + "source": { + "type": "git", + "url": "https://github.com/PHPMailer/PHPMailer.git", + "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/0c41a36d4508d470e376498c1c0c527aa36a2d59", + "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-filter": "*", + "php": ">=5.5.0" + }, + "require-dev": { + "doctrine/annotations": "1.2.*", + "friendsofphp/php-cs-fixer": "^2.2", + "phpdocumentor/phpdocumentor": "2.*", + "phpunit/phpunit": "^4.8 || ^5.7", + "zendframework/zend-eventmanager": "3.0.*", + "zendframework/zend-i18n": "2.7.3", + "zendframework/zend-serializer": "2.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" + ], + "authors": [ + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, + { + "name": "Marcus Bointon", + "email": "phpmailer@synchromedia.co.uk" + }, + { + "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", + "time": "2019-02-01T15:04:28+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..b5eeb66 --- /dev/null +++ b/index.php @@ -0,0 +1,40 @@ +setHost("smtp.spacejewel-hosting.com") // can be anything that has a mail server + ->setProtocol("tls") // auto sets the port + ->setAuthPassword("examplepassword") + ->setFullyQualifiedAddress("exampleuser") + ->setRecipient("johndoe@example.com") + ->setReplyto("someone@example.com") + ->setFrom("someone@example.com") + ->prepare(); + +$content = << + + + + + +

Hello,

+

This is a sample test message

+ + + +EOL; + +try +{ + $mail->send("Test message", $content); + +} +catch (Exception $ex) +{ + echo "Problem while sending mail! " . $ex->getMessage(); +} diff --git a/src/MailWrapper.php b/src/MailWrapper.php new file mode 100644 index 0000000..2da1186 --- /dev/null +++ b/src/MailWrapper.php @@ -0,0 +1,127 @@ +mailer = new PHPMailer(true); + + + + } + + + public function prepare() + { + $this->mailer->SMTPDebug = 2; + $this->mailer->isSMTP(); + $this->mailer->Host = $this->host; + $this->mailer->SMTPAuth = true; + $this->mailer->Username = $this->fqm; + $this->mailer->Password = $this->authpassword; + $this->mailer->SMTPSecure = $this->protocol; + $this->mailer->Port = ($this->protocol == "tls") ? '587' : '465'; + + $this->mailer->setFrom($this->from); + $this->mailer->addAddress($this->recipient); + $this->mailer->addReplyTo($this->replyto); + + $this->mailer->isHTML(true); + + } + + + /** + * @param mixed $fqm + */ + public function setFullyQualifiedAddress($fqm) + { + $this->fqm = $fqm; + return $this; + } + + + /** + * @param mixed $from + */ + public function setFrom($from) + { + $this->from = $from; + return $this; + } + + /** + * @param mixed $host + */ + public function setHost($host) + { + $this->host = $host; + return $this; + } + + /** + * @param mixed $protocol + */ + public function setProtocol($protocol) + { + $this->protocol = $protocol; + return $this; + } + + /** + * @param mixed $recipient + */ + public function setRecipient($recipient) + { + $this->recipient = $recipient; + return $this; + } + + /** + * @param mixed $replyto + */ + public function setReplyto($replyto) + { + $this->replyto = $replyto; + return $this; + } + + public function setAuthPassword($authpassword) + { + $this->authpassword = $authpassword; + return $this; + } + + + public function send($subject, $content) + { + $this->mailer->Subject = $subject; + $this->mailer->Body = $content; + + try + { + $this->mailer->send(); + + return true; + } + catch (\Exception $ex) + { + echo "Could not send email! " . $ex->getMessage(); + } + + + } + +}