|
||||||||||
|
|||||||
| GoogleCommunity Sponsor |
Use coupon "forum" for 50% Off! |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Noogle
![]() Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Gmail Contacts Importer
I was hoping someone here experienced with PHP and Gmail can help me find this error in my Gmail Contacts Importer script.
It was working just fine a while ago but now I get the following error after i enter the username and password of my Gmail user account and press the submit button. Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/louis/gmail.php on line 117 The Following is the code on line 117 foreach ($snapshot2->contacts as $item2) { The following is the full code in the PHP file that contains this error. Code:
<?php
require("libgmailer.php");
if($_POST['login'])
{
$php_userid = $_POST['login'];
$php_password = $_POST['passwd'];
$sender = $_POST['login'];
$gmail_acc = $php_userid;
$gmail_pwd = $php_password;
$gmail_tmz = "+2";
$gm = new GMailer();
$gm->setLoginInfo($gmail_acc,$gmail_pwd,$gmail_tmz);
if ($gm->connect()) {
showList($php_userid,$php_password,$sender);
}
else{
login_form("ERROR: Invalid User Name or password");
}
}
else
{
login_form("");
}
////////////////////////////////////////////////////////////////////////////////////////////////
function login_form($errcode)
{
?>
<html>
<head>
<title>Google Mail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" bordercolor="#111111" width="400" id="AutoNumber1" bgcolor="#CCCCFF">
<tr>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="msn.php">MSN</a></b></font></div>
</td>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="yahoomail.php">Yahoo!</a></b></font></div>
</td>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="hotmail.php">Hotmail</a></b></font></div>
</td>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="gmail.php">GMail</a></b></font></div>
</td>
</tr>
</table>
<div align="center" style="border: #000000; border-style: solid; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; width:400px;">
<form method="post" action="gmail.php" autocomplete=on name="login_form" >
<table id="yreglgtb" summary="form: login information">
<tbody>
<tr>
<td colspan="2">
<div align="center">
<p><font face="Arial, Helvetica, sans-serif" size="5"><b><font size="4">Import GMail Contacts</font></b></font></p>
<p><img src="gmail.gif"></p>
</div>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" bordercolor="#111111" width="400" id="AutoNumber1">
<tr>
<td width="100%">
<p><font face="Arial, Helvetica, sans-serif" size="2"><b>Note: Privacy Statement-
Your ID and Password is not saved and will be cleared. All this does is
invite your contact list to check out this site. It's 100% safe to use.</b></font></p>
<p><font face="Arial, Helvetica, sans-serif" size="2">Please be patient
after clicking the invite button <b>once</b>. <b>Note:</b> There are tick
boxes beside the e-mail addresses - if you wish not to invite a particular
person / e-mail address then un-tick it. </font></p>
</td>
</tr>
</table></td>
</tr>
<tr>
<th><label for="username">Gmail Address:</label></th>
<td><input name="login" id="login" value="" size="17" class="yreg_ipt" type="text"></td>
</tr>
<tr>
<th><label for="passwd">Password:</label></th>
<td><input name="passwd" id="passwd" value="" size="17" class="yreg_ipt" type="password"></td>
</tr>
<tr><td colspan="2"><font face ="Arial" size="2" color="red"><b><?echo $errcode; ?></b></font></td></tr>
</tbody></table>
<input value="Sign In" type="submit">
</form>
</div>
</body>
</html>
<?
}
function showList($theUser,$thePassword,$theSender){
$gmail_tmz2 = "+2";
$retString = "";
$gm2 = new GMailer();
$gm2->setLoginInfo($theUser,$thePassword,$gmail_tmz2);
$gm2->connect();
$gm2->fetchBox(GM_CONTACT, "all", 0);
$snapshot2 = $gm2->getSnapshot(GM_CONTACT);
$myfile = "addresses.txt";
$fh = fopen($myfile, 'a');
foreach ($snapshot2->contacts as $item2) {
$retString .= "<tr><td><input name=\"addresses[]\" value=\"" . $item2["email"] . "\" checked=\"checked\" type=\"checkbox\"></td><td>" . $item2["email"]. "</td>";
fwrite($fh, $item2["email"] . "\n");
}
?>
<html>
<head>
<title>Google Mail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function togglechecked(){
for (var i = 0; i < document.inviteform.elements.length; i++) {
var e = document.inviteform.elements[i];
if ((e.disabled == false) && (e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.inviteform.allbox.checked;
}
}
}
function toggleselect(){
document.inviteform.allbox.checked = !document.inviteform.allbox.checked;
togglechecked();}
</script>
</head>
<body>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" bordercolor="#111111" width="400" id="AutoNumber1" bgcolor="#CCCCFF">
<tr>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="msn.php">MSN</a></b></font></div>
</td>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="yahoomail.php">Yahoo!</a></b></font></div>
</td>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="hotmail.php">Hotmail</a></b></font></div>
</td>
<td width="25%">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b><a href="gmail.php">GMail</a></b></font></div>
</td>
</tr>
</table>
<div align="center" style="border: #000000; border-style: solid; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; width:400px;">
<form method="post" action="gmail2.php" autocomplete=on name="inviteform" >
<table id="yreglgtb" summary="form: login information" border="0" cellspacing="4" cellpadding="4">
<tbody>
<tr>
<td colspan="2">
<div align="center"><p><font face="Arial, Helvetica, sans-serif" size="5"><b><font size="4">Import GMail Contacts</font></b></font></p>
<p><img src="gmail.gif"></p>
</div>
</td>
</tr>
<tr>
<td bgcolor="#cccccc"><input name="allbox" id="allbox" value="nothing" onclick="togglechecked()" checked="checked" type="checkbox"></td>
<td bgcolor="#cccccc"><b>E-Mail Address</b>
<input type="hidden" name="sender" value="<? echo $theSender; ?>"></td>
</tr>
<?
echo $retString;
?>
<tr><td><input name="allbox2" value="nothing" onclick="toggleselect()" checked="checked" type="checkbox"></td><td><a href="javascript:toggleselect()">Select/Deselect All</a></td></tr>
</tbody></table>
<input value="Send Invitation" type="submit">
</form>
</div>
</div>
</body>
</html>
<?
}
?>
Any help here would be greatly appreciated. My email address is roxboy_@hotmail.com if you want to contact me directly. Regards Aussie123 Last edited by intelliot; 02-09-2007 at 03:26 PM. Reason: use code tags |
|
|
|
|
Sponsored Links
|
|
|
|
#3 (permalink) |
|
Noogle
![]() Join Date: Feb 2007
Location: Atlanta
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Ok. I'll bite. My first guess is that "$snapshot2->contacts" is not populating. Try adding an echo there to write out the value before attempting to read it. or add some error trapping to fail if it's null.
|
|
|
|
|
|
#4 (permalink) |
|
Noogle
![]() Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
hi
Hey thanks for the advice here but unfortunately i do not know any php or programming.
Any chance you can show me what i need to add to the script to try and fix it. Thanks for your help here. Regards Lance |
|
|
|
|
|
#5 (permalink) |
|
Noogle
![]() Join Date: Feb 2007
Location: Atlanta
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Fraid not. The problems you're having are almost certainly environmental. I can't duplicate your issues without your environment. But you don't really need a lot of PHP skills to trouble shoot this. Try this. Find the line:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| unknown contacts | Fi3rizi0 | Gmail Forum | 2 | 03-11-2007 04:57 AM |
| save gmail contacts | petergriffen | Gmail Forum | 3 | 08-05-2006 05:25 PM |
| Exporting Contacts | Travis Lopes | Gmail Forum | 0 | 07-04-2005 10:19 AM |
| Importing Gmail Contacts Into Outlook | priapos | Gmail Forum | 0 | 04-19-2005 11:33 AM |
| How To Import Contacts | Jt0323 | Gmail Forum | 0 | 12-17-2004 08:20 PM |