Title: SendGrid WordPress Plugin + Official PHP Client Library
Last modified: August 9, 2017

---

# SendGrid WordPress Plugin + Official PHP Client Library

 *  [heyitsstacey](https://wordpress.org/support/users/heyitsstacey/)
 * (@heyitsstacey)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/sendgrid-wordpress-plugin-official-php-client-library/)
 * Hi guys,
 * I’m hoping someone can help me understand the relationship between this plugin
   and SendGrid’s own PHP Client Library ([https://github.com/sendgrid/sendgrid-php](https://github.com/sendgrid/sendgrid-php)).
   Looking at the plugin documentation at SendGrid’s website, it looks like there’s
   at least some cross-referencing happening, but I didn’t see all of the same library
   files in the plugin. Attempting to post a new campaign using an installed copy
   of the library while the plugin is activated results in an error (“Fatal error:
   Cannot declare class SendGrid\Email, because the name is already in use in /xxxxx/
   sendgrid-php/lib/helpers/mail/Mail.php on line 877”). Am I able to use any other
   library functions to access non email/contact endpoints with just the plugin 
   activated?
 * If it’s helpful, I’m ultimately trying to create and send a new campaign based
   on a WP_Query for the day’s curated posts.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Anonymous User 12640152
 * (@anonymized-12640152)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/sendgrid-wordpress-plugin-official-php-client-library/#post-9398086)
 * Hello.
 * You get this error because our plugin already comes with the official sendgrid-
   php library.
 * Our plugin currently uses version v4.0.2 of the sendgrid-php library to send 
   emails through SMTP or the SendGrid API.
 * Thank you,
    SendGrid
 *  Thread Starter [heyitsstacey](https://wordpress.org/support/users/heyitsstacey/)
 * (@heyitsstacey)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/sendgrid-wordpress-plugin-official-php-client-library/#post-9398207)
 * That’s great! Is there a good way to reference the library? I think I might still
   be missing something.
 * At the moment, I just have a test file called email-sendgrid.php that requires
   the wp-load.php file so that I can use WordPress functions. Previously, I also
   required the sendrid-php.php file, which resulted in the fatal error about SendGrid/
   Email already being in use. Removing that manually loaded sendgrid-php library,
   I get “Fatal error: Uncaught Error: Class ‘SendGrid’ not found in /email-sendgrid.
   php:188 Stack trace: #0 {main} thrown in /email-sendgrid.php on line 188”
 *  Anonymous User 12640152
 * (@anonymized-12640152)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/sendgrid-wordpress-plugin-official-php-client-library/#post-9400513)
 * Hello.
 * The library code should be automatically loaded into WordPress existing pages.
   If you want to create a custom PHP page for your WordPress installation, there
   are a few tutorials and examples on the web.
 * We tested it this way and it works:
 *     ```
       <?php
          	 require_once(dirname(__FILE__) . '/wp-config.php');
   
           	$wp->init();
           	$wp->parse_request();
           	$wp->query_posts();
           	$wp->register_globals();
           	$wp->send_headers();
   
       	$email = new SendGrid\Email();
       	$email
           		->setFrom('my.email@my.domain.com')
           		->setHtml('<strong>Hello World!</strong>')
           		->addCategory('customCategory')
       	;
   
       	wp_mail('my.email@my.domain.com', 'Subject goes here' . site_url(), 'Message goes here', $email);
       ?>
       ```
   
 * We saved this file as test.php in the root directory of the WordPress installation
   and accessed it as [http://ourwebsite.com/test.php](http://ourwebsite.com/test.php)
 * You might encounter some issues depending on how your .htaccess file is configured
   for your website.
 * We hope this helps! Let us know if it worked for you.
 * Thank you,
    SendGrid
 *  Thread Starter [heyitsstacey](https://wordpress.org/support/users/heyitsstacey/)
 * (@heyitsstacey)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/sendgrid-wordpress-plugin-official-php-client-library/#post-9407857)
 * Thank you for the snippet! It hasn’t quite worked for me yet, but I’ll keep playing
   with the configuration and see what I can come up with.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘SendGrid WordPress Plugin + Official PHP Client Library’ is closed to
new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/sendgrid-email-delivery-simplified_264460.
   svg)
 * [SendGrid](https://wordpress.org/plugins/sendgrid-email-delivery-simplified/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sendgrid-email-delivery-simplified/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sendgrid-email-delivery-simplified/)
 * [Active Topics](https://wordpress.org/support/plugin/sendgrid-email-delivery-simplified/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sendgrid-email-delivery-simplified/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sendgrid-email-delivery-simplified/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [heyitsstacey](https://wordpress.org/support/users/heyitsstacey/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/sendgrid-wordpress-plugin-official-php-client-library/#post-9407857)
 * Status: not resolved