Page 1 of 1

Forward email using IMAP

Posted: Thu Dec 20, 2007 2:14 pm
by redbrad0
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a php page that connects to my email [s]thru[/s] [size=150][color=green]through[/color][/size] IMAP. How can I tell a email to forward to another email address? Below is the code I am currently using.

Code: Select all

//check for new messages
$mailbox = imap_open("{localhost:143/notls}INBOX", "email@address.com", "password")
	or die("Can't connect: " . imap_last_error());;

// Check messages
$check = imap_check($mailbox);
 
if ($check->Nmsgs=='0')	{
	echo "There are no messages that need to be handled"; 	
}	else	{
	/* Lets force to just work with the first email */
	$emailIndex = 1;

	echo "Processing email " . $emailIndex . "<br>";
	$header = imap_header($mailbox, $emailIndex);
	print("<PRE>");
	print("Header Date : " . $header->Date . "<BR>");
	print("Header To : " . $header->to) . "<BR>";
	print("Header From : " . $header->from . "<BR>");
	print("Header cc : " . $header->cc . "<BR>");
	print("Header ReplyTo : " . $header->ReplyTo . "<BR>");
	print("Header Subject : " . $header->Subject . "<BR></PRE>");

	/* Forward the email to another email address here */
	
}
die;

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]11.[/b] Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.[/quote]