dsykx64220 2015-09-15 10:05
浏览 1051

使用Content-type:application / xml发送POST数据

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog