Subversion Repositories cheapmusic

Rev

Rev 65 | Rev 74 | 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'];
65 - 29
        $subject = "Password Update Request | " . SITE_NAME;
25 - 30
        $mailContent = '<html><head><title>Find Cheap Music Password Update Request</title>
31
                        </head>
32
                        <body><p>Dear ' . $userData['first_name'] . ',</p>
33
        <p>Recently a request was submitted to reset a password for your account. If this was a mistake, just ignore this email and nothing will happen.</p>
34
        <p>To reset your password, visit the following link:</p>
73 - 35
	<table style="width:100%;border-style: none;border-radius:.25em;background-color:#4582e8;border-collapse:separate">
25 - 36
	<tbody>
37
		<tr>
73 - 38
			<td style="text-align:center;vertical-align:middle;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 - 39
				<a href="' . $resetPassLink . '" style="font-weight:500;color:#ffffff;text-decoration:none">Reset Password</a>
25 - 40
			</td>
41
		</tr>
42
	</tbody>
43
	</table>
44
        <p>Let us know at customerservice@FindCheapMusic.com in case of any query or feedback.</p>
65 - 45
        <p>Regards,<br/><strong>' . SITE_NAME . ' Team</strong></p></body></html>';
25 - 46
 
47
        $mailContentText = "Dear " . $userData['first_name'] . ",\r\n\r\n";
48
        $mailContentText .= "Recently a request was submitted to reset a password for your account. If this was a mistake, just ignore this email and nothing will happen.\r\n\r\n";
49
        $mailContentText .= "To reset your password, visit the following link:\r\n\r\n$resetPassLink\r\n\r\n";
50
        $mailContentText .= "Let us know at customerservice@FindCheapMusic.com in case of any query or feedback.\r\n";
51
        $mailContentText .= "\r\nRegards,\r\n" . SITE_NAME . " Team";
65 - 52
 
53
        if (SMTP == true) {
54
            $mail = PHPMailer_Init();
55
 
56
            // SMTP configuration
57
            $mail->isSMTP();
58
            $mail->Host = SMTP_HOST;
59
            $mail->SMTPAuth = true;
60
            $mail->Username = SMTP_USERNAME;
61
            $mail->Password = SMTP_PASSWORD;
62
            $mail->SMTPSecure = SMTP_SECURE;
63
            $mail->Port = SMTP_PORT;
64
 
65
            $mail->setFrom(SENDER_EMAIL, SENDER_NAME);
66
 
67
            // Add a recipient
68
            $mail->addAddress($to);
69
 
70
            // Email subject
71
            $mail->Subject = $subject;
72
 
73
            // Set email format to HTML
74
            $mail->isHTML(true);
75
 
76
            // Email body content
77
            $mail->Body = $mailContent;
78
            $mail->AltBody = $mailContentText;
79
 
73 - 80
            // DKIM
81
            $mail->DKIM_domain = DKIM_DOMAIN;
82
            $mail->DKIM_private = $_SERVER['DOCUMENT_ROOT'] . DKIM_PRIVATE;
83
            $mail->DKIM_selector = DKIM_SELECTOR;
84
            $mail->DKIM_passphrase = DKIM_PASSPHRASE;
85
            $mail->DKIM_identity = $mail->From;
86
            $mail->DKIM_copyHeaderFields = false;
87
            $mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
88
 
65 - 89
            // Send email
90
            if (!$mail->send()) {
91
                error_log('Mailer error: ' . $mail->ErrorInfo);
92
            }
93
        }
94
        else {
95
            //set content-type header for sending HTML email
96
            $headers = "MIME-Version: 1.0" . "\r\n";
97
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
98
            //additional headers
99
            $headers .= 'From: ' . SENDER_NAME . '<' . SENDER_EMAIL . '>' . "\r\n";
100
            //send email
101
            mail($to, $subject, $mailContent, $headers);
102
        }
25 - 103
        return true;
104
    }
105
}
106
 
