【发布时间】:2014-09-01 21:01:49
【问题描述】:
正如标题所述,电子邮件已收到,但不包括所有数据(姓名、电子邮件、电话、主题、消息)。
<?php
$url = 'https://api.sendgrid.com/';
$user = 'username';
$pass = 'password';
//HTML grab
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$params = array(
'api_user' => "$user",
'api_key' => "$pass",
'to' => "email@gmail.com",
'subject' => "Submission Inquiry",
'html' => "<html><head><title> Contact Form</title><body>
Name: $name\n<br>
Email: $email\n<br>
Subject: $subject\n<br>
Message: $message <body></title></head></html>",
'text' => "
Name: $name\n
Email: $email\n
Phone: $phone\n
Subject: $subject\n
$message",
'from' => "email@email.com",
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// Redirect to thank you page upon successfull completion, will want to build one if you don't alreday have one available
header('Location: ../success.html'); // feel free to use whatever title you wish for thank you landing page, but will need to reference that file name in place of the present 'thanks.html'
exit();
// print everything out
print_r($response);
?>
我的网站是http://geniecleaningcare.com
我做错了什么?这是我第一次编写 PHP 页面!在此先感谢您的帮助。
编辑:电子邮件正文如下所示:
--===============6352432520243076444==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Name:=20
Email:=20
Phone:=20
Subject:=20
=20=20=20=20=
--===============6352432520243076444==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
<html><head><title> Contact Form</title><body>
Name:=20
<br>
Email:=20
<br>
Subject:=20
<br>
Message: <body></title></head></html>=
--===============6352432520243076444==--
还有一些其他的数据,不过都和消息头什么的有关。
【问题讨论】:
-
它包括任何主体吗?查看邮件来源
-
我们可以看到你得到的错误,任何日志吗?
-
添加了消息中的信息。我不确定 =20 是什么意思或它来自哪里。看起来底部的 标签应该是 吗?我改了,测试了,还是不行。
-
只是为了排除前端表单,您是否在发送电子邮件之前验证了 POST 字段实际上包含正确的数据?
-
想通了!我没有在我的 HTML 的输入字段中添加 name="email"!那么现在它工作得很好。谢谢你让我检查:-)