Licenses added & README.md edited
[smail.git/.git] / mailbox / send.php
1 <?php
2 ini_set('display_errors',1);
3 ini_set('display_initial_errors',1);
4 error_reporting(E_ALL);
5 include '../i18n.class.php'; $i18n = new i18n('../lang/lang_{LANGUAGE}.ini'); $i18n->init();
6 ?>
7 <?php
8 include '../api/functions.php';
9 if (isset($_POST['content']) and isset($_POST['mail_r'])){
10     session_issruning();
11     $_POST['content']=str_replace('\n','<br>',$_POST['content']);
12     if (isloged()==1){
13         $split=preg_split('/@/',$_POST['mail_r']);
14         $cnt=count($split);
15         if ($cnt==2){
16             $query=mysqli_query($conn,'SELECT mail_password FROM mail WHERE mail_user="'.$_SESSION['m_user'].'"');
17             $hash=mysqli_fetch_array($query,MYSQLI_ASSOC)['mail_password'];
18             $mail=['mail'=>$_SESSION['m_user'],'html'=>$_POST['content'],'hash'=>$hash,'to'=>preg_split('/@/',$_POST['mail_r'])[0]];
19             $other=array(
20                 CURLOPT_URL => 'https://'.$split[1].'mailbox/reicive.php',
21                 CURLOPT_POST => true,
22                 CURLOPT_POSTFIELDS => $mail,
23                 CURLOPT_RETURNTRANSFER => true,
24                 CURLOPT_SSL_VERIFYPEER => false
25             );
26             echo 'Sending sm to the url '.$split[1];
27             echo '<br> and to the mail id '.$split[0];
28             $curl=curl_init();
29             curl_setopt_array($curl, ($other));
30             $out=curl_exec($curl);
31             echo curl_error($curl);
32             if (curl_error($curl)){
33                 header('Location: mailb.php?info=<text>'.L::errors_sslerror.'</text> '.curl_error($curl));
34             }
35             else{
36                 $info=curl_getinfo($curl,CURLINFO_HTTP_CODE);
37                 if ($info==200){
38                         header('Location: mailb.php?info=<text>'.L::errors_nonerror.'</text>');
39                 }
40                 else{
41                                         header('Location: mailb.php?info=<text>'.L::errors_iderror_not.'</text>');
42                 }
43             }
44         }
45         elseif ($cnt==1){
46             $selfUrl=$_SERVER['HTTP_HOST'].preg_replace('/mailbox\/send.php/','',$_SERVER['PHP_SELF']);
47             $query=mysqli_query($conn,'SELECT mail_password FROM mail WHERE mail_user="'.$_SESSION['m_user'].'"');
48             $hash=mysqli_fetch_array($query,MYSQLI_ASSOC)['mail_password'];
49             $mail=['mail'=>$_SESSION['m_user'],'html'=>$_POST['content'],'hash'=>$hash,'to'=>$split[0]];
50             $other=array(
51                 CURLOPT_URL => 'https://'.$selfUrl.'mailbox/reicive.php',
52                 CURLOPT_POST => true,
53                 CURLOPT_POSTFIELDS => $mail,
54                 CURLOPT_RETURNTRANSFER => true,
55                 CURLOPT_SSL_VERIFYPEER => false
56             );
57             echo 'Sending sm to the url '.$selfUrl;
58             echo '<br> and to the mail id '.$split[0];
59             $curl=curl_init();
60             curl_setopt_array($curl, ($other));
61             $out=curl_exec($curl);
62             echo $out;
63             if (curl_error($curl)){
64                 header('Location: mailb.php?info=<text>'.L::errors_sslerror.'</text>');
65             }
66             else{
67                 $info=curl_getinfo($curl,CURLINFO_HTTP_CODE);
68                 if ($info==200){
69                                         header('Location: mailb.php?info=<text>'.L::errors_nonerror.'</text>');
70                 }
71                 else{
72                         header('Location: mailb.php?info=<text>'.L::errors_iderror_not.'</text>'.$out);
73                 }
74             }
75         }
76     }
77     else{
78         header('Location: ../login.php');
79     }
80 }
81
82 ?>