-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cfm
174 lines (158 loc) · 5.71 KB
/
main.cfm
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
<!---
Creating Co. : Hostek.com
Programmed by: Kaleb L.
Creation Date: 11/15/2014
--->
<!--- Include nav header --->
<cfinclude template="header.cfm" >
<div class="wrapper">
<style type="text/css">
td {
padding: 10px;
}
</style>
<!--- Check to see if the form struct exists --->
<cfif #StructKeyExists(form, "FromEmail")# >
<cfif Len(Form.EmailHost)>
<cfif Len(Form.SmtpPort)>
<cfif Len(Form.FromEmail)>
<cfif Len(Form.EmailPassword)>
<cfif Len(Form.MessageUsed)>
<cfquery datasource="#Application.DSN#" name="MailerSettings">
UPDATE mailersettings SET SMTPHost='#Form.EmailHost#', SMTPPort=#Form.SmtpPort#, SMTPAddress='#Form.FromEmail#', SMTPPassword='#Form.EmailPassword#'
</cfquery>
<!--- Call all the subscribers from the database --->
<cfquery datasource="#Application.DSN#" name="subscribers" timeout="6000000">
SELECT Email FROM mailersubscribers
</cfquery>
<!--- Reset SentMessages to 0 for stats on the new job --->
<cfquery datasource="#Application.DSN#" name="MailerStats" timeout="6000000">
UPDATE `mailerstats` SET `SentMessages`= 0
</cfquery>
<!--- Call the template into query struct --->
<cfquery datasource="#Application.DSN#" name="MailerTemplate" timeout="6000000">
SELECT * FROM mailertemplates Where ID=<cfqueryPARAM value = "#MessageUsed#"
CFSQLType = 'CF_SQL_INTEGER'>
</cfquery>
<!--- Save the needed variables from the query struct --->
<cfoutput query="MailerTemplate">
<cfset Body = #Body# />
<cfset Subject = #Subject# />
</cfoutput>
<!--- Loop through all the subscribers called from the database --->
<cfloop query="subscribers">
<cfoutput>
<cfmail
from="#Form.FromEmail#"
subject="#Subject#"
to="#Email#"
server="#Form.EmailHost#"
port="#Form.SmtpPort#"
useSSL="#Form.UseSSL#"
username="#Form.FromEmail#"
password="#Form.EmailPassword#"
type="#Form.MessageType#"
timeout="6000000" >#Body#</cfmail>
</cfoutput>
<!--- Add +1 to SentMessages for each email that is sent to a subscriber --->
<cfquery datasource="#Application.DSN#" name="MailerStats" timeout="6000000">
UPDATE `mailerstats` SET `SentMessages`=`SentMessages` + 1
</cfquery>
</cfloop>
<cfoutput>
<br /><div class="alert alert-success" style="text-align: center;" role="alert">Email sent to <strong>#subscribers.RecordCount#</strong> contacts!</div><br />
</cfoutput>
<cfelse>
<div class="alert alert-danger center" role="alert">A Template could not be found. Please ensure that you have created one.</div>
</cfif>
<cfelse>
<div class="alert alert-danger center" role="alert">The SMTP Password has not been defined. Please do so.</div>
</cfif>
<cfelse>
<div class="alert alert-danger center" role="alert">The SMTP User has not been defined. Please do so.</div>
</cfif>
<cfelse>
<div class="alert alert-danger center" role="alert">The SMTP Port has not been defined. Please do so.</div>
</cfif>
<cfelse>
<div class="alert alert-danger center" role="alert">The SMTP Host has not been defined. Please do so.</div>
</cfif>
</cfif>
<!--- Initial queries to the database --->
<cfquery datasource="#Application.DSN#" name="MailerSettings">
SELECT * FROM mailersettings
</cfquery>
<cfquery datasource="#Application.DSN#" name="MailerTemplates">
SELECT * FROM mailertemplates
</cfquery>
<!--- Main form for sending to the email list --->
<form action="" method="post" role="form">
<!--- SMTP settings for the mailer to use --->
<cfoutput>
<table style="width: 800px;">
<tr>
<td>
<strong>SMTP Host</strong><br />
<input type="text" name="EmailHost" class="form-control" value="#MailerSettings.SMTPHost#" />
</td>
<td>
<strong>SMTP Port</strong><br />
<input type="text" name="SmtpPort" class="form-control" value="#MailerSettings.SMTPPort#" />
</td>
</tr>
<tr>
<td>
<strong>SMTP User (Email Address)</strong><br />
<input type="text" name="FromEmail" class="form-control" value="#MailerSettings.SMTPAddress#" />
</td>
<td>
<strong>SMTP Password</strong><br />
<input type="password" name="EmailPassword" class="form-control" value="#MailerSettings.SMTPPassword#" />
</td>
</tr>
<tr>
<td>
<strong>Use SSL</strong><br />
<select class="form-control" name="UseSSL">
<option value="false">False</option>
<option value="true">True</option>
</select>
</td>
<td>
<strong>Message Type</strong><br />
<select class="form-control" name="MessageType">
<option value="html">HTML</option>
<option value="text">Plain Text</option>
</select>
</td>
</tr>
<tr>
<td><br />
</td>
</tr>
<!--- Message fields to form the message that will be sent --->
<tr>
<td>
<cfif #MailerTemplates.RecordCount# GT 0>
<strong>Select Template to Send</strong><br />
<select class="form-control" name="MessageUsed">
<cfoutput query="MailerTemplates">
<option value="#ID#">#Subject#</option>
</cfoutput>
</select>
<cfelse>
<div class="alert alert-danger center" role="alert">No Templates Avalible</div>
<input type="hidden" name="MessageUsed" value="" />
</cfif>
</td>
</tr>
<tr>
<td>
<!--- Button to send the mail --->
<input class="btn btn-success" type="submit" value="Send" name="Send" style="width: 100%;">
</td>
</tr>
</table>
</cfoutput>
</form>
</div>