Envoi de mail en TLS par Gandi, quelle fonction?

Billybobbonnet Messages postés 148 Date d'inscription lundi 12 février 2007 Statut Membre Dernière intervention 9 novembre 2013 - 3 janv. 2008 à 17:24
Billybobbonnet Messages postés 148 Date d'inscription lundi 12 février 2007 Statut Membre Dernière intervention 9 novembre 2013 - 4 janv. 2008 à 10:17
Bonjour à tous,

J'ai un nom de domaine tout neuf chez Gandi pour un site que j'héberge. Pour envoyer des mails via les serveurs smtp de gandi, je dois utiliser une connexion TLS authentifiée par nom d'utilisateur & mot de passe. J'y arrive depuis thunderbird.

Or, il me semble que je ne peux pas utiliser la fonction 'mail' de php si j'utilise ce type de protocole pour accéder au serveur smtp. Vous avez des solutions? Quelle méthode? Il faut que j'installe pear ou un module dédié aux mails?

Merci!

1 réponse

Billybobbonnet Messages postés 148 Date d'inscription lundi 12 février 2007 Statut Membre Dernière intervention 9 novembre 2013
4 janv. 2008 à 10:17
J'ai trouvé cette fonction pour créer une connexion sécurisée en TLS vers gmail, mais j'ignore si c'est ce qu'il me faut, si ça marche pour gandimail, et si il n'y a pas possibilité de le faire plus simplement.

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 = "yous@gmail.com"; //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
".$smtpResponse."Continuing";

}


//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);

}


Je suppose que quelques uns parmi vous ont déjà eu à résoudre ce problème, alors, je viens aux nouvelles.

Merci de vos avis!
0
Rejoignez-nous