【发布时间】:2021-03-02 16:45:05
【问题描述】:
发送付款页面以通过 sendgrid 发送带有表单数据的电子邮件。之前的开发者在不久前就做了这个,直到一个月左右之前都可以正常工作。
我认为问题出在身份验证上,因为他们使用电子邮件 + 密码作为 $user 和 `$pass.更新了密码以使用 sendgrid 生成的 API 密钥。付款提交很好,所以我知道问题一定出在下面的代码中。
$url = 'https://api.sendgrid.com/';
$user = 'apikey';
$pass = 'apikeyhere';
$categories = 'Bill Payment';
$json_string = array(
'to' => array(
'test1@email.com', 'test@email.com'
),
'category' => $categories,
'filters' => array('templates' => array('settings' => array('enable' => 1, 'template_id' => '7c4ecc93-8575-a46a3d-9864-97sabedf54119')))
);
$full_name = $_POST['billing-address-first-name'].' '.$_POST['billing-address-last-name'];
$address1 = $_POST['billing-address-address1'];
$city = $_POST['billing-address-city'];
$state = $_POST['billing-address-state'];
$postal = $_POST['billing-address-zip'];
$phone = $_POST['billing-address-phone'];
$amount = $_POST['billing-address-bill-total'];
$email = $_POST['billing-address-email'];
$discountField = $_POST['discount-code'];
if($discountField != ''){
$discCode = $discountField;
}else{
$discCode = 'N/A';
}
$body = "Thank you for paying online.<br/>This email can serve as your receipt.<br/><br/>";
$body = $body. "Name: $full_name<br/>";
$body = $body. "Address: <a href='#' style='text-decoration:none;color: #005044;'>$address1 $city, $state $postal</a><br/>";
$body = $body. "Phone: $phone<br/>";
$body = $body. "Amount: $amount<br/><br/>";
$body = $body. "Discount Code Applied: $discCode<br/><br/>";
$body = $body. "As always, if there are any questions or concerns please email us at <a href='mailto:email@email.com</a>.";
// Send email to person submitting hte payment.
$params = array(
'api_user' => $user,
'api_key' => $pass,
'x-smtpapi' => json_encode($json_string),
'to' => $email,
'subject' => "Online Payment Receipt",
'html' => $body,
'text' => $body,
'from' => 'info@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);
// Send email to Nolan Painting as well.
$params = array(
'api_user' => $user,
'api_key' => $pass,
'x-smtpapi' => json_encode($json_string),
'to' => 'steve@email.com',
'subject' => "Nolan Painting - Online Payment Receipt",
'html' => $body,
'text' => $body,
'from' => 'info@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);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
【问题讨论】: