[英]How to Fetch Particular part of email body using PHP(imap function)?
My email body contains the Email and Phone Number fields I want to extract that fields and store in the database how can I do that? 我的电子邮件正文包含要提取的“电子邮件”和“电话号码”字段,并将其存储在数据库中,我该怎么做? This is my PHP Code...
这是我的PHP代码...
<?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);
?>
I m providing the screen shot of the my Email Body, In This whatever infront of Email and Mobile Number. 我要提供“电子邮件正文”的屏幕快照,无论电子邮件和手机号码的任何形式。 I want to extract that.
我要提取出来。
You could try 你可以试试
$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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.