Note that there are some explanatory texts on larger screens.

plurals
  1. POSimpleXMLElement Help with putting XML in PHP Mail
    primarykey
    data
    text
    <p>I'm having problems putting the contents of my XML webhook into a PHP mail script.... For some reason I can't access the variables... I must be doing something wrong...</p> <p>Can anyone help?</p> <pre><code> // Get XML data and read it into a string for use with SimpleXML $xmlData = fopen('php://input' , 'rb'); while (!feof($xmlData)) { $xmlString .= fread($xmlData, 4096); } fclose($xmlData); $xml = new SimpleXMLElement($xmlString); // Extract the name, email, country $user_email = trim($xml-&gt;email); $user_first_name = trim($xml-&gt;{'billing-address'}-&gt;{'first-name'}); $user_last_name = trim($xml-&gt;{'billing-address'}-&gt;{'last-name'}); $user_address1 = trim($xml-&gt;{'billing-address'}-&gt;address1); $user_address2 = trim($xml-&gt;{'billing-address'}-&gt;address2); $user_phone = trim($xml-&gt;{'billing-address'}-&gt;phone); $user_province = trim($xml-&gt;{'billing-address'}-&gt;province); $user_zip = trim($xml-&gt;{'billing-address'}-&gt;zip); $user_city = trim($xml-&gt;{'billing-address'}-&gt;city); $user_country = trim($xml-&gt;{'billing-address'}-&gt;country); $date = trim($xml-&gt;{'order'}-&gt;{'created-at'}); foreach ($xml-&gt;{'line-items'}-&gt;{'line-item'} as $lineItem) { array_push($productTitles, trim($lineItem-&gt;title)); } // multiple recipients $to = 'firstemail@hotmail.com'; // subject $subject = 'myemail Purchase - '.$user_first_name.' '.$user_last_name.''; $message = ' &lt;html&gt; &lt;head&gt; &lt;title&gt;myemail Purchase&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Here are the details&lt;/p&gt; &lt;table&gt;&lt;tr&gt;'; $message .= '&lt;td&gt;'.$user_first_name.' '.$user_last_name.'&lt;/td&gt;'; $message .= '&lt;td&gt;'; $message .= '&lt;/td&gt;'; $message .= '&lt;td&gt;'.$date.'&lt;/td&gt;'; $message .= '&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Charles &lt;myemail@hotmail.com&gt;' . "\r\n"; $headers .= 'From: myemail.com &lt;myemail.com&gt;' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); </code></pre> <p>Here is the XML I'm getting...</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;order&gt; &lt;buyer-accepts-marketing type="boolean"&gt;false&lt;/buyer-accepts-marketing&gt; &lt;cart-token nil="true"&gt;&lt;/cart-token&gt; &lt;closed-at type="datetime" nil="true"&gt;&lt;/closed-at&gt; &lt;created-at type="datetime"&gt;2005-07-31T15:57:11Z&lt;/created-at&gt; &lt;currency&gt;USD&lt;/currency&gt; &lt;email&gt;bob@customer.com&lt;/email&gt; &lt;financial-status&gt;paid&lt;/financial-status&gt; &lt;fulfillment-status nil="true"&gt;&lt;/fulfillment-status&gt; &lt;gateway&gt;bogus&lt;/gateway&gt; &lt;id type="integer"&gt;516163746&lt;/id&gt; &lt;note nil="true"&gt;&lt;/note&gt; &lt;number type="integer"&gt;1&lt;/number&gt; &lt;shop-id type="integer"&gt;820947126&lt;/shop-id&gt; &lt;subtotal-price type="integer"&gt;10.00&lt;/subtotal-price&gt; &lt;taxes-included type="boolean"&gt;false&lt;/taxes-included&gt; &lt;total-discounts type="integer"&gt;0.00&lt;/total-discounts&gt; &lt;total-line-items-price type="integer"&gt;10.00&lt;/total-line-items-price&gt; &lt;total-price type="integer"&gt;11.50&lt;/total-price&gt; &lt;total-tax type="integer"&gt;1.50&lt;/total-tax&gt; &lt;total-weight type="integer"&gt;0&lt;/total-weight&gt; &lt;updated-at type="datetime"&gt;2005-08-01T15:57:11Z&lt;/updated-at&gt; &lt;name&gt;#1001&lt;/name&gt; &lt;billing-address&gt; &lt;address1&gt;123 Amoebobacterieae St&lt;/address1&gt; &lt;address2&gt;&lt;/address2&gt; &lt;city&gt;Ottawa&lt;/city&gt; &lt;company&gt;&lt;/company&gt; &lt;country&gt;Canada&lt;/country&gt; &lt;first-name&gt;Bob&lt;/first-name&gt; &lt;id type="integer"&gt;943494288&lt;/id&gt; &lt;last-name&gt;Bobsen&lt;/last-name&gt; &lt;phone&gt;(555)555-5555&lt;/phone&gt; &lt;province&gt;Ontario&lt;/province&gt; &lt;shop-id type="integer"&gt;820947126&lt;/shop-id&gt; &lt;zip&gt;K2P0V6&lt;/zip&gt; &lt;name&gt;Bob Bobsen&lt;/name&gt; &lt;/billing-address&gt; &lt;shipping-address&gt; &lt;address1&gt;123 Amoebobacterieae St&lt;/address1&gt; &lt;address2&gt;&lt;/address2&gt; &lt;city&gt;Ottawa&lt;/city&gt; &lt;company&gt;&lt;/company&gt; &lt;country&gt;Canada&lt;/country&gt; &lt;first-name&gt;Bob&lt;/first-name&gt; &lt;id type="integer"&gt;943494288&lt;/id&gt; &lt;last-name&gt;Bobsen&lt;/last-name&gt; &lt;phone&gt;(555)555-5555&lt;/phone&gt; &lt;province&gt;Ontario&lt;/province&gt; &lt;shop-id type="integer"&gt;820947126&lt;/shop-id&gt; &lt;zip&gt;K2P0V6&lt;/zip&gt; &lt;name&gt;Bob Bobsen&lt;/name&gt; &lt;/shipping-address&gt; &lt;line-items type="array"&gt; &lt;line-item&gt; &lt;fulfillment-service&gt;manual&lt;/fulfillment-service&gt; &lt;grams type="integer"&gt;1500&lt;/grams&gt; &lt;id type="integer"&gt;642703538&lt;/id&gt; &lt;price type="integer"&gt;10.00&lt;/price&gt; &lt;quantity type="integer"&gt;1&lt;/quantity&gt; &lt;sku&gt;1&lt;/sku&gt; &lt;title&gt;Draft&lt;/title&gt; &lt;variant-id type="integer"&gt;47052976&lt;/variant-id&gt; &lt;vendor nil="true"&gt;&lt;/vendor&gt; &lt;name&gt;Draft - 151cm&lt;/name&gt; &lt;/line-item&gt; &lt;/line-items&gt; &lt;/order&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload