Add files
This commit is contained in:
parent
db00ff2a16
commit
8ed2db3d6d
|
@ -0,0 +1,2 @@
|
|||
# Default ignored files
|
||||
/workspace.xml
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/phpmailer-test.iml" filepath="$PROJECT_DIR$/.idea/phpmailer-test.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"require": {
|
||||
"phpmailer/phpmailer": "^6.0"
|
||||
},
|
||||
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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": []
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
// for testing use only. Please define user, password and host in a config file of your own
|
||||
$mail = new MailWrapper();
|
||||
|
||||
$mail
|
||||
->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 = <<<EOL
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>Hello,</p>
|
||||
<p>This is a sample test message</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
EOL;
|
||||
|
||||
try
|
||||
{
|
||||
$mail->send("Test message", $content);
|
||||
|
||||
}
|
||||
catch (Exception $ex)
|
||||
{
|
||||
echo "Problem while sending mail! " . $ex->getMessage();
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
|
||||
class MailWrapper
|
||||
{
|
||||
|
||||
private $fqm, $host, $protocol, $replyto, $from;
|
||||
|
||||
private $recipient;
|
||||
|
||||
private $mailer;
|
||||
|
||||
private $authpassword;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue