Automatically forwarding email

the mail() function

Moderators: macek, egami, gesf

ashajf
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Aug 24, 2012 5:45 pm

Automatically forwarding email

Postby ashajf » Fri Aug 24, 2012 5:49 pm

HI..!!
I wanted to write a script to forward my gmail unread messages to another one of my account automatically. I wanted to do this in php.
First I wanted to fetch the unread messages and tried below code. :/

<?php
//fucntion to get unread emails taking username and password as parametes
$username = 'XXXXX@gmail.com';

$password = 'XXXXX';

function check_email($username, $password)
{
//url to connect to
$url = "https://mail.google.com/mail/feed/atom";

// sendRequest
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
curl_close($curl);
//returning retrieved feed
return $curlData;

}

//making page to behave like xml document to show feeds
header('Content-Type:text/xml; charset=UTF-8');
//calling function
$feed = check_email("username", "password");
echo $feed;
?>

But I am getting following error. Seems like there is something wrong in the xml format. Can somebody help with this?? Or it would also be great if someone can provide me help with full code to automatically forward unread gmail.

XML Parsing Error: junk after document element
Location: http://127.0.0.1/unread.php
Line Number 2, Column 1:<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
^

I am wondering whether this is the right way to automatically forward my gmail...!!!
I am new and donno the direction...!! :( :(


Thanks in advance...!!1 :) :) :) :D

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest