【问题标题】:How to install phpMailer on azure Web App如何在 azure Web App 上安装 phpMailer
【发布时间】:2016-07-15 17:14:12
【问题描述】:

我一直在研究 azure 邮件服务中的许多解决方案,我认为对我来说最好的解决方案是使用 phpMailer。我已经尝试过使用 sendgrid API,但我想使用带有 jquery/javascript 的 Ajax post 方法。

我还找到了另一个涉及 CURL 的解决方案。但是我在

上遇到错误
Dotenv::load(__DIR__);

错误似乎来自 sendGrids 自己的 php 文件。

如何在 azure 上解决这些问题。

我使用的代码如下:

<?php

require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_apikey = getenv('YOUR_SENDGRID_APIKEY');
$sendgrid = new SendGrid($sendgrid_apikey);
$url = 'https://api.sendgrid.com/';
$pass = $sendgrid_apikey;
$template_id = '<your_template_id>';
$js = array(
  'sub' => array(':name' => array('Elmer')),
  'filters' => array('templates' => array('settings' => array('enable' => 1, 'template_id' => $template_id)))
);

$params = array(
    'to'        => "test@example.com",
    'toname'    => "Example User",
    'from'      => "you@youremail.com",
    'fromname'  => "Your Name",
    'subject'   => "PHP Test",
    'text'      => "I'm text!",
    'html'      => "<strong>I'm HTML!</strong>",
    'x-smtpapi' => json_encode($js),
  );

$request =  $url.'api/mail.send.json';

// Generate curl request
$session = curl_init($request);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $sendgrid_apikey));
// 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);

?>

祝你好运,斯坦纳

【问题讨论】:

  • 你是说你想用PHPMailer,但你没用?
  • 是的,我希望使用它。我只是对如何在 azure web 应用程序上安装库感到困惑,所以如果你知道我为什么会收到错误,我发布了另一个解决方案。我已经检查了 phpinfo No phpmailer 库,除非我正在寻找错误的变量。
  • PHPMailer 是一个外部库,它不是 PHP 的一部分。您可以从here 获取它并将其与您的其他 PHP 库和文件一起上传,或者(推荐的方式)使用composer 加载它。将您的代码基于随附的示例。

标签: php azure curl phpmailer sendgrid


【解决方案1】:

phpMailer是一个邮件服务器,需要PHP运行时开启SMTP服务器,需要开启25端口。很遗憾,我们无权在 Azure Web Apps 上执行此操作。

我建议您使用第 3 部分邮件服务器从 Azure Web 应用程序上的应用程序发送电子邮件。在 Azure 上,您可以轻松地使用 SendGrid 来满足这一点,请参阅https://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-php-how-to-send-email/ 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 2023-01-22
    • 2021-07-24
    • 2021-09-28
    • 1970-01-01
    相关资源
    最近更新 更多