2017-10-05 10 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를 사고 싶은 슬림 POP 패널 조명을 LED 크기 : 15 인치 전력 : 15 와트 친절하게 나에게 보내 가격 및 기타 세부 .. 필수 입력란 : - " –