2017-10-05 4 views
0

メールの本文にメールと電話番号のフィールドが含まれています。フィールドを抽出してデータベースに保存したいのですが、どうすればいいですか? これは私が電子メールや携帯電話番号のこの何でもインフロントでは、私の電子メール本文のスクリーンショットを提供メートル...フェッチ方法PHP(imap関数)を使用して電子メール本文の特定の部分を取得しますか?

<?php 

$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; 
$username = "myusername"; 
$password = "mypassword"; 

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 


$emails = imap_search($inbox,"ALL"); 

if($emails) { 
$output = ''; 

foreach($emails as $email_number) { 

$headerInfo = imap_headerinfo($inbox,$email_number); 
$structure = imap_fetchstructure($inbox, $email_number); 

$overview = imap_fetch_overview($inbox,$email_number,0); 

$message = imap_qprint(imap_fetchbody($inbox,$email_number,1)); 


$output .= 'Body: '.$message.'<br />'; 
$structure = imap_fetchstructure($inbox, $email_number); 
print_r($structure); 
} 
} 
imap_close($inbox); 

?> 

私のPHPコードです。私はそれを抽出したい。 enter image description here

答えて

1

あなたは

$message = "Business Enquiry for Lister --------- Buyer Contact I 
nformation:aaaaa Mobile/ Cell Phone: +91--------, Email: Not Available<br> 
Buyer's ment Details: We want to buy Lister Gold UV LED Slim POP 
Panel Lights. Size: 15 Inches Power: 15 Watts Kindly send 
me price and other details. d Qty : -"; 


preg_match('# Mobile/ Cell Phone: (.*?), #', $message, $match);// checks for string between "Mobile/ Cell Phone: " and "," 
echo $mobile = $match[1]; 

preg_match('/Email:(.*?)<br> /', $message, $match);//// checks for string between "Email:" and "<br>" 
echo $email = $match[1]; 
+0

ありがとう@Muhammed Hafilを試みることができます。私は空の配列を取得していますが、両方のハイフンを削除した場合、配列要素として 'Email:'が得られます。そのパターンを精緻化できますか? –

+0

あなたは$メッセージにあるものを投稿してください。 –

+0

$ message = "リスターのビジネスのお問い合わせ--------- 買い手の連絡先:aaaaa 携帯電話:+91 ------- - 、 電子メール:
買い手の要件の詳細は使用できません: 我々はリスターゴールドUV LEDスリムPOPパネルのライトを購入したい サイズ:15インチ 電力:15ワット は親切に私に価格やその他の詳細を送信 。必要な数量: - " –

関連する問題