Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method 'mail' not found in SendGrid\Client #424

Closed
TeodorVecerdi opened this issue Aug 31, 2017 · 13 comments
Closed

Method 'mail' not found in SendGrid\Client #424

TeodorVecerdi opened this issue Aug 31, 2017 · 13 comments
Labels
status: help wanted requesting help from the community type: question question directed at the library

Comments

@TeodorVecerdi
Copy link

Issue Summary

While attempting to run the mail example (The one with the Mail Helper class) I encountered a error.
I have tried both the Composer and the direct library and the same problem occurs.
On this line $response = $sg->client->mail()->send()->post($mail); on mail() I get Method 'mail' not found in SendGrid\Client.
After that everything falls apart

Steps to Reproduce

Not needed.

Technical details:

  • sendgrid-php Version: 6.0 (latest)
  • PHP Version: 7.1.9
@thinkingserious
Copy link
Contributor

Hi @TeodorVecerdi,

My apologies, I can not reproduce. Here are the steps I took:

mkdir test
cd ./test
code composer.json

composer.json

{
    "require": {
      "sendgrid/sendgrid": "~6.0"
    }
 }
code test.php

code.php

<?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("DX Team", "dx@sendgrid.com");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email("Elmer Thomas", "elmer.thomas@sendgrid.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();
php test.php

The email was sent successfully.

Could you please walk me through your install steps?

Thanks!

With Best Regards,

Elmer

@thinkingserious thinkingserious added status: help wanted requesting help from the community type: question question directed at the library labels Aug 31, 2017
@TeodorVecerdi
Copy link
Author

Thanks for the quick reply, @thinkingserious !
Here are the steps I followed:
sendemail.php and composer.json are the same as your files.
then I did

composer install

and then php sendemail.php
and this is what I got:

J:\Development\GitHub\PHP\test>php sendemail.php
PHP Fatal error: Uncaught Error: Call to undefined function SendGrid\curl_init() in J:\Development\GitHub\PHP\test\vendor\sendgrid\php-http-client\lib\Client.php:142
Stack trace:
#0 J:\Development\GitHub\PHP\test\vendor\sendgrid\php-http-client\lib\Client.php(214): SendGrid\Client->makeRequest('post', 'https://api.sen...', Object(SendGrid\Mail), NULL)
#1 J:\Development\GitHub\PHP\test\sendemail.php(17): SendGrid\Client->__call('post', Array)
#2 {main}
thrown in J:\Development\GitHub\PHP\test\vendor\sendgrid\php-http-client\lib\Client.php on line 142

@thinkingserious
Copy link
Contributor

@TeodorVecerdi
Copy link
Author

@thinkingserious I have installed curl and added it to the path. I don't understand what I should do.

@thinkingserious
Copy link
Contributor

@TeodorVecerdi,

Now that you have done that, what happens when you do composer install?

@TeodorVecerdi
Copy link
Author

Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
Installing sendgrid/php-http-client (3.7.0): Loading from cache
Installing sendgrid/sendgrid (6.0.0): Loading from cache
Writing lock file
Generating autoload files

@thinkingserious
Copy link
Contributor

Ok, that looks good. How about when you run php sendemail.php?

@TeodorVecerdi
Copy link
Author

The same error

@TeodorVecerdi
Copy link
Author

PHP Fatal error: Uncaught Error: Call to undefined function SendGrid\curl_init() in J:\Development\GitHub\PHP\test\vendor\sendgrid\php-http-client\lib\Client.php:142
Stack trace:
#0 J:\Development\GitHub\PHP\test\vendor\sendgrid\php-http-client\lib\Client.php(214): SendGrid\Client->makeRequest('post', 'https://api.sen...', Object(SendGrid\Mail), NULL)
#1 J:\Development\GitHub\PHP\test\sendemail.php(17): SendGrid\Client->__call('post', Array)
#2 {main}
thrown in J:\Development\GitHub\PHP\test\vendor\sendgrid\php-http-client\lib\Client.php on line 142

@thinkingserious
Copy link
Contributor

For some reason your install of php7 is not finding curl_init().

Can you try stepping through these steps?

@thinkingserious
Copy link
Contributor

@TeodorVecerdi
Copy link
Author

I'm on windows, this is my first time doing this. Curl was disabled in php.ini indeed. Thank you for the help @thinkingserious

@thinkingserious
Copy link
Contributor

Awesome, thanks for following up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

2 participants