Faster Update, fixing bugs
[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     if (isloged()==1){
12         $split=preg_split('/@/',$_POST['mail_r']);
13         $cnt=count($split);
14         if ($cnt==2){
15             $query=mysqli_query($conn,'SELECT mail_password FROM mail WHERE mail_user="'.$_SESSION['m_user'].'"');
16             $hash=mysqli_fetch_array($query,MYSQLI_ASSOC)['mail_password'];
17             $mail=['mail'=>$_SESSION['m_user'],'html'=>$_POST['content'],'hash'=>$hash,'to'=>preg_split('/@/',$_POST['mail_r'])[0]];
18             $other=array(
19                 CURLOPT_URL => 'https://'.$split[1].'mailbox/reicive.php',
20                 CURLOPT_POST => true,
21                 CURLOPT_POSTFIELDS => $mail,
22                 CURLOPT_RETURNTRANSFER => true
23             );
24             echo 'Sending sm to the url '.$split[1];
25             echo '<br> and to the mail id '.$split[0];
26             $curl=curl_init();
27             curl_setopt_array($curl, ($other));
28             $out=curl_exec($curl);
29             echo curl_error($curl);
30             if (curl_error($curl)){
31                 header('Location: mailb.php?info=<text>'.L::errors_sslerror.'</text> '.curl_error($curl));
32             }
33             else{
34                 $info=curl_getinfo($curl,CURLINFO_HTTP_CODE);
35                 if ($info==200){
36                         header('Location: mailb.php?info=<text>'.L::errors_nonerror.'</text>');
37                 }
38                 else{
39                                         header('Location: mailb.php?info=<text>'.L::errors_iderror_not.'</text>');
40                 }
41             }
42         }
43         elseif ($cnt==1){
44             $selfUrl=$_SERVER['HTTP_HOST'].preg_replace('/mailbox\/send.php/','',$_SERVER['PHP_SELF']);
45             $query=mysqli_query($conn,'SELECT mail_password FROM mail WHERE mail_user="'.$_SESSION['m_user'].'"');
46             $hash=mysqli_fetch_array($query,MYSQLI_ASSOC)['mail_password'];
47             $mail=['mail'=>$_SESSION['m_user'],'html'=>$_POST['content'],'hash'=>$hash,'to'=>$split[0]];
48             $other=array(
49                 CURLOPT_URL => 'https://'.$selfUrl.'mailbox/reicive.php',
50                 CURLOPT_POST => true,
51                 CURLOPT_POSTFIELDS => $mail,
52                 CURLOPT_RETURNTRANSFER => true
53             );
54             echo 'Sending sm to the url '.$selfUrl;
55             echo '<br> and to the mail id '.$split[0];
56             $curl=curl_init();
57             curl_setopt_array($curl, ($other));
58             $out=curl_exec($curl);
59             echo curl_error($curl);
60             if (curl_error($curl)){
61                 header('Location: mailb.php?info=<text>'.L::errors_sslerror.'</text>');
62             }
63             else{
64                 $info=curl_getinfo($curl,CURLINFO_HTTP_CODE);
65                 if ($info==200){
66                                         header('Location: mailb.php?info=<text>'.L::errors_nonerror.'</text>');
67                 }
68                 else{
69                         header('Location: mailb.php?info=<text>'.L::errors_iderror_not.'</text>');
70                 }
71             }
72         }
73     }
74     else{
75         header('Location: ../login.php');
76     }
77 }
78
79 ?>