Skip to content

Commit d828729

Browse files
committed
PHP Mail System
0 parents  commit d828729

File tree

7 files changed

+6838
-0
lines changed

7 files changed

+6838
-0
lines changed

index.html

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Mail System</title>
6+
<!-- Required meta tags -->
7+
<meta charset="utf-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
9+
10+
<!-- Bootstrap CSS -->
11+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
12+
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
13+
</head>
14+
15+
<body>
16+
<div class="container">
17+
<h1 class="display-1 text-center">PHP Mail System</h1>
18+
<div class="row justify-content-center">
19+
<div class="col-md-6 col-md-offset-3">
20+
<form action="mailconfig.php" method="post">
21+
<div class="form-group">
22+
<label for="name">Name</label>
23+
<input type="text" class="form-control" name="name" placeholder="Enter Name" required>
24+
</div>
25+
<div class="form-group">
26+
<label for="email"> Email</label>
27+
<input type="email" class="form-control" name="email" required placeholder="Enter Email">
28+
</div>
29+
<div class="form-group">
30+
<label for="subject">Subject</label>
31+
<input type="text" class="form-control" name="subject" placeholder="Enter Subject" required>
32+
</div>
33+
<div class="form-group">
34+
<label for="message">Message</label>
35+
<textarea class="form-control" name="message" style="resize: none;" rows=" 3"
36+
placeholder="Enter Message" required></textarea>
37+
</div>
38+
<button type="submit" name="submit" id="submit" class="btn btn-primary btn-block">Send Mail</button>
39+
</form>
40+
</div>
41+
</div>
42+
</div>
43+
<!-- Optional JavaScript -->
44+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
45+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
46+
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
47+
</script>
48+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
49+
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
50+
</script>
51+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
52+
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
53+
</script>
54+
</body>
55+
56+
</html>

mailconfig.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use PHPMailer\PHPMailer\PHPMailer;
4+
5+
if (isset($_POST['name']) && isset($_POST['email'])) {
6+
$name = $_POST['name'];
7+
$email = $_POST['email'];
8+
$subject = $_POST['subject'];
9+
$message = $_POST['message'];
10+
11+
require_once "phpmailer/PHPMailer.php";
12+
require_once "phpmailer/SMTP.php";
13+
require_once "phpmailer/Exception.php";
14+
15+
$mail = new PHPMailer();
16+
17+
// SMTP Settings
18+
$mail->isSMTP();
19+
$mail->Host = "smtp.gmail.com";
20+
$mail->SMTPAuth = true;
21+
$mail->Username = $senderemail;
22+
$mail->Password = $senderpassword;
23+
$mail->Port = 465; //587
24+
$mail->SMTPSecure = "ssl"; //tls
25+
26+
//Email Settings
27+
$mail->isHTML(true);
28+
$mail->setFrom($email, $name);
29+
$mail->addAddress($email);
30+
$mail->Subject = $subject;
31+
$mail->Body = $message;
32+
33+
if ($mail->send()) {
34+
echo "Email sent successfully to " . $email;
35+
} else {
36+
echo "Something is wrong: <br><br>" . $mail->ErrorInfo;
37+
}
38+
}

phpmailer/Exception.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* PHPMailer Exception class.
4+
* PHP Version 5.5.
5+
*
6+
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
7+
*
8+
* @author Marcus Bointon (Synchro/coolbru) <[email protected]>
9+
* @author Jim Jagielski (jimjag) <[email protected]>
10+
* @author Andy Prevost (codeworxtech) <[email protected]>
11+
* @author Brent R. Matzelle (original founder)
12+
* @copyright 2012 - 2017 Marcus Bointon
13+
* @copyright 2010 - 2012 Jim Jagielski
14+
* @copyright 2004 - 2009 Andy Prevost
15+
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
16+
* @note This program is distributed in the hope that it will be useful - WITHOUT
17+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18+
* FITNESS FOR A PARTICULAR PURPOSE.
19+
*/
20+
21+
namespace PHPMailer\PHPMailer;
22+
23+
/**
24+
* PHPMailer exception handler.
25+
*
26+
* @author Marcus Bointon <[email protected]>
27+
*/
28+
class Exception extends \Exception
29+
{
30+
/**
31+
* Prettify error message output.
32+
*
33+
* @return string
34+
*/
35+
public function errorMessage()
36+
{
37+
return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
38+
}
39+
}

