Ver Mensaje Individual
  #19 (permalink)  
Antiguo 06/12/2007, 18:54
Avatar de denied
denied
 
Fecha de Ingreso: octubre-2005
Ubicación: Barcelona - España
Mensajes: 52
Antigüedad: 18 años, 6 meses
Puntos: 0
De acuerdo Re: Obtener lista contactos Messenger PHP

Hola de nuevo,

Aquí os pego el script necesario para conectarse al MSN y Gmail y conseguir el listado de contactos, que sea mostrado en una siguiente pagina y ademas consigamos seleccionar a todos los contactos a quienes les deseamos enviar un mesaje.

El codigo esta completo, debeis activar la extensión php_curl en el archivo php.ini

El codigo para MSN, no funciona correctamente, funciona pero no al 100%, es lo unico que he podido conseguir, el de Gmail si que funciona perfectame.

A continuación el codigo:



get_details.php
Código PHP:
<HTML>
<
HEAD>
</
HEAD>
<
BODY>
<
table border="1">
<
tr>
<
TD>
        <!-- 
Login form -->
        <
form method="post" action="choose_contacts.php">
        <
table>
        <
tr>
        <
td>Username</td><td><input type="text" name="username" /></td>
        </
tr>
        <
tr>
        <
td>Password</td><td><input type="password" name="password" /></td>
        </
tr>
        <
tr>
        <
td colspan="2">Choose the service you wish to connect to.</td>
        </
tr>
        <
tr>
        <
td>MSN Messenger:<br /><input type="radio" name="service" value="msn" /></td>
        <
td>Gmail: <br /><input type="radio" name="service" value="gmail" /></td>
        </
tr>
        <
tr>
        <
td colspan="2"><input type="submit" value="Get contacts" /></td>
        </
tr>
        </
table>
        </
form>
</
TD>
<
TD>
        <!-- 
Important notes on the completion of the form -->
        <
b><p>
        
Contacts will not be immediately contacted
        
You will have an opportunity to select which of your contacts you wish to
        send an email to in the next page
.
        </
p></b>
</
TD>
</
TR>
<
TR>
<
td colspan="2">
        <!-- 
Description of what the tool does -->
        <
p>
        
This tool will allow you to get your contacts from either your Gmail account or
        
your MSN messenger account.  Your contacts will be displayed and you will be able to
        choose which contacts you want to email before any emails are sent
.
        </
p>
        <
p>
        
To grab your contacts from MSN messenger enter your full email in the username fieldyour password
        in the password field 
and then select MSN messenger.
        </
p>
        <
p>
        
To grab your contacts from Gmail enter your username (the part of your email address
        before the 
'@' symbolin the username fieldyour password in the password field and then
        select Gmail
.
        </
p>
</
td>
</
tr>
</
TABLE>
</
BODY>
</
HTML
choose_contacts.php
Código PHP:
<?PHP

//Get contacts

if((isset($_POST['username'])) && (isset($_POST['password']))) {
        
//Check to ensure that a username and password have been supplied
       
        
if($_POST['service'] == "msn") {
                
//The service is msn
               
                
include('msn_contact_grab.class.php');

                
$msn2 = new msn;

                
$returned_emails $msn2->qGrab($_POST['username'], $_POST['password']);
        }
        elseif(
$_POST['service'] == "gmail") {
                
//The service is gmail
               
                
include('libgmailer.php');
               
                
$gmailer = new GMailer();
                if (
$gmailer->created) {
                        
$gmailer->setLoginInfo($_POST['username'], $_POST['password'], 0);

                        
//uncomment if you need it
                        //$gmailer->setProxy("proxy.company.com");

                        
if ($gmailer->connect()) {
                                
// GMailer connected to Gmail successfully.
                                // Do something with it.

                                //Get the contacts
                                // For "Inbox"

                                
$gmailer->fetchBox(GM_CONTACT"all""");

                                
$snapshot $gmailer->getSnapshot(GM_CONTACT);


                                
//Outputs an array of the contacts
                                
$returned_emails $snapshot->contacts;

                               
                        } else {
                                die(
"Fail to connect because: ".$gmailer->lastActionStatus());
                        }
                } else {
                        die(
"Failed to create GMailer because: ".$gmailer->lastActionStatus());
                }
               
        }       
}


?>
<HTML>
<HEAD>


</HEAD>
<BODY>

<p>
Your contacts have been retrieved from the <?php echo $_POST['service']; ?> service.  Using the form below
you are able to choose which of your contacts you wish to be contacted.  Once you have made your
choices use the 'Send Emails' button to send an email to the contacts selected.
</p>

<form method="post" action="send_emails.php">
<table border="1">
<tr>
<td></td>
<td>Email</td>
<td>Name</td>
</tr>


<?PHP

//Create the form for all the emails returned from the contact list
if($_POST['service'] == "msn") {
       
        foreach(
$returned_emails as $row){
                echo 
"<tr>";
                echo 
'<td><input type="checkbox" name="emails[]" value="'.$row['0'].'" checked="checked"/></td>';
                echo 
'<td>'.$row['0'].'</td>';
                echo 
'<td>'.$row['1'].'</td>';
                echo 
"</tr>\n\n";
        };
}
elseif(
$_POST['service'] == "gmail") {
       
        foreach(
$returned_emails as $row){
                echo 
"<tr>";
                echo 
'<td><input type="checkbox" name="emails[]" value="'.$row['email'].'" checked="checked"/></td>';
                echo 
'<td>'.$row['email'].'</td>';
                echo 
'<td>'.$row['name'].'</td>';
                echo 
"</tr>\n\n";
        };
}

?>

</table>
<input type="submit" value="Send Emails" />
</form>
send_mails.php
Código PHP:
<?PHP

$subject 
"Some subject.";
$message "Hello Joe it's only me!";
$extra_header "From: [email protected]";

foreach (
$_POST['emails'] as $email){
               
        
mail($email$subject$message$extra_header);
       
}

echo 
"Emails sent.";

?>


Hasta aquí sería la aplicación necesaria, para pedir el email y password, luego seleccionar entre los contactos mostrados a los que deseamos enviarles el mensaje y el último fichero, realiza el envío a los contactos seleccionados.

Laslibrerías son demasiadas largas, para incluirlas en el post, si alguién las necesitara, pedirmelo por privado.Saludos a todos.
__________________
Retroceder Nunca, Rendirse Jamas
===============================

Última edición por denied; 23/01/2008 a las 11:50