2012-10-10 56 views
1

我遇到了電子郵件同步應用程序的問題,我正在爲我的項目開發對話模塊,所以我從電子郵件帳戶中提取了電子郵件正文和附件,但問題是我還在電子郵件正文中獲得了一些標題文本像從電子郵件正文中刪除標題

"--PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: text/plain --PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 " 

,我想刪除它

實際產量

--PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: text/plain --PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: multipart/related; boundary="PHP-related-9ce0b24f8d52c4d37de61cb315107795d140f8b7" --PHP-related-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: text/html Dear Milind 

Thank you for choosing XXXXX for your limo hire. 

Please accept this e-mail as confirmation the following booking has been 
confirmed and requires you to print, sign and return the attached 
contract with us, either by e-mail, fax or post, within 3 days. 
To view contract for booking please click here 
We would like to draw your attention to our agreed Terms and 
Conditions concerning the booking and ask that you ensure you comply, 
which can be found on our website www.xxxxx.co.uk 

If this has been received in error, please contact our Office 
immediately on XXXXXXX or XXXXXX. 

Regards 
Company name 
TEL: 

,我想是這樣

Dear Milind 

    Thank you for choosing XXXXX for your limo hire. 

    Please accept this e-mail as confirmation the following booking has been 
    confirmed and requires you to print, sign and return the attached 
    contract with us, either by e-mail, fax or post, within 3 days. 
    To view contract for booking please click here 
    We would like to draw your attention to our agreed Terms and 
    Conditions concerning the booking and ask that you ensure you comply, 
    which can be found on our website www.xxxxx.co.uk 

    If this has been received in error, please contact our Office 
    immediately on XXXXXXX or XXXXXX. 

    Regards 
    Company name 
    TEL: 

我已經嘗試substr()但它不是有用 任何正則表達式可能? 這裏是電子郵件發送 代碼讓我們假設體字符串= $email_message所有電子郵件格式寫在「字符串」 PS:請注意,有些郵件包含附件

$subject = 'A sample email - Dual Format plus attachment plus inline'; 

// Create a boundary string. It needs to be unique (not in the text) so ... 
// We are going to use the sha1 algorithm to generate a 40 character string: 
$sep = sha1(date('r', time())); 

// Define the headers we want passed. 
$headers = "From: StarLimosine <[email protected]> \r\n X-Mailer: Custom PHP Script"; 
//$headers.="\r\nCc:[email protected]"; 
$headers.="\r\nBcc:[email protected] , [email protected]"; 
// Add in our primary content boundary, and mime type specification: 
$headers .= 
    "\r\nContent-Type: text/html; boundary=\"PHP-mixed-{$sep}\""; 

// Prepare our attachment file - Read it in, encode it and split it 
//$attached = chunk_split(base64_encode(file_get_contents('attachment.zip'))); 

// Also now prepare our inline image - Also read, encode, split: 
$inline = chunk_split(base64_encode(file_get_contents('images/Logo.png'))); 

// Now the body of the message. 
$body =<<<EOBODY 
--PHP-mixed-{$sep} 
Content-Type: multipart/alternative; boundary="PHP-alt-{$sep}" 

--PHP-alt-{$sep} 
Content-Type: text/plain 


--PHP-alt-{$sep} 
Content-Type: multipart/related; boundary="PHP-related-{$sep}" 

--PHP-related-{$sep} 
Content-Type: text/html 

$email_message 
<strong> 
Star Limousines<br/> 
TEL: 0800 9 556 556 <br/> 
or 01435 813494</strong><br/> 
<span style="font-size:10px">Registerd Office Pick Hill Farm, Horam East Sussex TN21 0JR</span> 

--PHP-mixed-{$sep}-- 
EOBODY; 
$body=$email_message; 

mail($to,$subject,$body); 
+0

響應問題就出在你的電子郵件的提取方法即可。使用適當的MIME庫,而不是在之後嘗試修復它。 – mario

+0

你可以請描述更多或給我的網址或東西? –

+0

你不應該自己生成啞劇電子郵件。 [PHPMailer](http://phpmailer.worxware.com)和[Swiftmailer](http://swiftmailer.org)可以爲你提供更少的代碼。 –

回答

1

在任何時間點上,標題是在前兩行是正確的?如果是這樣的話,你可以這樣做:

substr($email, strpos($email, PHP_EOL, strpos($email, PHP_EOL) + 1)); 
+0

謝謝Praveen它的幫助它修復了我的一些問題,但不是全部 –

+0

還有哪些其他問題? –

+1

感謝Praveen,但PHP梅勒爲我工作! –

0

只有當你使用GET發佈數據時才加這個刪除這個。

$headers .= 
    "\r\nContent-Type: text/html; boundary=\"PHP-mixed-{$sep}\""; 

你會得到無頭

相關問題