par Sékiltoyai » 12 août 2009, 20:25
par Lovek » 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, @+
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); }
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:
par FuZZyLine » 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.
Tout faire soi-même : non (il existe plein de routines ...et très bien faites aussi pourquoi devoir réinventer la roue? Non)
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
par Sékiltoyai » 12 août 2009, 17:23
par FuZZyLine » 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.
par Lovek » 12 août 2009, 15:47
par Sékiltoyai » 12 août 2009, 15:38
par FuZZyLine » 12 août 2009, 14:11
Bonjour FuZZyLine, Ces classes utilisent tous fsockopen.
par Lovek » 12 août 2009, 12:44
par FuZZyLine » 12 août 2009, 10:35
par Sékiltoyai » 11 août 2009, 22:48
par Sékiltoyai » 11 août 2009, 22:18
par Lovek » 11 août 2009, 20:54
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.
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.
par Sékiltoyai » 11 août 2009, 20:46
/** * Sets connection prefix. * Options are "", "ssl" or "tls" * @var string */ var $SMTPSecure = "";
par Lovek » 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"; ?>