summaryrefslogtreecommitdiff
path: root/html/app/extends/Send_mail.php
blob: fa0d8d316876423f8bdaed02ad005ded53ca00df (plain)
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
<?php
namespace app\extends;

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;


class Send_mail
{

    private static function init_mail()
    {
        $mail = new PHPMailer();

        // setup smpt
        $mail->SMTPDebug = 3;
        $mail->IsSMTP();
        $mail->Host = MAIL_HOST;
        $mail->SMPTAuth = false;
        $mail->SMTPSecure = MAIL_ENCRYPTION;
        // $mail->Protocol = 'mail';
        
        $mail->Mailer = MAIL_MAILER;
        $mail->Port = MAIL_PORT;
        $mail->Username = MAIL_USERNAME;
        $mail->Password = MAIL_PASSWORD;

        return $mail;
    }


    /**
     * 
     */
    private static function init_slack()
    {

    }


    /**
     * 
     * @param $envelope (array): mail from/to and activation code 
     * 
     * TODO:
     * check for email templating:
     * + https://stackoverflow.com/questions/2391171/how-to-get-output-from-local-script-in-php
     * + https://stackoverflow.com/questions/171318/how-do-i-capture-php-output-into-a-variable
     */
    public static function send_activation_code($envelope)
    {
        $mail = self::init_mail();

        // setup format
        $mail->CharSet = 'utf-8';
        $mail->IsHTML(true);

        // setup THE mail
        // --- -- -- - - -
        // It's important not to use the submitter's address as the from address as it's forgery,
        // which will cause your messages to fail SPF checks.
        // Use an address in your own domain as the from address, put the submitter's address in a reply-to
        $mail->setFrom(NO_REPLY_EMAIL, MAIL_FROM_NAME);
        $mail->addAddress($envelope['email'], $envelope['name']);
        $mail->addReplyTo(REPLY_TO_EMAIL, MAIL_FROM_NAME);
        $mail->Subject = 'Εγγραφή στο Classroom';
        $mail->Body = "Χαίρετε,<br>
            το παρόν αυτοποιημένο email σάς έχει σταλεί γιατί έχει γίνει αίτημα εγγραφής σας στο Classroom.<br>
            <br>
            Όνομα επαφής: <b>". $envelope['name'] ."</b><br>
            Email : <b>". $envelope['email'] ."</b><br>
            <br>
            Για να ενεργοποιήσετε την πρόσβασή σας στο site θα πρέπει να παρακαλώ πατήστε στον 
            παρακάτω σύνδεσμο url
            <a href=\"https://eaadhsy.roptron.gr/account/activate?ticket=". $envelope['code'] ."\">.
            <br>
            <br>
            Μετά την ενεργοποίηση θα έχετε πρόσσβαση στο περιεχόμενο του site.<br>
            <br>
            Μην απαντήσετε στο email γιατί δεν υπάρχει φυσική επαφή η οποία να λαμβάνει τυχόν replies.<br>";
        if (!$mail->send()) {
            return false;
        } else {
            return true;
        }
      
    }




}





/**
 *
 * 

Optimization per concept alternative technologies
--- -- -- - - -

## Session
File Session
Database Session
Redis Session
Memcached Session

---

## Cache
File Cache
Database Cache
Redis Cache
Memcashed Cache

---

## Log
File Log
Database Log
Log event to Slack
Log event to Email

 *
 * 
 */

/** custom email api
 * 
 * host  : https://api.roptron.gr
 * apikey : md5(hash)-substring(0,5, md5(service)) 8668d1c4a8f5aba236a8f821d148340f-0c83f
 * message : serialize([
 *    from[email] => from name
 *    replyTo[email] => reply-to-Name
 *    to => [
 *        email => email-name
 *        secondemail => another email name
 *    ]
 *    type => html
 *    charset => utf8
 *    subject => mail subject
 *    mailBody => html string
 * ])
 * 
 */

/** Several custom APIs
 * 
 * Mailer
 * 
 * sendpulse
 * rU8WEmcHsRcEQaH
 * rU8WEmcHsRcEQaH
 * 
 * mailjet
 * piipiis@g
 * EN6Xg8!99ZTKaYp7
 * 
 * 
 * sendGrid
 * piipiis
 * EN6Xg899ZTKU8WEmcHsR54321
 * 
 * 
 * time4vps...
 * https://community.time4vps.com/discussion/75/are-any-ports-blocked-by-time4vps
 * 
 * test activation code:
 * ca42d68cfba5fbbafeacc010b8e3a551
 * 
 * 
 * 
 * MAIL API
 * --- -- -- - - -
 * client = ip/mp5(IP)  or domain/md5(ref_domain)
 * token  = md5(client + timestamp + rand(0,10000))
 * 
 * api   : auth_content : client : token
 * ---   : ---          : ---    : ---
 * mail  : ip|domain    : md5(*) : md5(...)  -> send an email
 * image : ip|domain    : md5(*) : md5(...)  -> proccess an image (resize|crop|convert)
 * slack : ip|domain    : md5(*) : md5(...)  -> send a slack message to channel
 * database : ip|domain : md5(*) : md5(...)  -> 
 * 
 */