I want to see XML data that is being POSTed via email.
The process:
1) XML POST is made to a PHP script.
2) The PHP script simply mails me the $_POST data via print_r($_POST, true)
as the message.
I am using PHPMailer and SimpleXML to accomplish this.
Here is my code which POSTs the XML:
$xml = new SimpleXMLElement('<lead/>');
$post_body = array_flip($template['post_body']);
array_walk_recursive($post_body, array($xml, 'addChild'));
$stream_options = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/xml
",
'content' => $xml->asXML(),
),
);
$context = stream_context_create($stream_options);
$response = file_get_contents($template['address'], null, $context);
$post_body
is an array which looks like this:
Array
(
[testbuyer] => buyerName
[tdunn5e@hatena.ne.jp] => testEmail
[Timothy] => leadFirstName
[world] => customTest2
)
Here is my code which sends the email:
try
{
$mailer = new PHPMailer();
$mailer->isSMTP();
$mailer->Host = EMAIL_HOST;
$mailer->Port = EMAIL_PORT;
$mailer->SMTPAuth = true;
$mailer->Username = EMAIL_USERNAME;
$mailer->Password = EMAIL_PASSWORD;
$mailer->setFrom(EMAIL_ADDRESS);
$mailer->addAddress('myemail@gmail.com');
$mailer->Subject = 'Test POST';
$mailer->Body = print_r($_POST, true);
$mailer->send();
$response = 'Mail sent OK';
}
catch (phpmailerException $e)
{
$response = $e->errorMessage();
}
catch (Exception $e)
{
$response = $e->getMessage();
}
I receive the email fine, but the message just shows an empty array. It looks like this:
Array
(
)
Why is this happening? I just want to see the XML in the message so I can verify its all working properly. Any help would be appreciated.