-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
92 lines (79 loc) · 3.76 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
<!DOCTYPE html>
<html>
<head>
<title>Send mail from PHP using SMTP</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<hr>
<?php
if(isset($_POST['sendmail'])) {
require 'PHPMailerAutoload.php';
require 'credential.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = EMAIL; // SMTP username
$mail->Password = PASS; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom(EMAIL, 'litdeveloper');
$mail->addAddress($_POST['email']); // Add a recipient
$mail->addReplyTo(EMAIL);
// print_r($_FILES['file']); exit;
for ($i=0; $i < count($_FILES['file']['tmp_name']) ; $i++) {
$mail->addAttachment($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]); // Optional name
}
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = '<div style="border:2px solid red;">This is the HTML message body <b>in bold!</b></div>'.$_POST['message'];
$mail->AltBody = $_POST['message'];
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
?>
<div class="row">
<div class="col-md-9 col-md-offset-2">
<form role="form" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-9 form-group">
<label for="email">To Email:</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email" maxlength="50">
</div>
</div>
<div class="row">
<div class="col-sm-9 form-group">
<label for="subject">Subject:</label>
<input type="text" class="form-control" id="subject" name="subject" value="Test Mail with attachments" maxlength="50">
</div>
</div>
<div class="row">
<div class="col-sm-9 form-group">
<label for="name">Message:</label>
<textarea class="form-control" type="textarea" id="message" name="message" placeholder="Your Message Here" maxlength="6000" rows="4">Test mail using PHPMailer</textarea>
</div>
</div>
<div class="row">
<div class="col-sm-9 form-group">
<label for="name">File:</label>
<input name="file[]" multiple="multiple" class="form-control" type="file" id="file">
</div>
</div>
<div class="row">
<div class="col-sm-9 form-group">
<button type="submit" name="sendmail" class="btn btn-lg btn-success btn-block">Send</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>