Subversion Repositories cheapmusic

Rev

Rev 73 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
25 - 1
<?php
2
use PHPMailer\PHPMailer\PHPMailer;
3
use PHPMailer\PHPMailer\Exception;
4
 
5
ini_set("log_errors", 1);
31 - 6
ini_set("error_log", $_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/logs/php_error.log");
25 - 7
error_reporting(E_ALL);
8
 
65 - 9
if (!function_exists('PHPMailer_Init')) {
10
    function PHPMailer_Init() {
11
        // Include PHPMailer library files
12
        require 'PHPMailer/Exception.php';
13
        require 'PHPMailer/PHPMailer.php';
14
        require 'PHPMailer/SMTP.php';
15
 
16
        $mail = new PHPMailer;
17
 
18
        return $mail;
19
    }
25 - 20
}
21
 
22
/*
23
 * Reset new password email sender function
65 - 24
*/
25
if (!function_exists('forgotPassEmail')) {
26
    function forgotPassEmail($userData) {
27
        $resetPassLink = BASE_URL . 'resetPassword.php?fp_code=' . $userData['forgot_pass_identity'];
25 - 28
        $to = $userData['email'];
74 - 29
        $subject = "Password Reset Request | " . SITE_NAME;
30
        $mailContent =
31
       '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
        <html xmlns="http://www.w3.org/1999/xhtml">
33
        <head>
34
            <title>Find Cheap Music Password Reset Request</title>
35
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
36
            <meta name="viewport" content="width=device-width" />
37
        </head>
38
        <body>
39
        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-radius:6px;background-color:#ffffff;padding-top:15px;border-collapse:separate">
40
			<tbody>
41
				<tr>
42
					<td style="color:#616471;font-weight:400;text-align:left;line-height:190%;padding-top:15px;padding-right:40px;padding-bottom:30px;padding-left:40px;font-size:15px">
43
					<h1 style="font-weight:500;font-size:22px;letter-spacing:-1px;line-height:115%;margin:18px 0 0;padding:0;text-align:left;color:#3c7bb6">Password Reset Request</h1>
44
					<br/>
45
					<p>Recently a request was submitted to reset a password for your account email ' . $to . '. If this was a mistake, just disregard this email and nothing will happen.</p>
46
                                        <p>To reset your password, visit the following link:</p>
47
					<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse">
48
					<tbody>
49
						<tr>
50
							<td align="center" valign="middle" style="padding-top:25px;padding-right:15px;padding-bottom:25px;padding-left:15px">
51
								<table cellpadding="0" cellspacing="0" border="0" style="border-radius:.25em;background-color:#4582e8;border-collapse:separate">
52
								<tbody>
53
									<tr>
54
										<td align="center" valign="middle" style="border-radius:.25em;background-color:#4582e8;font-weight:400;min-width:180px;font-size:16px;line-height:100%;padding-top:18px;padding-right:30px;padding-bottom:18px;padding-left:30px;color:#ffffff">
55
											<a href="' . $resetPassLink . '" style="font-weight:500;color:#ffffff;text-decoration:none">Reset Password</a>
56
										</td>
57
									</tr>
58
								</tbody>
59
								</table>
60
							</td>
61
						</tr>
62
					</tbody>
63
					</table>
64
					<p>Let us know at customerservice@FindCheapMusic.com in case of any query or feedback.</p>
65
                                        <p>Regards,<br/><strong>' . SITE_NAME . ' Team</strong></p>
66
					</td>
67
				</tr>
68
			</tbody>
69
		 </table>
70
         </body>
71
         </html>';
25 - 72
 
74 - 73
        $mailContentText = "Recently a request was submitted to reset a password for your account. If this was a mistake, just disregard this email and nothing will happen.\r\n\r\n";
25 - 74
        $mailContentText .= "To reset your password, visit the following link:\r\n\r\n$resetPassLink\r\n\r\n";
75
        $mailContentText .= "Let us know at customerservice@FindCheapMusic.com in case of any query or feedback.\r\n";
76
        $mailContentText .= "\r\nRegards,\r\n" . SITE_NAME . " Team";
65 - 77
 
78
        if (SMTP == true) {
79
            $mail = PHPMailer_Init();
80
 
81
            // SMTP configuration
82
            $mail->isSMTP();
83
            $mail->Host = SMTP_HOST;
84
            $mail->SMTPAuth = true;
85
            $mail->Username = SMTP_USERNAME;
86
            $mail->Password = SMTP_PASSWORD;
87
            $mail->SMTPSecure = SMTP_SECURE;
88
            $mail->Port = SMTP_PORT;
89
 
90
            $mail->setFrom(SENDER_EMAIL, SENDER_NAME);
91
 
92
            // Add a recipient
93
            $mail->addAddress($to);
94
 
95
            // Email subject
96
            $mail->Subject = $subject;
97
 
98
            // Set email format to HTML
99
            $mail->isHTML(true);
100
 
101
            // Email body content
102
            $mail->Body = $mailContent;
103
            $mail->AltBody = $mailContentText;
104
 
73 - 105
            // DKIM
106
            $mail->DKIM_domain = DKIM_DOMAIN;
107
            $mail->DKIM_private = $_SERVER['DOCUMENT_ROOT'] . DKIM_PRIVATE;
108
            $mail->DKIM_selector = DKIM_SELECTOR;
109
            $mail->DKIM_passphrase = DKIM_PASSPHRASE;
110
            $mail->DKIM_identity = $mail->From;
111
            $mail->DKIM_copyHeaderFields = false;
112
            $mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
113
 
65 - 114
            // Send email
115
            if (!$mail->send()) {
116
                error_log('Mailer error: ' . $mail->ErrorInfo);
117
            }
118
        }
119
        else {
120
            //set content-type header for sending HTML email
121
            $headers = "MIME-Version: 1.0" . "\r\n";
122
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
123
            //additional headers
124
            $headers .= 'From: ' . SENDER_NAME . '<' . SENDER_EMAIL . '>' . "\r\n";
125
            //send email
126
            mail($to, $subject, $mailContent, $headers);
127
        }
25 - 128
        return true;
129
    }
130
}
131
 
132
/*
133
 * Account verification email sender function
65 - 134
*/
135
if (!function_exists('emailVerification')) {
136
    function emailVerification($userData) {
74 - 137
        $emailVerifyLink = BASE_URL . 'userAccount.php?verifyEmail=1&amp;ac_code=' . $userData['activation_code'];
25 - 138
        $to = $userData['email'];
65 - 139
        $subject = "Please Confirm Your Email | " . SITE_NAME;
74 - 140
        $mailContent =
141
       '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
142
        <html xmlns="http://www.w3.org/1999/xhtml">
143
        <head>
144
            <title>Find Cheap Music Email Confirmation</title>
145
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
146
            <meta name="viewport" content="width=device-width" />
147
        </head>
148
        <body>
149
        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-radius:6px;background-color:#ffffff;padding-top:15px;border-collapse:separate">
25 - 150
			<tbody>
151
				<tr>
152
					<td style="color:#616471;font-weight:400;text-align:left;line-height:190%;padding-top:15px;padding-right:40px;padding-bottom:30px;padding-left:40px;font-size:15px">
153
					<h1 style="font-weight:500;font-size:22px;letter-spacing:-1px;line-height:115%;margin:18px 0 0;padding:0;text-align:left;color:#3c7bb6">Email Confirmation</h1>
74 - 154
					<br/>
155
					Thank you for signing up with Find Cheap Music! Please confirm your email address ' . $to . ' by clicking the link below.
156
					<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse">
25 - 157
					<tbody>
158
						<tr>
74 - 159
							<td align="center" valign="middle" style="padding-top:25px;padding-right:15px;padding-bottom:25px;padding-left:15px">
160
								<table cellpadding="0" cellspacing="0" border="0" style="border-radius:.25em;background-color:#4582e8;border-collapse:separate">
25 - 161
								<tbody>
162
									<tr>
74 - 163
										<td align="center" valign="middle" style="border-radius:.25em;background-color:#4582e8;font-weight:400;min-width:180px;font-size:16px;line-height:100%;padding-top:18px;padding-right:30px;padding-bottom:18px;padding-left:30px;color:#ffffff">
65 - 164
											<a href="' . $emailVerifyLink . '" style="font-weight:500;color:#ffffff;text-decoration:none">Confirm Email</a>
25 - 165
										</td>
166
									</tr>
167
								</tbody>
168
								</table>
169
							</td>
170
						</tr>
171
					</tbody>
172
					</table>
74 - 173
					We look forward to serving you,<br/><strong>' . SITE_NAME . ' Team</strong>
25 - 174
					</td>
175
				</tr>
176
			</tbody>
74 - 177
		 </table>
178
         </body>
179
         </html>';
25 - 180
 
181
        $mailContentText = "Thank you for signing up with Find Cheap Music! Please confirm your email address via this link:\r\n\r\n$emailVerifyLink\r\n\r\n";
182
        $mailContentText .= "\r\nWe look forward to serving you,\r\n" . SITE_NAME . " Team";
183
 
65 - 184
        if (SMTP == true) {
185
            $mail = PHPMailer_Init();
186
 
187
            // SMTP configuration
188
            $mail->isSMTP();
189
            $mail->CharSet = "text/html; charset=UTF-8;";
190
            $mail->WordWrap = 80;
191
            $mail->Host = SMTP_HOST;
192
            $mail->SMTPAuth = true;
193
            $mail->Username = SMTP_USERNAME;
194
            $mail->Password = SMTP_PASSWORD;
195
            $mail->SMTPSecure = SMTP_SECURE;
196
            $mail->Port = SMTP_PORT;
197
 
198
            $mail->setFrom(SENDER_EMAIL, SENDER_NAME);
199
 
200
            // Add a recipient
201
            $mail->addAddress($to);
202
 
203
            // Email subject
204
            $mail->Subject = $subject;
205
 
206
            // Set email format to HTML
207
            $mail->isHTML(true);
208
 
209
            // Email body content
210
            $mail->Body = $mailContent;
211
            $mail->AltBody = $mailContentText;
212
 
73 - 213
            // DKIM
214
            $mail->DKIM_domain = DKIM_DOMAIN;
215
            $mail->DKIM_private = $_SERVER['DOCUMENT_ROOT'] . DKIM_PRIVATE;
216
            $mail->DKIM_selector = DKIM_SELECTOR;
217
            $mail->DKIM_passphrase = DKIM_PASSPHRASE;
218
            $mail->DKIM_identity = $mail->From;
219
            $mail->DKIM_copyHeaderFields = false;
220
            $mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
221
 
65 - 222
            // Send email
223
            if (!$mail->send()) {
224
                error_log('Mailer error: ' . $mail->ErrorInfo);
225
            }
226
        }
227
        else {
228
            //set content-type header for sending HTML email
229
            $headers = "MIME-Version: 1.0" . "\r\n";
230
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
231
            //additional headers
232
            $headers .= 'From: ' . SENDER_NAME . '<' . SENDER_EMAIL . '>' . "\r\n";
233
            //send email
234
            mail($to, $subject, $mailContent, $headers);
235
        }
25 - 236
        return true;
237
    }
31 - 238
}