envoie de mails par le smtp de hotmail avec authentification

ViPHP
ViPHP | 5924 Messages

10 août 2009, 22:36

C'est plus lisible comme ça (ils ne connaissent pas les sauts de ligne ? ) :

Code : Tout sélectionner

SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "220 BLU0-SMTP61.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Mon, 10 Aug 2009 12:56:49 -0700 " SMTP -> get_lines(): $data is "220 BLU0-SMTP61.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Mon, 10 Aug 2009 12:56:49 -0700 " SMTP -> FROM SERVER: 220 BLU0-SMTP61.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Mon, 10 Aug 2009 12:56:49 -0700 SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] " SMTP -> get_lines(): $str is "250-TURN " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN " SMTP -> get_lines(): $str is "250-SIZE 35840000 " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 " SMTP -> get_lines(): $str is "250-ETRN " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN " SMTP -> get_lines(): $str is "250-PIPELINING " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING " SMTP -> get_lines(): $str is "250-DSN " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN " SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES " SMTP -> get_lines(): $str is "250-8bitmime " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime " SMTP -> get_lines(): $str is "250-BINARYMIME " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME " SMTP -> get_lines(): $str is "250-CHUNKING " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING " SMTP -> get_lines(): $str is "250-VRFY " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY " SMTP -> get_lines(): $str is "250-TLS " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS " SMTP -> get_lines(): $str is "250-STARTTLS " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS 250-STARTTLS " SMTP -> get_lines(): $data was "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS 250-STARTTLS " SMTP -> get_lines(): $str is "250 OK " SMTP -> get_lines(): $data is "250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS 250-STARTTLS 250 OK " SMTP -> FROM SERVER: 250-BLU0-SMTP61.blu0.hotmail.com Hello [195.200.217.30] 250-TURN 250-SIZE 35840000 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS 250-STARTTLS 250 OK SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "530 5.7.0 Must issue a STARTTLS command first " SMTP -> get_lines(): $data is "530 5.7.0 Must issue a STARTTLS command first " SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first SMTP -> get_lines(): $data was "" SMTP -> get_lines(): $str is "530 5.7.0 Must issue a STARTTLS command first " SMTP -> get_lines(): $data is "530 5.7.0 Must issue a STARTTLS command first " SMTP -> FROM SERVER: 530 5.7.0 Must issue a STARTTLS command first SMTP -> ERROR: RSET failed: 530 5.7.0 Must issue a STARTTLS command first Message could not be sent.
Avec quel code ?

Eléphanteau du PHP | 13 Messages

11 août 2009, 19:46

<?php

if(!class_exists('PHPMailer')) {
    require('./class.phpmailer.php');
}

$mail = new PHPMailer();



$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = 'smtp.live.com';  // specify main and backup server
$mail->Port = 587;
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = '***@hotmail.com';  // SMTP username
$mail->Password = '****'; // SMTP password

$mail->From = '***@hotmail.com';
$mail->FromName = "Mailer";
$mail->AddAddress("***@hotmail.com");                  // name is optional
$mail->AddReplyTo('***@hotmail.com','****@hotmail.com');

//$mail->WordWrap = 50;                                 // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
//$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";




?>

ViPHP
ViPHP | 5924 Messages

11 août 2009, 20:46

Tu as oublié une propriété :

Code : Tout sélectionner

  /**    * Sets connection prefix.    * Options are "", "ssl" or "tls"    * @var string    */   var $SMTPSecure = ""; 

Eléphanteau du PHP | 13 Messages

11 août 2009, 20:54

Code : Tout sélectionner

Warning: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in /home/d/domains/domaine.fr/public_html/m/class.smtp.php on line 122 Warning: fsockopen() [function.fsockopen]: Failed to enable crypto in /home/d/domains/domaine.fr/public_html/m/class.smtp.php on line 122 Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.live.com:587 (Unknown error) in /home/d/domains/domaine.fr/public_html/m/class.smtp.php on line 122 SMTP -> ERROR: Failed to connect to server: (0) Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.

Code : Tout sélectionner

Warning: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number in /home/d/domains/domaine.fr/public_html/m/class.smtp.php on line 122 Warning: fsockopen() [function.fsockopen]: Failed to enable crypto in /home/d/domains/domaine/public_html/m/class.smtp.php on line 122 Warning: fsockopen() [function.fsockopen]: unable to connect to tls://smtp.live.com:587 (Unknown error) in /home/d/domains/domaine.fr/public_html/m/class.smtp.php on line 122 SMTP -> ERROR: Failed to connect to server: (0) Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
...

ViPHP
ViPHP | 5924 Messages

11 août 2009, 22:18

En effet…

Bon, ce n'est pas ça, cette classe là non plus ne supporte pas cette extension là…

