【发布时间】:2015-11-10 23:34:16
【问题描述】:
我想在用户填写并提交表单后向他们发送电子邮件,我使用 POST 方法来捕获数据,现在我想用表单中捕获的变量替换静态文本。我已经从表单中提供了一些可变的数据样本。
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$uri = 'https://mandrillapp.com/api/1.0/messages/send.json';
$postString = '{
"key": "xxxxxxxxxxxxx",
"message": {
"html": "this is the emails html content",
"text": "this is the emails text content",
"subject": "this is the subject",
"from_email": "me@gmail.com",
"from_name": "John",
"to": [
{
"email": "me@yahoo.com",
"name": "Bob"
}
],
"headers": {
},
"track_opens": true,
"track_clicks": true,
"auto_text": true,
"url_strip_qs": true,
"preserve_recipients": true,
"merge": true,
"global_merge_vars": [
],
"merge_vars": [
],
"tags": [
],
"google_analytics_domains": [
],
"google_analytics_campaign": "...",
"metadata": [
],
"recipient_metadata": [
],
"attachments": [
]
},
"async": false
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($ch);
echo $result;
【问题讨论】: