Google Community
Latest Forums Rules Resources
Custom Search

Go Back   Google Community > Google Forums > Gmail Forum

GoogleCommunity Sponsor
Cirtex Hosting
Use coupon "forum" for 50% Off!

Reply
 
LinkBack Thread Tools Display Modes
Old 01-26-2007, 08:19 PM   #1 (permalink)
Noogle
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
aussie123 is on a distinguished road
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
aussie123 is offline   Reply With Quote
 
Sponsored Links
Old 02-01-2007, 06:36 PM   #2 (permalink)
Noogle
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
aussie123 is on a distinguished road
anyone

Can anyone help me out here PLEASEEEEE
aussie123 is offline   Reply With Quote
Old 02-09-2007, 12:57 PM   #3 (permalink)
Noogle
 
Join Date: Feb 2007
Location: Atlanta
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
dziemecki is on a distinguished road
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.
dziemecki is offline   Reply With Quote
Old 02-12-2007, 10:07 PM   #4 (permalink)
Noogle
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
aussie123 is on a distinguished road
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
aussie123 is offline   Reply With Quote
Old 02-13-2007, 07:08 AM   #5 (permalink)
Noogle
 
Join Date: Feb 2007
Location: Atlanta
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
dziemecki is on a distinguished road
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:
foreach ($snapshot2->contacts as $item2) { 
Then put this over it:

PHP Code:
print_r($snapshot2->contacts); 
And try this under it:

PHP Code:
echo $item2
So it looks like this:

PHP Code:
print_r($snapshot2->contacts);
foreach (
$snapshot2->contacts as $item2) {
echo 
$item2
The print should display the entire source object. The echo should display the individual item being looped through. Hopefully, that will give you a little hint. If not, you may need to try a different importer.
dziemecki is offline   Reply With Quote
Old 02-13-2007, 11:01 PM   #6 (permalink)
Noogle
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
aussie123 is on a distinguished road
thanks

sorry but i do not understand.
i am not a programmer or php hacker of any kind.
thanks anyway.
aussie123 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -8. The time now is 07:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004–2007 Google Community