【问题标题】:Azure SendGrid SMTP giving 500 errorAzure SendGrid SMTP 给出 500 错误
【发布时间】:2018-05-01 19:56:55
【问题描述】:

我正在尝试在我的 Azure 应用程序上实现 SendGrid,但它一直在浏览器上抛出 HTTP ERROR 500。我正在使用完全相同的代码遵循本教程,但输入了我的值。我似乎找不到任何关于如何解决这个问题的信息,以及我可以判断这些值是正确的。错误发生在创建Swift_SmtpTransport::newInstance() 方法时。

这里是sn-p的代码:

$text = "Hi!\nHow are you?\n";
$html = "<html>
    <head></head>
    <body>
        <p>Hi!<br>
            How are you?<br>
        </p>
    </body>
    </html>";
// This is your From email address
$from = array('someone@example.com' => 'Test User');
// Email recipients
$to = array(
    'toemail@email.com' => 'Elite Email Address'
);
// Email subject
$subject = 'Example PHP Email';

// Login credentials
$username = 'myusernamefromazure';
$password = 'mypassword';

// Setup Swift mailer parameters
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587); <-- this is where the error is thrown...

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: php azure sendgrid


    【解决方案1】:

    sendgrid 网站上的教程看起来有点不同:

    <?php
    // using SendGrid's PHP Library
    // https://github.com/sendgrid/sendgrid-php
    
    // If you are using Composer (recommended)
    require 'vendor/autoload.php';
    
    // If you are not using Composer
    // require("path/to/sendgrid-php/sendgrid-php.php");
    
    $from = new SendGrid\Email("Example User", "test@example.com");
    $subject = "Sending with SendGrid is Fun";
    $to = new SendGrid\Email("Example User", "test@example.com");
    $content = new SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
    $mail = new SendGrid\Mail($from, $subject, $to, $content);
    
    $apiKey = getenv('SENDGRID_API_KEY');
    $sg = new \SendGrid($apiKey);
    
    $response = $sg->client->mail()->send()->post($mail);
    echo $response->statusCode();
    print_r($response->headers());
    echo $response->body();
    

    来源: https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/php.html

    【讨论】:

    • 我试过了,现在在$from = new SendGrid\Email("Example User", "test@example.com");出现同样的错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2014-09-25
    • 2014-04-23
    • 1970-01-01
    相关资源
    最近更新 更多