ViPHP
ViPHP | 5924 Messages

11 août 2009, 22:48

Bon, je ne vais pas te mentir, ça risque d'être vraiment très chiant à implémenter. Je te conseille plusieurs solutions :
- De trouver une classe qui supporte l'extension SMTP TLS
- De trouver un client en ligne de commande qui supporte l'extension SMTP TLS
- D'envoyer les mails par ton SMTP local

A vrai dire, je t'aurais bien apporté mon aide, mais j'ai l'impression d'un relatif vide documentaire sur le sujet. Certaines parties du protocole ne semblent pas explicitées et cela compromet une mise en oeuvre simple par un petit hack à la va-vite.

Eléphant du PHP | 369 Messages

12 août 2009, 10:35

Salut,

Je te conseille d'utiliser la fonction fsockopen, non que tu auras un rendu réèl de ce que tu attends
mais cela te permetra de savoir exactement ce qui manque et à quel endroit

http://www.manuelphp.com/php/function.fsockopen.php

@+ ;)

Eléphanteau du PHP | 13 Messages

12 août 2009, 12:44

Bonjour FuZZyLine,

Ces classes utilisent tous fsockopen.

Eléphant du PHP | 369 Messages

12 août 2009, 14:11

Re,
Bonjour FuZZyLine,
Ces classes utilisent tous fsockopen.
Je me suis peut-être mal exprimé, désole.
Je parle de créer toi-même l'accès par fsockopen (sans passer par du tout fait).
C'est long mais ca a le mérite de savoir exactement ou ca cloche et donc de remédier
au problème (peut-être plus rapidement).

@+ ;)

ViPHP
ViPHP | 5924 Messages

12 août 2009, 15:38

Mon opinion ici (en fin de message).

FuZZyLine, c'est bien gentil de prôner de tout faire soi-même, comme Nagol en l'occurence, mais je te laisse implémenter proprement cette petite vingtaine de RFC afférent au protocole SMTP, en y ajoutant le support TLS.
:wink:

Eléphanteau du PHP | 13 Messages

12 août 2009, 15:47

Tout à fait d'accord Sékiltoyai.

Eléphant du PHP | 369 Messages

12 août 2009, 16:54

Mon opinion ici (en fin de message).
FuZZyLine, c'est bien gentil de [*]prôner de tout faire soi-même, comme Nagol en l'occurence, mais je te laisse implémenter proprement cette petite vingtaine de RFC afférent au protocole SMTP, en y ajoutant le support TLS. :wink:
Tout faire soi-même : non (il existe plein de routines ...et très bien faites aussi pourquoi devoir réinventer
la roue? Non) c'est juste que je trouve plus facile la detection des erreurs quand on touche du doigt les fonctions
natives et de plus, par la suite, ca fait gagner du temps -je trouve-.
Effectivement j'aurai pu inserer du code mais en quoi lorek aurait compris le problème?
Bref... ce qui suit n'est pas de moi, le code n'a pas un aspects génial... libre à lorek de s'en servir...

@lorek: t'as juste à changer le nom du serveur et ca roule ;)
function authgMail($from, $namefrom, $to, $nameto, $subject, $message)
{
/*  your configuration here  */

$smtpServer = "tls://smtp.gmail.com"; //does not accept STARTTLS
$port = "465"; // try 587 if this fails
$timeout = "45"; //typical timeout. try 45 for slow servers
$username = "[email protected]"; //your gmail account
$password = "y0u4p@55"; //the pass for your gmail
$localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip
$newLine = "\r\n"; //var just for newlines 
 
/*  you shouldn't need to mod anything else */

//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
echo $errstr." - ".$errno;
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
   $output = "Failed to connect: $smtpResponse";
   echo $output;
   return $output;
}
else
{
   $logArray['connection'] = "Connected to: $smtpResponse";
   echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";
}

//you have to say HELO again after TLS is started
   fputs($smtpConnect, "HELO $localhost". $newLine);
   $smtpResponse = fgets($smtpConnect, 4096);
   $logArray['heloresponse2'] = "$smtpResponse";
   
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";

//email to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";

//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
}
Espérant ne pas avoir trop pollué le topic, @+ ;)

ViPHP
ViPHP | 5924 Messages

12 août 2009, 17:23

