I have a script that checks emails and puts them in a database. This works fine when new emails are composed and sent. However, if I reply to an email the imap_fetchbody does not work and it is empty.
Where am I going wrong here?
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$structure = imap_fetchstructure($inbox,$email_number);
$message = imap_fetchbody($inbox,$email_number,0);
$header = imap_headerinfo($inbox,$email_number);
//print_r($structure);
//make sure emails are read or do nothing
if($overview[0]->seen = 'read'){
//strip everything below line
$param="## In replies all text above this line is added to the ticket ##";
$strip_func = strpos($message, $param);
$message_new = substr($message,0,$strip_func );
/* output the email body */
$output.= '<div class="body">'.$message_new.'<br><br></div>';
If I output the $message instead of the $message_new so before I start stripping the text everything is displayed.
If that line “In replies…” is not present in the message at all,
strposwill return booleanfalse, which when coerced to an integer will be 0.So when you ask for the substring from 0 to the position, you’re asking for the substring from 0 to 0, and
$message_newis empty.Check if that line is present in the mail before you try to take a substring based on it.