-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
193 lines (160 loc) · 8.69 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/*PHPMAILER*/
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require __DIR__.'/phpmailer/src/Exception.php';
require __DIR__.'/phpmailer/src/PHPMailer.php';
require __DIR__.'/phpmailer/src/SMTP.php';
function getPost($name){
if(!isset($_POST[$name])){
return '';
}
return $_POST[$name];
}
//set default data
if(!isset($_POST['mail_send'])){
$_POST['from-email'] = '[email protected]';
$_POST['from-email-name'] = 'Max Mustermann';
$_POST['to-email'] = '[email protected]';
$_POST['to-email-name'] = 'Maria Musterfrau';
$_POST['username'] = 'user';
$_POST['password'] = '********';
$_POST['port'] = '587';
$_POST['security'] = 'tls';
$_POST['host'] = 'smtp.google.com';
$_POST['subject'] = 'Test Email via SMTP using PHPMailer';
$_POST['message_is_html'] = 'yes';
$_POST['message'] = "<h1>Send HTML Email using SMTP in PHP</h1>
<p>This is a test email I’m sending using SMTP mail server with PHPMailer.</p>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TEST EMAIL SMTP</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS only -->
<!-- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> -->
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-2 col-12"></div>
<div class="col-md-8 col-12 py-5">
<h3>TEST SMTP DATA</h3>
<p class="text-muted">Use this to test your SMTP Connection Data</p>
<p>
<a href="https://github.com/harrowmykel/Email-SMTP-Data-Test-With-PHPMailer" class="text-muted" target="_blank">
Click here to view the code on Github
</a>
</p>
<?php
if(isset($_POST['mail_send'])){
$mail = new PHPMailer();
$mail->isSMTP();
//remove debug
$mail->SMTPDebug = 1;
$mail->Host = getPost('host');
$mail->SMTPAuth = true;
$mail->Username = getPost('username');
$mail->Password = getPost('password');
$mail->SMTPSecure = getPost('security');
$mail->Port = getPost('port');
$mail->setFrom(getPost('from-email'), getPost('from-email-name'));
$mail->addReplyTo(getPost('from-email'), getPost('from-email-name'));
$mail->addAddress(getPost('to-email'), getPost('to-email-name'));
$mail->Subject = getPost('subject');
$mail->isHTML( getPost('message_is_html') != 'no' );
$mailContent = getPost('message');
$mail->Body = $mailContent;
if($mail->send()){
?>
<div class="alert alert-success"> Message has been sent </div>
<?php
}else{
?>
<div class="alert alert-warning">
Message could not be sent. <br/> Mailer Error:
<?php echo $mail->ErrorInfo; ?>
</div>
<?php
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="input-group-bl mb-3">
<span class="input-placeholder">Username</span>
<input type="text" class="form-control" placeholder="Username" name="username" value="<?= getPost('username'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Password</span>
<input type="text" class="form-control" placeholder="Password" name="password" value="<?= getPost('password'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Host</span>
<input type="text" class="form-control" placeholder="HOST" name="host" value="<?= getPost('host'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Port (common ports are 25, 465, 587, or 2525)</span>
<input type="text" class="form-control" placeholder="Port" name="port" value="<?= getPost('port'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Security</span>
<select class="form-select" name="security">
<option value="tls" <?= getPost('security') == 'tls'?'selected':''; ?> >TLS</option>
<option value="ssl" <?= getPost('security') == 'ssl'?'selected':''; ?>>SSL</option>
</select>
<!-- <input type="text" class="form-control" placeholder="Security" name="security" value="<?= getPost('security'); ?>"> -->
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">From E-Mail</span>
<input type="text" class="form-control" placeholder="From Email" name="from-email" value="<?= getPost('from-email'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Sender Name</span>
<input type="text" class="form-control" placeholder="From Email Name" name="from-email-name" value="<?= getPost('from-email-name'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">To E-Mail</span>
<input type="text" class="form-control" placeholder="To Email" name="to-email" value="<?= getPost('to-email'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Recipient Name</span>
<input type="text" class="form-control" placeholder="Recipient Name" name="to-email-name" value="<?= getPost('to-email-name'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Subject</span>
<input type="text" class="form-control" placeholder="Subject" name="subject" value="<?= getPost('subject'); ?>">
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Is HTML Message?</span>
<select class="form-select" name="message_is_html">
<option value="yes" <?= getPost('message_is_html') == 'yes'?'selected':''; ?> >YES</option>
<option value="no" <?= getPost('message_is_html') == 'no'?'selected':''; ?>>NO</option>
</select>
</div>
<div class="input-group-bl mb-3">
<span class="input-placeholder">Message</span>
<textarea class="form-control" style="min-height: 100px;" placeholder="Message" name="message"><?= getPost('message'); ?></textarea>
</div>
<input class="btn btn-sm btn-success" type="submit" name="mail_send" value=" Send Test Email">
</form>
</div>
<div class="col-md-2 col-12"></div>
</div>
<div class="row mt-4 mb-3">
<div class="col-12 px-2 text-center">
<small>
2021 · With Love from <a class="text-dark" href="https://aro-micheal.piccmaq.com.ng/" target="_blank">Aro Micheal</a> | Using
<a class="text-dark" href="https://getbootstrap.com/" target="_blank">Bootstrap</a> &
<a class="text-dark" href="https://github.com/PHPMailer/PHPMailer/" target="_blank">PHPMailer</a> ·
<a class="text-primary" href="https://aro-micheal.piccmaq.com.ng/privacy-policy/" target="_blank">Privacy Policy</a>
</small>
</div>
</div>
</div>
</body>
</html>