[英]AJAX call PHP file containing SendGrid email
我想通过单击按钮发送电子邮件,并使用Azure设置服务。
productPage.php
$(document).ready(function () {
$.ajax({
url: 'outbidEmail.php',
data: {},
type: 'post',
success:function(output) {
alert ("email sent");
}
});
});
outbidEmail.php
<?php
$url = 'https://api.sendgrid.com/';
$user = 'username removed';
$pass = 'password removed';
$to = 'abc@hotmail.com';
$subject = "Auction Website: You have been outbidded!";
$message = "
<html>
<head>
<title>You have been outbidded!</title>
</head>
<body>
<p>Heljko</p>
</body>
</html>
";
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $email_address,
'subject' => $subject,
'html' => $message,
'text' => 'testing body',
'from' => 'noreply@ajewfheuwfh.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);
// print everything out
print_r($response);
?>
单击按钮时将调用ajax函数-显示警报“已发送电子邮件”。 但是,没有收到电子邮件。 但是,这不太可能是用户名或密码问题,因为我们已经在其他地方收到了有关我们应用程序的电子邮件(但改用电子邮件)。
您可能需要添加以下行来阻止cURL验证对等方的证书:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.