2015-05-14 138 views
0

你好,我有電子郵件,我發送給我的客戶看起來像: $body = '<div>my email content</div>'; ,我需要從谷歌API添加到$ body變量此腳本:如何用JavaScript初始化php變量?

<script type="application/ld+json"> 
{ 
    "@context": "http://schema.org", 
    "@type": "LodgingReservation", 
    "reservationNumber": "abc456", 
    "reservationStatus": "http://schema.org/Confirmed", 
    "underName": { 
    "@type": "Person", 
    "name": "John Smith" 
    }, 
    "reservationFor": { 
    "@type": "LodgingBusiness", 
    "name": "Hilton San Francisco Union Square", 
    "address": { 
     "@type": "PostalAddress", 
     "streetAddress": "333 O'Farrell St", 
     "addressLocality": "San Francisco", 
     "addressRegion": "CA", 
     "postalCode": "94102", 
     "addressCountry": "US" 
    }, 
    "telephone": "415-771-1400" 
    }, 
    "checkinDate": "2017-04-11T16:00:00-08:00", 
    "checkoutDate": "2017-04-13T11:00:00-08:00" 
} 
</script> 

我該怎麼辦呢?有任何想法嗎? 我不能改變「爲」。

回答

0

你的問題不明確,我認爲這什麼方法是你在找什麼。 您可以使用Ajax,使用jQuery AJAX $.ajax({}); 用於實現跨瀏覽器的AJAX支持你使用ajax發送該數組到您執行郵件功能的php文件。只需使用$_GET$_POST獲取數據。然後將數據附加到您的郵件正文中。

請參閱底層鏈接以閱讀jquery ajax文檔。 http://api.jquery.com/jquery.ajax/

2

如果我的理解這個問題,這應該是你在尋找什麼:

$script = <<<EOF 
<script type="application/ld+json"> 
{ 
    "@context": "http://schema.org", 
    "@type": "LodgingReservation", 
    "reservationNumber": "abc456", 
    "reservationStatus": "http://schema.org/Confirmed", 
    "underName": { 
    "@type": "Person", 
    "name": "John Smith" 
    }, 
    "reservationFor": { 
    "@type": "LodgingBusiness", 
    "name": "Hilton San Francisco Union Square", 
    "address": { 
     "@type": "PostalAddress", 
     "streetAddress": "333 O'Farrell St", 
     "addressLocality": "San Francisco", 
     "addressRegion": "CA", 
     "postalCode": "94102", 
     "addressCountry": "US" 
    }, 
    "telephone": "415-771-1400" 
    }, 
    "checkinDate": "2017-04-11T16:00:00-08:00", 
    "checkoutDate": "2017-04-13T11:00:00-08:00" 
} 
</script> 
EOF; 

$body = '<div>my email content</div>' . $script; 

更多heredoc

可能是你需要使用ヶ輛()方法來將特殊字符編碼

+0

沒錯! !非常感謝你。 – pey22