sendmail.php
12.6 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace
{
require( __DIR__.'/PHPMaile/PHPMailerAutoload.php');
/**
* sendmail
*
* @author Jane Bezmaternykh
* @version 0.1.20131120
*/
class sendmail extends \core
{
/////////////////////////////////////////////////////////////////////////////
/**
* sendmail::addCustomer()
*
* @author Jane Bezmaternykh
* @version 0.1.20131120
*
* @param integer $type
* @param array $data
* @return string
*/
public function addCustomer( $type, $data, $info = '' )
{
$view = new \Phalcon\Mvc\View();
$view->setViewsDir( ROOT_PATH.config::get( 'dirs/viewsDir' ) );
$view->start();
$view->setVar( 'data', $data );
$view->render( 'sendmail', 'message_'.$type );
$view->finish();
//p($data_base['message_body'],1);
//$email_to_customer = $data['email'];
$email_from = 'Robot <robot@'.\config::get( 'global#domains/www' ).'>';
//$email_reply_customer = $data['name'].' <'.$data['email'].'>';
switch( $type )
{
case 1: // customer order
$data_base =
[
'email_to' => $data['email'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Заказ на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 2: // admin order
$data_base =
[
'email_to' => \config::get( 'global#email' ),
'email_reply' => \config::get( 'global#email' ),
'subject' => 'Новый заказ на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 3: //customer registration
$data_base =
[
'email_to' => $data['email'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Регистрация на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 4: //customer do not finish registration
$data_base =
[
'email_to' => $data['email'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Регистрация на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 5: //customer registration
$data_base =
[
'email_to' => $data['email'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Регистрация на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 6: //restore passwd
$data_base =
[
'email_to' => $data['email'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Смена пароля на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 7: //callback email for admin
$data_base =
[
'email_to' => \config::get( 'global#email' ),
'email_reply' => \config::get( 'global#email' ),
'subject' => 'Новое сообщение на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 8: //callback email for admin
$data_base =
[
'email_to' => $data['email'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Ваше сообщение на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 9: //callback email for admin
$data_base =
[
'email_to' => $info[0]['text'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Ваше сообщение на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
case 10: //popup
$data_base =
[
'email_to' => $data['email'],
'email_reply' => $data['name'].' <'.$data['email'].'>',
'subject' => 'Благодарим за подписку на сайте: '.\config::get( 'global#title' ),
'message_body' => $view->getContent()
];
break;
default:
return false;
break;
}
$header =
'From: '.$email_from."\n".
'Reply-To: '.$data_base['email_reply']."\n".
'Return-Path: '.$data_base['email_reply']."\n".
'MIME-Version: 1.0'."\n".
'Content-type: text/html; charset=UTF-8'."\n".
'Content-Transfer-Encoding: 8bit'."\n".
'X-Mailer: PHP/' . phpversion();
if( mail( $data_base['email_to'], $data_base['subject'], $data_base['message_body'], $header, '-f '.$email_from ) )
{
return true;
}
else
{
return false;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* sendmail::addAdmin()
*
* @author Jane Bezmaternykh
* @version 0.1.20131120
*
* @param integer $type
* @param array $data
* @return string
*/
public function addAdmin( $type, $data )
{
$view_admin = new \Phalcon\Mvc\View();
$view_admin->setViewsDir( ROOT_PATH.config::get( 'dirs/viewsDir' ) );
$view_admin->start();
$view_admin->setVar( 'data', $data );
$view_admin->render( 'sendmail', 'message_'.$type );
$view_admin->finish();
$email_to_admin = \config::get( 'global#email' );
$email_from = 'Robot <robot@'.\config::get( 'global#domains/www' ).'>';
$email_reply_admin = '<'.\config::get( 'global#email' ).'>';
$header_admin =
'From: '.$email_from."\n".
'Reply-To: '.$email_reply_admin."\n".
'Return-Path: '.$email_reply_admin."\n".
'MIME-Version: 1.0'."\n".
'Content-type: text/html; charset=UTF-8'."\n".
'Content-Transfer-Encoding: 8bit'."\n".
'X-Mailer: PHP/'.phpversion();
if( mail( $email_to_admin, $data['subject_admin'], $view_admin->getContent(), $header_admin, '-f '.$email_from ) )
{
return true;
}
else
{
return false;
}
}
/////////////////////////////////////////////////////////////////////////////
public function sendSubscribe($data) {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir( ROOT_PATH.config::get( 'dirs/viewsDir' ) );
$view->start();
$view->setVar( 'data', $data );
$view->render( 'sendmail', 'message_10' );
$view->finish();
$message_body = $view->getContent();
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
$mail->CharSet = 'UTF-8';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "arctic.semenainua@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "arctic0411";
//Set who the message is to be sent from
$mail->setFrom('semena@hs.kiev.ua', 'semena.in.ua');
//Set who the message is to be sent to
$mail->addAddress($data['email'], $data['name']);
//Set the subject line
$mail->Subject = 'Благодарим за подписку!';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($message_body);
$mail->send();
}
/////////////////////////////////////////////////////////////////////////////
public function abandonedBasket($email) {
$email_from = 'Robot <robot@'.\config::get( 'global#domains/www' ).'>';
$data_base = [
'email_to' => $email,
'email_reply' => $email.' <'.$email.'>',
'subject' => ''.\config::get( 'global#title' ),
];
$header =
'From: '.$email_from."\n".
'Reply-To: '.$data_base['email_reply']."\n".
'Return-Path: '.$data_base['email_reply']."\n".
'MIME-Version: 1.0'."\n".
'Content-type: text/html; charset=UTF-8'."\n".
'Content-Transfer-Encoding: 8bit'."\n".
'X-Mailer: PHP/' . phpversion();
//msg body
// $view = new \Phalcon\Mvc\View();
// $view->setViewsDir( ROOT_PATH.config::get( 'dirs/viewsDir' ) );
// $view->start();
// $view->render( 'basket', 'abandoned' );
// $view->finish();
// $body = $view->getContent();
$body = file_get_contents(ROOT_PATH.config::get( 'dirs/viewsDir' ).'basket/abandoned.php');
if( mail( $email, $data_base['subject'], $body, $header, '-f '.$email_from ) ) {
return true;
}
else {
return false;
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////