2

At the top of my index.php file I have:

require('sendgrid-php/SendGrid_loader.php');

And at the bottom I use this code to send the email:

    <?php
       if(isset($_POST['submit']))
          {


          $sendgrid = new SendGrid('app11445063@heroku.com', 'password');

         $mail = new SendGrid\Mail();
          $mail->
             addTo('email@gmail.com')->
             setFrom('app11445063@heroku.com')->
             setSubject('Subject goes here')->
             setText('Hello World!')->
             setHtml('<strong>Hello World!</strong>');

          $sendgrid->
            smtp->
             send($mail);
    }
 ?>

I can't get the code to send an email out. I have the proper account from SendGrid and Heroku. The required files are in my directory. Do I have the wrong path to the required file?

4

2 回答 2

1

The issue was that the SendGrid library was not in the repository in Heroku. Just do a "git status" and add the directory to the commit and then push the directory to Heroku. Make sure you also have the correct path in the "include" in your PHP code.

于 2013-01-31T15:59:06.053 回答
0

I believe this has to do with Sendgrid's PHP lib. If you are using SMTP (you must if using heroku) you must also have swiftmailer installed. Otherwise the line 25 won't work in sendgrid-php/SendGrid/Smtp.php

public function __construct($username, $password){
/* check for SwiftMailer,
 * if it doesn't exist, try loading
 * it from Pear
 */
if (!class_exists('Swift')) {
  require_once 'swift_required.php';
}
于 2013-10-22T01:29:15.197 回答