What am i doing wrong? PHP & IMAP

Hello there i am hoping for some help. so when i call this function to mark a email i have opened as read, this is the following code:

function mark_email_as_read() {
	
	$user_id = $_SESSION[$this->session_prefix.'_user_id'];
	
	$msgnum = $this->common_model->search_get($this->url,'msgnumber');
	$acc = $this->common_model->search_get($this->url,'acc');
	$folder = $this->common_model->search_get($this->url,'accfolder');
	
	$ssl = false;

	$ssl=($ssl==false)?"/novalidate-cert":"";
		
			$host = $this->email_accounts[$this->the_helpdesk_view][$this->the_helpdesk_company]['server'];
			$port = $this->email_accounts[$this->the_helpdesk_view][$this->the_helpdesk_company]['port'];
			$folder = $this->email_accounts[$this->the_helpdesk_view][$this->the_helpdesk_company]['folder'];
			$user = $this->email_accounts[$this->the_helpdesk_view][$this->the_helpdesk_company]['user'];
			$pass = $this->email_accounts[$this->the_helpdesk_view][$this->the_helpdesk_company]['pass'];
		
	$this->imap = imap_open("{"."$host:$port/imap$ssl"."}$folder", $user, $pass);
	
	$uid = imap_uid($imap_connection, $msgnum);
	
	imap_setflag_full($imap_connection,$uid,"\\\\Seen",ST_UID);
			
	imap_headers($this->imap);

This is the error i am recieving:

Notice: Undefined variable: imap_connection in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/the_helpdesk.php on line 1548 Warning: imap_uid(): supplied argument is not a valid imap resource in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/the_helpdesk.php on line 1548 Notice: Undefined variable: imap_connection in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/the_helpdesk.php on line 1550 Warning: imap_setflag_full(): supplied argument is not a valid imap resource in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/the_helpdesk.php on line 1550

i dont understand where im going wrong and whats happeneing.

could you please help.

Hi Jamie, welcome to the forums!

I think the cause of the errors is this section of code:


$this->imap = imap_open("{"."$host:$port/imap$ssl"."}$folder", $user, $pass);

$uid = imap_uid($imap_connection, $msgnum);

imap_setflag_full($imap_connection,$uid,"\\\\Seen",ST_UID);

You’re opening a connection with imap_open and assigning it to $this->imap, but in the next line you’re using the variable $imap_connection. Probably what you want to be doing is this:


$this->imap = imap_open("{"."$host:$port/imap$ssl"."}$folder", $user, $pass);

$uid = imap_uid($this->imap, $msgnum);

imap_setflag_full($this->imap, $uid, "\\\\Seen", ST_UID);