107
/*
108
 * Account verification email sender function
65 - 109
*/
110
if (!function_exists('emailVerification')) {
111
    function emailVerification($userData) {
112
        $emailVerifyLink = BASE_URL . 'userAccount.php?verifyEmail=1&ac_code=' . $userData['activation_code'];
25 - 113
        $to = $userData['email'];
65 - 114
        $subject = "Please Confirm Your Email | " . SITE_NAME;
25 - 115
        $mailContent = '<html>
116
                        <head>
117
                                <title>Find Cheap Music Email Confirmation</title>
118
                        </head>
119
                        <body>
73 - 120
                        <table style="width:100%;border-style: none;border-radius:6px;background-color:#ffffff;padding-top:15px;border-collapse:separate">
25 - 121
			<tbody>
122
				<tr>
123
					<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">
124
					<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>
125
					<br>
126
					Thank you for signing up with Find Cheap Music! Please confirm your email address by clicking the link below.
73 - 127
					<table style="width:100%;border-style: none;border-collapse:collapse">
25 - 128
					<tbody>
129
						<tr>
73 - 130
							<td style="text-align:center;vertical-align:middle;padding-top:25px;padding-right:15px;padding-bottom:25px;padding-left:15px">
131
								<table style="border-style: none;border-radius:.25em;background-color:#4582e8;border-collapse:separate">
25 - 132
								<tbody>
133
									<tr>
73 - 134
										<td style="text-align:center;vertical-align:middle;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 - 135
											<a href="' . $emailVerifyLink . '" style="font-weight:500;color:#ffffff;text-decoration:none">Confirm Email</a>
25 - 136
										</td>
137
									</tr>
138
								</tbody>
139
								</table>
140
							</td>
141
						</tr>
142
					</tbody>
143
					</table>
65 - 144
					We look forward to serving you,<br><strong>' . SITE_NAME . ' Team</strong>
25 - 145
					</td>
146
				</tr>
147
			</tbody>
148
		</table>
149
                </body>
150
                </html>';
151
 
152
        $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";
153
        $mailContentText .= "\r\nWe look forward to serving you,\r\n" . SITE_NAME . " Team";
154
 
65 - 155
        if (SMTP == true) {
156
            $mail = PHPMailer_Init();
157
 
158
            // SMTP configuration
159
            $mail->isSMTP();
160
            $mail->CharSet = "text/html; charset=UTF-8;";
161
            $mail->WordWrap = 80;
162
            $mail->Host = SMTP_HOST;
163
            $mail->SMTPAuth = true;
164
            $mail->Username = SMTP_USERNAME;
165
            $mail->Password = SMTP_PASSWORD;
166
            $mail->SMTPSecure = SMTP_SECURE;
167
            $mail->Port = SMTP_PORT;
168
 
169
            $mail->setFrom(SENDER_EMAIL, SENDER_NAME);
170
 
171
            // Add a recipient
172
            $mail->addAddress($to);
173
 
174
            // Email subject
175
            $mail->Subject = $subject;
176
 
177
            // Set email format to HTML
178
            $mail->isHTML(true);
179
 
180
            // Email body content
181
            $mail->Body = $mailContent;
182
            $mail->AltBody = $mailContentText;
183
 
73 - 184
            // DKIM
185
            $mail->DKIM_domain = DKIM_DOMAIN;
186
            $mail->DKIM_private = $_SERVER['DOCUMENT_ROOT'] . DKIM_PRIVATE;
187
            $mail->DKIM_selector = DKIM_SELECTOR;
188
            $mail->DKIM_passphrase = DKIM_PASSPHRASE;
189
            $mail->DKIM_identity = $mail->From;
190
            $mail->DKIM_copyHeaderFields = false;
191
            $mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
192
 
65 - 193
            // Send email
194
            if (!$mail->send()) {
195
                error_log('Mailer error: ' . $mail->ErrorInfo);
196
            }
197
        }
198
        else {
199
            //set content-type header for sending HTML email
200
            $headers = "MIME-Version: 1.0" . "\r\n";
201
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
202
            //additional headers
203
            $headers .= 'From: ' . SENDER_NAME . '<' . SENDER_EMAIL . '>' . "\r\n";
204
            //send email
205
            mail($to, $subject, $mailContent, $headers);
206
        }
25 - 207
        return true;
208
    }
31 - 209
}