Received: from outmail4.bc.edu (18.104.22.168) by BFRANKLIN04.bc.edu
(192.168.1.34) with Microsoft SMTP Server id 14.2.347.0; Thu, 9 Jan 2014
Received: from o1.outreach.nercomp.org (o1.outreach.nercomp.org
[22.214.171.124]) by krait.bc.edu (8.14.5/8.14.5) with SMTP id s09EqQix012162
for <email@example.com>; Thu, 9 Jan 2014 09:52:27 -0500
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=outreach.nercomp.org;
s=smtpapi; bh=DvaYBQwmkNJzfT2Ef9kY09h415E=; b=Kg0JHzVv4X8KksSDVc
Received: by mf253.sendgrid.net with SMTP id mf253.19201.52CEB7AA5 Thu,
09 Jan 2014 14:52:26 +0000 (UTC)
Received: from prod3.jjcbigideas.com (unknown [126.96.36.199]) by mi24 (SG)
with ESMTP id 143777d7221.2da7.f27c for <firstname.lastname@example.org>; Thu, 09
Jan 2014 08:52:26 -0600 (CST)
Received: from nercomp by prod3.jjcbigideas.com with local (Exim 4.82)
(envelope-from <email@example.com>) id 1W1GyA-0008Uc-2Q for
firstname.lastname@example.org; Thu, 09 Jan 2014 08:52:26 -0600
Subject: NERCOMP - Security Training and Risk Assessment - Feb 10
Content-Type: text/html; charset="ISO-8859-1"
Date: Thu, 9 Jan 2014 08:52:26 -0600
I want it to pipe emails to a PHP script (which I've got working but now need to read the data). So when someone sends an email to this email address it will be forwarded to the PHP script and will filter out all the data I want an insert it into the database.
Maybe I didn't understood your initial request: you have a form to send an email, let's say with the mail() function, and you want also to save the input to the database, correct? Or you want to access the inbox of an email account to read the headers and the body of the received messages?
No I want the received email inserted into the database.
Whenever someone sends an email to my websites email address it is piped to a PHP script, I then want the information (that was piped) filtered to get who it was sent from who it's sent to, subject and body which I will then insert into the database.
Whenever someone sends an email to my websites email address it is piped to a PHP script
Ok, but I hope I can make you understand that when an email message is received by your website, in practice is received by the mail server associated with your domain name.
This does not involve the web server (Apache for example) and neither the PHP engine. So you cannot redirect directly what is received by the mail server to a PHP script.
You can only access the email account and parse the received messages.
Imap, if supported by your mail server, is a protocol that allows to easily access email accounts, otherwise you can use POP3, which is supported also by the Fetch library suggested in the previous post, as example of connection, it could start with two or three arguments:
# for imap
$server = \Fetch\Server('imap.domain.tld', 993);
# for pop3
$server = \Fetch\Server('pop3.domain.tld', 995, 'pop3');
By default the third argument is imap so it can be avoided in the first example. It is just like a connection string to a database. The second argument is the port, and the first is the server path.
If, for example, you want to parse the mails from your GMail account you would do:
$server = new \Fetch\Server('pop.gmail.com', 995, 'pop3');
# set username and password
# get 3 messages
$messages = $server->getMessages(3);
foreach ($messages as $message)
echo "Subject: " . $message->getSubject() . PHP_EOL;
echo "Header: ".PHP_EOL;
In the case of the GMail example you will need an application password and to enable the IMAP and/or POP3 access. But a part these peculiarities, most of the procedure is the same for all the hosts, just check the Server.php class to see the options for the connection and the Message.php class to retrieve the information from each email message.
Thanks but I pretty much need immediate email action so once an email comes in I need it placed in the database, that is why I like the piping system but sadly email headers couldn't be anymore cluttered with crap so it's hard to filter out information so I guess this is my only option.