I need to extract the email address from "php://input" and render it within xml output – as part of the outlook ‘autodiscover.xml’ process. Working as expected, but I just need to pass the email address as the login name.
Here is the autodiscover.php I am working with, it works to pull the address, but I only get the username portion, not the entire UPN/address.
<?php
//get raw POST data so we can extract the email address
$raw = file_get_contents("php://input");
$matches = array();
preg_match('/<EMailAddress>([^@]+)@([^.]+).*</EMailAddress>/', $raw, $matches);
In the xml rendering code, these are the fields I am trying to populate with the entire email address, example [email protected]
This code renders only the "user123" as LoginName
<LoginName><?php echo $matches[1]; ?></LoginName>
<Domain><?php echo $matches[2]; ?></Domain>
I have tried $matches[0]; and it adds EMailAddress inline like so:
<LoginName>
<EMailAddress>[email protected]</EMailAddress>
</LoginName>
Is there a simple way to just pass the entire address for the ‘LoginName’ stanza?
What I have output with the above code:
<LoginName>user123</LoginName>
What I am trying to pass:
<LoginName>[email protected]</LoginName>
2
Answers
i think there might be an issue with your regex? try this:
preg_match('/<EMailAddress>([^<]+)</EMailAddress>/', $raw, $matches)
Parsing XML with regular expressions is hard to get right and always unreliable, but it’s trivial with SimpleXML:
Demo