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
| <!doctype html>
<html lang="fr">
<head>
<meta charset="ISO-8859-1" />
<title>Envoie d'un e-mail avec socket !</title>
<link rel="stylesheet" type="text/css" href="Styles.css" />
</head>
<body>
<?php
/* ======================= */
/* Paramétrage des e-mails */
/* ======================= */
$serveur = "???";
$nom1 = "???";
$email1 = "???";
$password = "???";
$nb = 7;
$client = gethostname();
$port = 587;
$nom2 = "???";
$email2 = "???";
$sujet = "Test 1 !";
$message = "Test de l'envoi d'un message simple !\n\nCordialement.\nArtemus24\n@+";
?>
<table>
<tr><td>Client </td><td><?php echo ': '.$client; ?></td></tr>
<tr><td>Serveur </td><td><?php echo ': '.$serveur; ?></td></tr>
<tr><td>Port </td><td><?php echo ': '.$port; ?></td></tr>
<tr><td>Expéditeur </td><td><?php echo ': '.$nom1.' ('.$email1.')'; ?></td></tr>
<tr><td>Destinataire </td><td><?php echo ': '.$nom2.' ('.$email2.')'; ?></td></tr>
<tr><td>Sujet </td><td><?php echo ': '.$sujet; ?></td></tr>
</table>
<?php
/* ----------------------------- */
/* Liste des commandes à envoyer */
/* ----------------------------- */
$list = array(
array($nb, "EHLO $client"),
array(1, "AUTH LOGIN"),
array(1, base64_encode($email1)),
array(1, base64_encode($password)),
array(1, "MAIL FROM: <$email1>"),
array(1, "RCPT TO: <$email2>"),
array(1, "DATA"),
array(0, "Mime-Version: 1.0"),
array(0, "Content-Type: Text/Plain; Charset=ISO-8859-1"),
array(0, "Content-Transfer-Encoding: 8bit"),
array(0, "X-Mailer: Php ".phpversion()),
array(0, "Content-Language: fr"),
array(0, "Message-Id: <".sha1(''.(idate('U')-1000000000))."@xxxxxxxx.fr>"),
array(0, "FROM: $nom1 <$email1>"),
array(0, "TO: $nom2 <$email2>"),
array(0, "SUBJECT: $sujet"),
array(0, ""),
array(0, "$message"),
array(1, "."),
array(1, "QUIT")
);
/* --------------- */
/* Fonction Lecure */
/* --------------- */
function lect($socket)
{
$result = fgets($socket,128);
echo $result;
return substr($result,0,3);
}
/* -------------- */
/* Test du socket */
/* -------------- */
$errno = "";
$errmsg = "";
$socket = fsockopen($serveur, $port, $errno, $errmsg, 1);
if (!$socket)
{
?>
<br />
<table>
<tr><td>Connexion impossible</td><td><?php echo ': '.$serveur.' !'; ?></td></tr>
<tr><td>numero d'erreur </td><td><?php echo ': '.$errno; ?></td></tr>
<tr><td>Message d'erreur </td><td><?php echo ': '.htmlentities($errmsg); ?></td></tr>
</table>
<?php
}
else
{
?>
<br />
<pre>
<?php
stream_set_blocking($socket, true);
stream_set_timeout($socket, 1);
echo "Connecting To ".$serveur."\n";
if (lect($socket) == "220");
{
foreach ($list as $cmd)
{
fputs($socket,$cmd[1]."\r\n");
echo "<spam>".htmlentities($cmd[1])."</spam>\n";
for ($i=0; $i<$cmd[0]; $i++)
lect($socket);
}
}
fclose($socket);
}
?>
</pre>
</body>
</html> |
Partager