2015-05-14 137 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