Tout faire soi-même : non (il existe plein de routines ...et très bien faites aussi pourquoi devoir réinventer
la roue? Non)
Ok, alors parlons de cette classe. Elle ne prend pas en compte les messages d'information ni les codes de retour du serveur. Elle est moins élaborée que les deux classes que Lovek a présenté précédemment. Elle gère moins de commande que le minimum requis par le protocole.
Elle fonctionne peut être, mais, non, elle n'est pas propre.
Bref... ce qui suit n'est pas de moi, le code n'a pas un aspects génial... libre à lorek de s'en servir...
Le problème n'est pas d'avoir un code à hacker pour ajouter la fonctionnalité voulue, le problème, c'est que la fonctionnalité à ajouter est complexe à implémenter. Lis le reste du sujet, lis la RFC 3207, renseigne toi sur le TLS, tu comprendras.
@lorek: t'as juste à changer le nom du serveur et ca roule ;)
Il ne s'agit pas de changer le nom du serveur, il s'agit de gérer une extension qu'aucune classe PHP ne sait gérer. Initier directement une connexion TLS sans la négocier avec la commande STARTTLS, Lovek a déjà essayé avec la classe PHPMailer, et ça n'a pas marché, je ne vois pas pourquoi cela fonctionnerait mieux avec cette classe-ci.

Eléphant du PHP | 369 Messages

12 août 2009, 17:35

Tout faire soi-même : non (il existe plein de routines ...et très bien faites aussi pourquoi devoir réinventer
la roue? Non)
Ok, alors parlons de cette classe. Elle ne prend pas en compte les messages d'information ni les codes de retour du serveur. Elle est moins élaborée que les deux classes que Lovek a présenté précédemment. Elle gère moins de commande que le minimum requis par le protocole.
Elle fonctionne peut être, mais, non, elle n'est pas propre.
Bref... ce qui suit n'est pas de moi, le code n'a pas un aspects génial... libre à lorek de s'en servir...
Le problème n'est pas d'avoir un code à hacker pour ajouter la fonctionnalité voulue, le problème, c'est que la fonctionnalité à ajouter est complexe à implémenter. Lis le reste du sujet, lis la RFC 3207, renseigne toi sur le TLS, tu comprendras.
@lorek: t'as juste à changer le nom du serveur et ca roule ;)
Il ne s'agit pas de changer le nom du serveur, il s'agit de gérer une extension qu'aucune classe PHP ne sait gérer. Initier directement une connexion TLS sans la négocier avec la commande STARTTLS, Lovek a déjà essayé avec la classe PHPMailer, et ça n'a pas marché, je ne vois pas pourquoi cela fonctionnerait mieux avec cette classe-ci.
Je le répète (ou pas...) Il ne s'agit pas de *re-créer* de A à Z ce qui existe déja mais juste de comprendre le
fonctionnement d'une fonction de base. Pour info j'utilise "aussi" PHPMailer et j'en suis très satisfait ca m'a pas
empéché de créer divreses class employant fsockopen en natif.
Comme on dit: à chacun de voir, perso je préfere comprendre puis utiliser qu'utiliser...

Ca devient un brin troll, rendons à lorek ce topic, bon code @+ ;)

Eléphanteau du PHP | 13 Messages

12 août 2009, 18:06

@lorek: t'as juste à changer le nom du serveur et ca roule ;)
function authgMail($from, $namefrom, $to, $nameto, $subject, $message)
{
/*  your configuration here  */

$smtpServer = "tls://smtp.gmail.com"; //does not accept STARTTLS
$port = "465"; // try 587 if this fails
$timeout = "45"; //typical timeout. try 45 for slow servers
$username = "[email protected]"; //your gmail account
$password = "y0u4p@55"; //the pass for your gmail
$localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip
$newLine = "\r\n"; //var just for newlines 
 
/*  you shouldn't need to mod anything else */

//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
echo $errstr." - ".$errno;
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
   $output = "Failed to connect: $smtpResponse";
   echo $output;
   return $output;
}
else
{
   $logArray['connection'] = "Connected to: $smtpResponse";
   echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";
}

//you have to say HELO again after TLS is started
   fputs($smtpConnect, "HELO $localhost". $newLine);
   $smtpResponse = fgets($smtpConnect, 4096);
   $logArray['heloresponse2'] = "$smtpResponse";
   
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";

//email to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";

//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
}
Espérant ne pas avoir trop pollué le topic, @+ ;)
Avec un compte gmail ca marche mais pas sur le smtp de hotmail, je reçois le même message d'erreur, hotmail exigerait une vrai connexion sécurisé et pas gmail ?

Code : Tout sélectionner

Warning: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number in /home/s/domains/domaine.fr/public_html/m/t/index.php on line 19 Warning: fsockopen() [function.fsockopen]: Failed to enable crypto in /home/d/domains/domaine.fr/public_html/m/t/index.php on line 19 Warning: fsockopen() [function.fsockopen]: unable to connect to tls://smtp.live.com:587 (Unknown error) in /home/d/domains/domaine.fr/public_html/m/t/index.php on line 19 - 0 Warning: fgets(): supplied argument is not a valid stream resource in /home/d/domains/domaine.fr/public_html/m/t/index.php on line 21 Failed to connect: