I did resolve this issue.
#!/usr/bin/php -q
<?php
/**/
//setup global $_SERVER variables to keep WP from trying to redirect
$_SERVER = array(
"HTTP_HOST" => "domain.com",
"SERVER_NAME" => "domain.com",
"REQUEST_URI" => "/email_pipe/reader.php", // location of this file
"REQUEST_METHOD" => "GET"
);
//require the WP bootstrap
require_once('/home/user/public_html/wp-load.php');
switch_to_blog(70);
//include email parser
require_once('/home/user/public_html/email_pipe/include/rfc822_addresses.php');
require_once('/home/user/public_html/email_pipe/include/mime_parser.php');
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd))
{
$email .= fread($fd, 1024);
}
fclose($fd);
//create the email parser class
$mime=new mime_parser_class;
$mime->ignore_syntax_errors = 1;
$parameters=array(
'Data'=>$email,
);
$mime->Decode($parameters, $decoded);
//---------------------- GET EMAIL HEADER INFO -----------------------//
//get the name and email of the sender
$fromName = $decoded[0]['ExtractedAddresses']['from:'][0]['name'];
$fromEmail = $decoded[0]['ExtractedAddresses']['from:'][0]['address'];
//get the name and email of the recipient
$toEmail = $decoded[0]['ExtractedAddresses']['to:'][0]['address'];
$toName = $decoded[0]['ExtractedAddresses']['to:'][0]['name'];
//get the subject
$subject = $decoded[0]['Headers']['subject:'];
if (!$subject) {$subject = "(no subject)";}
$removeChars = array('<','>');
//get the message id
$messageID = str_replace($removeChars,'',$decoded[0]['Headers']['message-id:']);
//get the reply id
$replyToID = str_replace($removeChars,'',$decoded[0]['Headers']['in-reply-to:']);
//---------------------- FIND THE BODY -----------------------//
//get the message body
if(substr($decoded[0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Body'])){
$body = $decoded[0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Parts'][0]['Body'];
}
//create email message
$email = "
Message ID: $messageID
Reply ID: $replyToID
Subject: $subject
To: $toName $toEmail
From: $fromName $fromEmail
Body: $body
";
$email_post = "
To: $toName $toEmail
From: $fromName $fromEmail
Subject: $subject
$body
";
// Create post object
$my_post = array(
'post_title' => $subject,
'post_content' => $email_post,
'post_status' => 'publish',
'post_author' => 52,
'post_type' => 'ticket'
);
// Insert the post into the database
$new_post = wp_insert_post( $my_post );
// Update status to: New
$wpdb->insert(
'blog_70_term_relationships',
array(
'object_id' => $new_post,
'term_taxonomy_id' => 5
),
array(
'%d',
'%d'
)
);
// Update priority to: High
$wpdb->insert(
'blog_70_term_relationships',
array(
'object_id' => $new_post,
'term_taxonomy_id' => 3
),
array(
'%d',
'%d'
)
);
// Update type to: Start
$wpdb->insert(
'blog_70_term_relationships',
array(
'object_id' => $new_post,
'term_taxonomy_id' => 17
),
array(
'%d',
'%d'
)
);
// Send email
//mail('[email protected]',$subject, $email);
?>
Things I discovered through trial and error…
The EOL (end of line) Conversion for the file had to be Unix and not Windows format. I think it also had to be created in UTF-8 and not ANSI.
I had to specify the server variables at the beginning or the switch_to_blog() function wouldn’t work at all.
After the new post was created I had to use MySQL queries to update the post’s taxonomy because it wouldn’t work using the WordPress functions. I think this was because they didn’t recognize the switch_to_blog() function.