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
| <?php
header('Content-type: text/plain; charset=utf-8');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$eol="\n";
$today = date("D M j G:i:s T Y");
$from="<moi@orange.fr>";
$to="<moi@gmail.com>";
$reply="<moi@christophe-charron.org>";
$subject="Test 08 socket local orange -> $today";
$msg=$subject;
mailto($from , $to , $reply , $subject , $msg);
function mailto($from, $to, $reply, $subject, $msg) {
echo "Envoi d'un mail à $to";
echo $eol;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "Reply-To: $reply\r\n";
$headers .= "X-Mailer: Mes mimines";
$connection = fsockopen ("smtp.orange.fr", 25, &$errno, &$errstr, 1);
if (!$connection) {
echo "$errstr ($errno) $eol";
} else {
$res1=fgets($connection, 256);
if(substr($res1, 0, 3) != "220") {echo "1 Ouverture error : $res1 $eol";} else {echo "1 Ouverture ok : $res1 $eol";}
fputs($connection, "HELO localhost\n");
$res2=fgets($connection, 256);
if(substr($res2, 0, 3) != "250") {echo "2 HELO error : $res2 $eol";} else {echo "2 HELO ok : $res2 $eol";}
fputs($connection, "MAIL FROM: $from\n");
$res3=fgets($connection, 256);
if(substr($res3, 0, 3) != "250") {echo "3 MAIL error : $res3 $eol";} else {echo "3 MAIL ok : $res3 $eol";}
fputs($connection, "RCPT TO: $to\n");
$res4=fgets($connection, 256);
if(substr($res4, 0, 3) != "250") {echo "4 RCPT error : $res4 $eol";} else {echo "4 RCPT ok : $res4 $eol";}
fputs($connection, "DATA\n");
$res5=fgets($connection, 256);
if(substr($res5, 0, 3) != "354") {echo "5 DATA error : $res5 $eol";} else {echo "5 DATA ok : $res5 $eol";}
fputs($connection, "TO: $to\nFrom: $reply\nSubject:$subject\n$headers\n\n$msg\n.\n");
$res6=fgets($connection, 256);
if(substr($res6, 0, 3) != "250") {echo "6 TO error : $res6 $eol";} else {echo "6 TO ok : $res6 $eol";}
fputs($connection, "QUIT\n");
$res7=fgets($connection, 256);
if(substr($res7, 0, 3) != "221") {echo "7 QUIT error : $res7 $eol";} else {echo "8 QUIT ok : $res1 $eol";}
fclose ($connection);
}
if(substr($res1, 0, 3) == "220" && substr($res2, 0, 3) == "250" && substr($res3,0, 3) == "250" && substr($res4, 0, 3) == "250" && substr($res5, 0, 3) == "354" && substr($res6, 0, 3) == "250" && substr($res7, 0, 3) == "221") echo "message envoyé correctement$eol";
}
?> |
Partager