phpmailer/OAuth.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* PHPMailer - PHP email creation and transport class.
4+
* PHP Version 5.5.
5+
*
6+
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
7+
*
8+
* @author Marcus Bointon (Synchro/coolbru) <[email protected]>
9+
* @author Jim Jagielski (jimjag) <[email protected]>
10+
* @author Andy Prevost (codeworxtech) <[email protected]>
11+
* @author Brent R. Matzelle (original founder)
12+
* @copyright 2012 - 2015 Marcus Bointon
13+
* @copyright 2010 - 2012 Jim Jagielski
14+
* @copyright 2004 - 2009 Andy Prevost
15+
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
16+
* @note This program is distributed in the hope that it will be useful - WITHOUT
17+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18+
* FITNESS FOR A PARTICULAR PURPOSE.
19+
*/
20+
21+
namespace PHPMailer\PHPMailer;
22+
23+
use League\OAuth2\Client\Grant\RefreshToken;
24+
use League\OAuth2\Client\Provider\AbstractProvider;
25+
use League\OAuth2\Client\Token\AccessToken;
26+
27+
/**
28+
* OAuth - OAuth2 authentication wrapper class.
29+
* Uses the oauth2-client package from the League of Extraordinary Packages.
30+
*
31+
* @see http://oauth2-client.thephpleague.com
32+
*
33+
* @author Marcus Bointon (Synchro/coolbru) <[email protected]>
34+
*/
35+
class OAuth
36+
{
37+
/**
38+
* An instance of the League OAuth Client Provider.
39+
*
40+
* @var AbstractProvider
41+
*/
42+
protected $provider;
43+
44+
/**
45+
* The current OAuth access token.
46+
*
47+
* @var AccessToken
48+
*/
49+
protected $oauthToken;
50+
51+
/**
52+
* The user's email address, usually used as the login ID
53+
* and also the from address when sending email.
54+
*
55+
* @var string
56+
*/
57+
protected $oauthUserEmail = '';
58+
59+
/**
60+
* The client secret, generated in the app definition of the service you're connecting to.
61+
*
62+
* @var string
63+
*/
64+
protected $oauthClientSecret = '';
65+
66+
/**
67+
* The client ID, generated in the app definition of the service you're connecting to.
68+
*
69+
* @var string
70+
*/
71+
protected $oauthClientId = '';
72+
73+
/**
74+
* The refresh token, used to obtain new AccessTokens.
75+
*
76+
* @var string
77+
*/
78+
protected $oauthRefreshToken = '';
79+
80+
/**
81+
* OAuth constructor.
82+
*
83+
* @param array $options Associative array containing
84+
* `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements
85+
*/
86+
public function __construct($options)
87+
{
88+
$this->provider = $options['provider'];
89+
$this->oauthUserEmail = $options['userName'];
90+
$this->oauthClientSecret = $options['clientSecret'];
91+
$this->oauthClientId = $options['clientId'];
92+
$this->oauthRefreshToken = $options['refreshToken'];
93+
}
94+
95+
/**
96+
* Get a new RefreshToken.
97+
*
98+
* @return RefreshToken
99+
*/
100+
protected function getGrant()
101+
{
102+
return new RefreshToken();
103+
}
104+
105+
/**
106+
* Get a new AccessToken.
107+
*
108+
* @return AccessToken
109+
*/
110+
protected function getToken()
111+
{
112+
return $this->provider->getAccessToken(
113+
$this->getGrant(),
114+
['refresh_token' => $this->oauthRefreshToken]
115+
);
116+
}
117+
118+
/**
119+
* Generate a base64-encoded OAuth token.
120+
*
121+
* @return string
122+
*/
123+
public function getOauth64()
124+
{
125+
// Get a new token if it's not available or has expired
126+
if (null === $this->oauthToken || $this->oauthToken->hasExpired()) {
127+
$this->oauthToken = $this->getToken();
128+
}
129+
130+
return base64_encode(
131+
'user=' .
132+
$this->oauthUserEmail .
133+
"\001auth=Bearer " .
134+
$this->oauthToken .
135+
"\001\001"
136+
);
137+
}
138+
}

0 commit comments

Comments
 (0)