RSS
 

Archive for the ‘PHP’ Category

PHP: Gmail with RoundCube

12 Aug

Some times I have problem accessing Gmail because of some Firewall restrictions. Or I would like to have my own WebMail client for my mail service hosted with Google Apps. I tried several setting and I found out that it is not that difficult just you have to know the right parameters.

Here are the parameters that worked for me:
In your main.inc.php try to modify these setting:

// IMAP settings
$rcmail_config['default_host'] = 'ssl://imap.gmail.com:993';
$rcmail_config['default_port'] = 993;
$rcmail_config['imap_auth_type'] = null;

$rcmail_config['username_domain'] = 'gmail.com';
$rcmail_config['mail_domain'] = 'gmail.com';

//SMTP settings
$rcmail_config['smtp_server'] = 'ssl://smtp.gmail.com';
$rcmail_config['smtp_port'] = 465;
$rcmail_config['smtp_user'] = '%u';
$rcmail_config['smtp_pass'] = '%p';

//MBox settings
$rcmail_config['drafts_mbox'] = '[Gmail]/Drafts';
$rcmail_config['junk_mbox'] = '[Gmail]/Spam';
$rcmail_config['sent_mbox'] = '';
$rcmail_config['trash_mbox'] = '';
$rcmail_config['default_imap_folders'] = array('INBOX', 'Drafts', 'Sent', 'Junk', 'Trash');

[ad#AdBrite inline]

If you want to try. I made this setting on my sub domain mygmail.kristou.com. It is a RoudCube with the above settings.

 
2 Comments

Posted in PHP

 

PHP: Write to ini file array containing array

22 Jun
public function write_ini_file($data, $path, $mode) {

		foreach ($data as $key => $item) {
			if (is_array($item)) {
				$content .= "\n[$key]\n";
				foreach ($item as $key2 => $item2) {
					if(is_array($item2)){
						foreach ($item2 as $key3 => $item3) {
							$content .= $key2."[] = \"".$item3."\"\n";
						}
					} else {
						$content .= "$key2 = \"$item2\"\n";
					}
				}
			} else {
				$content .= "$key = \"$item\"\n";
			}
		}

		if (!$handle = fopen($path, $mode)) {
			return false;
		}

		if (!fwrite($handle, $content)) {
			return false;
		}

		fclose($handle);
		return true;
	} // end write_ini_file()

[ad#AdBrite inline]

 
No Comments

Posted in PHP

 

PHP: Append content to file

14 Jun
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "New Stuff 1\n";
fwrite($fh, $stringData);
$stringData = "New Stuff 2\n";
fwrite($fh, $stringData);
fclose($fh);
 
No Comments

Posted in PHP

 

PHP: String token for string split

14 Jun
< ?
$token = strtok($string,",");
while($token){
  print($token . "");
  $token = strtok(",");
}
?>

[ad#AdBrite inline]

 
No Comments

Posted in PHP

 

PHP: Find string between 2 strings

14 Jun

While looking in the Internet for a good function to strip a string, I found this blog where this function is implemented.
[code brush="php"] function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$fullstring = "this is my [tag]dog[/tag]";
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
echo $parsed; // (result = dog)
[/code]

 
No Comments

Posted in PHP