ここで私の初心者の状態を許してください...
(HostGator) 電子メール アカウントから電子メールをダウンロードし、それらを解析してブラウザ ウィンドウに表示する必要があります。次に、ブラウザの印刷機能を使用してそれらを印刷します...
テキストのみのバージョンが機能するようになりましたが、このプロジェクトには画像/添付ファイルも表示する必要があります。Web には断片的なものがたくさんありますが、すべてを解決するソリューションはありません。それらの多くは機能していないようです!
私はこれに何週間もイライラしています。
PECL Mailparse と PHP IMAP 拡張機能をインストールしました (ただし、別のソリューションの方が優れている場合は、そのソリューションには慣れていません)。
誰かがこれに対する解決策を持っていますか、または私に連絡してこれを処理してくれますか? この時点で、私は最初に生まれた子供にあなたの名前を付けることを誓います!
これが私の既存のコードです:
<?php
// This seems to be rx'ed by the PHP Master tutorial for dealing w attachments, but draws code errors???
// include 'emailAttachments.inc';
// connects successfuly to the inmate database, where I store the received emails
include 'includes/dbConnect.inc';
// connects successfully to the email hosting service
include 'includes/emailConnect.inc';
/* get the emails */
//$emails = imap_search($inbox,'UNSEEN'); //Restore this one once done testing; only new ones show
$emails = imap_search($inbox,'ALL'); //This is for testing, so ALL emails show up w/out re-sending new
/* if emails are returned, cycle through each... */
if($emails) {
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get the overview part to the email */
$overview = imap_fetch_overview($inbox,$email_number,0);
// returns the structure (NOT the data within the structure...)
$structure = imap_fetchstructure($inbox,$email_number,0);
/* get body part of this email */
/* note that passing FT_PEEK as the 4th param prevents the email being marked as 'read' on server */
if ($message = imap_fetchbody($inbox,$email_number,1.1)=='') {
$message = imap_fetchbody($inbox,$email_number,1);
}
// an earlier attempt...
// Below includes FT_PEEK, which keeps messages from being excluded in subsequent runs of this code...
/*if ($message = imap_fetchbody($inbox,$email_number,1.1,FT_PEEK)=='') {
$message = imap_fetchbody($inbox,$email_number,1,FT_PEEK);
}*/
$message = trim(quoted_printable_decode($message));
$trimmedRecipient = trim(str_replace('"','',$overview[0]->to)); // Used in CBS_Inmate table query
// Used to add data to CBS_Email table on INSERT query, below
$emlTimestamp = $overview[0]->date;
$emlTo = trim(str_replace('\\','',$overview[0]->to));
$emlTo = trim(str_replace('"','',$overview[0]->to));
/*$emlFrom = htmlentities($overview[0]->from, ENT_QUOTES);*/
$emlFrom = getSetMaskedEmailAddress(htmlentities($overview[0]->from, ENT_QUOTES));
$emlSubject = $overview[0]->subject;
// Prepare and use the current Client/recipient to retrieve full Client info from table...
$pareEmailAdd = strtolower(strtok(str_replace('"','',$overview[0]->to),"@")); // l.c and pre-@
$emailAdd = $pareEmailAdd; // copy it to final var, so if no more processing...
if (substr_count($pareEmailAdd,"<")>0) { // if there still a '<' in there
$pareEmailAdd = strtok($pareEmailAdd, "<"); // take the '<' out
$emailAdd = trim(strtok(" ")); // like this...
}
// Lookup on the Inmates (Client) table to see if there is a matching, active client...
if (inmateFoundCount($mysqli, $emailAdd) > 0) {
?>
// ..... (Page layout, wherein I echo various parts of the email)
<?php
} else if ($emailAdd = 'webmaster') {
echo '<p> </p><p style="color:red">WEBMASTER received a contact. <a href="https://gator2005.hostgator.com:2096/cpsess9352445381/3rdparty/roundcube/?_task=mail" target="_blank">Click here to Login to HostGator email.</a></p><p> </p>';
} else {
echo '<p> </p>Received Invalid/Inactive/Non-Client Email: (' . $emailAdd . ')<p> </p><p> </p>';
} // Ends the 'If Inmate Found Count' process
$nuthin = "";
$email_Query = 'INSERT INTO `CBS_Email` ' .
'VALUES ("' .
$nuthin . '","' .
$emlTimestamp . '","' .
$emailAdd . '","' . // TO
trim(addslashes($emlFrom)) . '","' . // FROM
trim(addslashes($emlSubject)) . '","' . // SUBJECT
trim(addslashes($message)) . '","' . // MESSAGE
$nuthin . '","' .
$overview . '","' .
date("Y-m-d H:i:s") . '")';
$emailResult = $mysqli->query($email_Query) or die($mysqli->error.__LINE__);
} // Ends 'ForEach $Email' loop
} else {
echo "<br /><br /><br /> ";
?><A HREF="javascript:history.back()"><< back</A><?php
echo " NO NEW MESSAGES in '" . strtoupper($username) . "' ";
?><a href="javascript:document.location.reload();">refresh >></a>
<?php
} // Ends the 'If $Email' process
?>
<!-- end .content --></div>
<div class="footer">
<!-- end .footer --></div>
<?php
/* close the connection */
imap_close($inbox);
function getSetMaskedEmailAddress($emailFrom) {
// connect to the inmate database
include 'includes/dbConnect.inc';
$Query = "SELECT * FROM `CBS_Email_Address_Masking` WHERE `unMaskedEmail` = '". $emailFrom . "'";
$result = $mysqli->query($Query) or die($mysqli->error.__LINE__);
$return = $result->fetch_assoc();
$Found_maskedEmail = $return['maskedEmail'];
$Query = "SELECT * FROM `CBS_Email_Address_Masking` WHERE `maskedEmail` = '". $emailFrom . "'";
$result = $mysqli->query($Query) or die($mysqli->error.__LINE__);
$return = $result->fetch_assoc();
$Found_unMaskedEmail = $return['unMaskedEmail'];
if ($Found_maskedEmail) {
// Found a Masked Email for the passed Unmasked Email. Return the Masked Email.
return $Found_maskedEmail;
} else if ($Found_unMaskedEmail) {
// Found an Unmasked Email for the passed Masked Email. Return the Unmasked Email.
return $Found_unMaskedEmail;
} else {
// Failed to find any entries. Create a new Masked Email, and create a table entry containing the new Masked Email and the passed Unmasked Email. Return the new Masked Email.
$randomNewMaskedEmail = rand(1,1000000000) . '@MaskedEmailAddress.com';
$nuthin = "";
$maskEmailQuery = 'INSERT INTO `CBS_Email_Address_Masking` VALUES ("' .
$nuthin . '","' .
date("Y-m-d H:i:s") . '","' .
$emailFrom . '","' . // Masked Email Address
$randomNewMaskedEmail . '")'; // Unmasked Email Address
$emailResult = $mysqli->query($maskEmailQuery) or die($mysqli->error.__LINE__);
return $randomNewMaskedEmail;
}
}
function pageHits($clientEmail) {
// connect to the inmate database
include 'includes/dbConnect.inc';
$Query = "SELECT * FROM `CBS_Inmates` WHERE `emailAddress` = '". $clientEmail . "'";
$result = $mysqli->query($Query) or die($mysqli->error.__LINE__);
$numberResult = $result->fetch_assoc();
$Query = "SELECT * FROM `CBS_Hit_Counts` WHERE `number` = '". $numberResult['number'] . "'";
$result = $mysqli->query($Query) or die($mysqli->error.__LINE__);
$hitCount = $result->num_rows;
Return $hitCount;
}
function featuredClientCount($clientEmail) {
// connect to the inmate database
include 'includes/dbConnect.inc';
$Query = "SELECT * FROM `CBS_Inmates` WHERE `emailAddress` = '". $clientEmail . "'";
$result = $mysqli->query($Query) or die($mysqli->error.__LINE__);
$numberResult = $result->fetch_assoc();
$Query = "SELECT * FROM `CBS_Featured_Clients` WHERE `number` = '". $numberResult['number'] . "'";
$result = $mysqli->query($Query) or die($mysqli->error.__LINE__);
$numberResult = $result->fetch_assoc();
$hitCount = $result->num_rows;
Return $hitCount;
}
function randomQuote() {
// connect to the inmate database
include 'includes/dbConnect.inc';
$query = "SELECT * FROM `CBS_Inspirational_Quotes` ORDER BY rand() LIMIT 1";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$quote = $result->fetch_assoc();
$fullQuote = '<p>"' . $quote['quoteText'] . '"</p><p style="margin-top:-5px;"><em>–' . $quote['quoteBy'] . '</em></p>';
return $fullQuote;
}
function spitClientsAddress($clientEmail) {
// connect to the inmate database
include 'includes/dbConnect.inc';
$addressQuery = "SELECT * FROM `CBS_Inmates` WHERE `emailAddress` = '". strtok($clientEmail,"@") . "'";
$result = $mysqli->query($addressQuery) or die($mysqli->error.__LINE__);
$address = $result->fetch_assoc();
$spitAddress = '<p>' .
strtoupper($address['firstName']) . ' ' .
strtoupper($address['lastName']) . ' ' .
'(' . strtoupper($address['number']) . ')';
$spitAddress .= '<br />' .
$address['address1'];
$spitAddress .= '<br />' .
$address['address2'];
$spitAddress .= '<br />' .
$address['city'];
$spitAddress .= ', ' .
strtoupper($address['state']);
$spitAddress .= ' ' .
$address['zip'];
$spitAddress .= '</p>';
return $spitAddress;
}
// This function decodes and extracts the attachments from the email
function getAttachments($imap, $mailNum, $part, $partNum) {
$attachments = array();
if (isset($part->parts)) {
foreach ($part->parts as $key => $subpart) {
if($partNum != "") {
$newPartNum = $partNum . "." . ($key + 1);
}
else {
$newPartNum = ($key+1);
}
$result = getAttachments($imap, $mailNum, $subpart,
$newPartNum);
if (count($result) != 0) {
array_push($attachments, $result);
}
}
}
else if (isset($part->disposition)) {
if ($part->disposition == "ATTACHMENT") {
$partStruct = imap_bodystruct($imap, $mailNum,
$partNum);
$attachmentDetails = array(
"name" => $part->dparameters[0]->value,
"partNum" => $partNum,
"enc" => $partStruct->encoding
);
return $attachmentDetails;
}
}
return $attachments;
}
function inmateFoundCount($mysqli, $emailAdd) {
$inmates_Query = "SELECT * FROM `CBS_Inmates` WHERE (`inmateOrAdvertiser` = 'I') AND (`deactivateAccount` = 'N') AND (`emailAddress` = '" . $emailAdd . "') LIMIT 1";
$inmateResult = $mysqli->query($inmates_Query) or die($mysqli->error.__LINE__);
return $inmateResult->num_rows; // RETURN THE COUNT
}
?>