【发布时间】:2018-03-14 17:07:47
【问题描述】:
我想通过单击按钮发送电子邮件并使用 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 函数 - 显示“已发送电子邮件”警报。但是,没有收到任何电子邮件。但是,这不太可能是用户或密码的问题,因为我们已经在其他地方收到了我们的应用程序的电子邮件(但使用 a 代替)。
【问题讨论】: