testmail.php 3 KB
Newer Older
1
<?php
2 3 4
/**
 * ---------------------------------------------------------------------
 * GLPI - Gestionnaire Libre de Parc Informatique
5
 * Copyright (C) 2015-2018 Teclib' and contributors.
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
 *
 * http://glpi-project.org
 *
 * based on GLPI - Gestionnaire Libre de Parc Informatique
 * Copyright (C) 2003-2014 by the INDEPNET Development Team.
 *
 * ---------------------------------------------------------------------
 *
 * LICENSE
 *
 * This file is part of GLPI.
 *
 * GLPI is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GLPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GLPI. If not, see <http://www.gnu.org/licenses/>.
 * ---------------------------------------------------------------------
31 32
 */

33 34 35 36 37
if (PHP_SAPI != 'cli') {
   echo "This script must be run from command line";
   exit();
}

38
if (isset($_SERVER['argc'])) {
Anael Mobilia's avatar
Anael Mobilia committed
39 40 41
   for ($i=1; $i<$_SERVER['argc']; $i++) {
      $it           = explode("=", $_SERVER['argv'][$i], 2);
      $it[0]        = preg_replace('/^--/', '', $it[0]);
yllen's avatar
yllen committed
42 43
      $_GET[$it[0]] = (isset($it[1]) ? $it[1] : true);
   }
44
}
45
$NEEDED_ITEMS = ["mailgate", "mailing"];
46

47
include ('../inc/includes.php');
48 49

if (isset($_GET['from'])) {
yllen's avatar
yllen committed
50
   $from = $_GET['from'];
51
} else {
yllen's avatar
yllen committed
52
   $from = $CFG_GLPI['admin_email'];
53
}
yllen's avatar
yllen committed
54

55
if (isset($_GET['to'])) {
yllen's avatar
yllen committed
56
   $dest = $_GET['to'];
57
} else {
yllen's avatar
yllen committed
58
   die("--to option is mandatory\n");
59
}
yllen's avatar
yllen committed
60

61
if (isset($_GET['enc'])) {
yllen's avatar
yllen committed
62
   $enc = $_GET['enc'];
63
} else {
yllen's avatar
yllen committed
64 65
   // "7bit", "binary", "base64", and "quoted-printable".
   $enc = '';
66
}
yllen's avatar
yllen committed
67

68
if (isset($_GET['help'])) {
yllen's avatar
yllen committed
69
   die("usage php testmail.php  [ --from=email ] --to=email [ --enc=7bit|8bit|binary|base64|quoted-printable ]\n");
70
}
yllen's avatar
yllen committed
71 72 73

$dat     = date('r');
$secret  = "l'été, ça roule !";
74 75 76 77 78

echo "From : $from\n";
echo "To : $dest\n";
echo "Date : $dat\n";

Johan Cwiklinski's avatar
Johan Cwiklinski committed
79
$mmail = new NotificationMailing();
80 81 82
$mmail->From=$from;
$mmail->FromName="GLPI test";
$mmail->isHTML(true);
yllen's avatar
yllen committed
83 84 85 86

if ($enc) {
   $mmail->Encoding = $enc;
}
87 88

$mmail->Subject="GLPI test mail" . ($enc ? " ($enc)" : '');
yllen's avatar
yllen committed
89 90 91
$mmail->Body="<html><body><h3>GLPI test mail</h3><p>Encoding = <span class='b'>$enc</span></p>".
             "<p>Date = <span class='b'>$dat</span></p><p>Secret = <span class='b'>$secret</span>".
             "</p></body></html>";
92 93 94 95
$mmail->AltBody="GLPI test mail\nEncoding : $enc\nDate : $dat\nSecret=$secret";

$mmail->AddAddress($dest, "");

Anael Mobilia's avatar
Anael Mobilia committed
96
$logo=file_get_contents("../pics/logos/logo-GLPI-100-black.png");
Anael Mobilia's avatar
Anael Mobilia committed
97
$mmail->AddStringAttachment($logo, 'glpi.png', ($enc?$enc:'base64'), 'image/png');
98

Anael Mobilia's avatar
Anael Mobilia committed
99
$mmail->AddStringAttachment($secret, 'secret.txt', ($enc?$enc:'base64'), 'text/plain');
100 101

echo "Send : ". ($mmail->Send() ? "OK\n" : "Failed (". $mmail->ErrorInfo.")\n");