CC and BCC fields aren't working. BCC is required for integration with a 3rd party service, so multiple TO fields aren't an option for me.
Test case:
mkdir sgtest && cd sgtest
composer init -s dev
composer require sendgrid/sendgrid 2.0.3
echo "<?php return ['username'=>'', 'password'=>'']; ?>" > cfg.php
# Add your username and password to cfg.php
curl https://gist.githubusercontent.com/lexicalbits/9669433/raw/61ee6a296734d4aaad708fdd7a482780e886e60a/gistfile1.php > run.php
php run.php
If you use the default emails in the test, you can verify the results here:
http://mailinator.com/inbox.jsp?to=sgtest_to
http://mailinator.com/inbox.jsp?to=sgtest_cc
http://mailinator.com/inbox.jsp?to=sgtest_bcc
The test gist: https://gist.github.com/lexicalbits/9669433
My setup:
Ubuntu Server 12.04 in KVM
PHP from https://launchpad.net/~ondrej/+archive/php5
php -v
PHP 5.5.4-1+debphp.org~precise+1 (cli) (built: Sep 27 2013 12:39:52)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
Ok, so this is actually by design with the way the our Web API works. I've talked to our team and it might be something we change in the future. Until then, you will have to go through our smtp library for this. You can do it using swiftmailer - http://swiftmailer.org/ - and this bit of example code:
<?php
require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$sendgrid_username = $_ENV['SENDGRID_USERNAME'];
$sendgrid_password = $_ENV['SENDGRID_PASSWORD'];
$to = $_ENV['TO'];
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername($sendgrid_username);
$transport->setPassword($sendgrid_password);
$mailer = Swift_Mailer::newInstance($transport);
$message = new Swift_Message();
$message->setTo($to);
$message->setCc("[email protected]");
$message->addBcc("[email protected]");
$message->setFrom($to);
$message->setSubject("[smtp-php-example] Owl named %yourname%");
$message->setBody("%how% are you doing?");
$header = new Smtpapi\Header();
$header->addSubstitution("%yourname%", array("Mr. Owl"));
$header->addSubstitution("%how%", array("Owl"));
$message_headers = $message->getHeaders();
$message_headers->addTextHeader("x-smtpapi", $header->jsonString());
try {
$response = $mailer->send($message);
print_r($response);
} catch(\Swift_TransportException $e) {
print_r($e);
print_r('Bad username / password');
}
Thank you for the update and the code sample. Until the API changes, it might be worth throwing an exception if a web API call contains a CC or a BCC. There's no way a user would be able to figure this restriction out on their own.
This is a very good idea.
Hi scott
I am unable to run the above file because it gives me an error Fatal error: Class 'Dotenv' not found.
And can you please specify in detail what all i need to run a sendgrid email. I downloaded all your github files and i am confused on how to use them
Hi @prashanthpanyam - take a look here for some working code examples:
https://github.com/sendgrid/sendgrid-php-example
But otherwise, if you follow the readme here:
https://github.com/sendgrid/sendgrid-php#installation
everything should work ok.
Don't use the example in this issue. It had to do with a different issue.
Yes I used the same example specified in the first link and followed the installation as in 2nd link.
But the error still persists saying Fatal error: Class 'Dotenv' not found in D:xampp\htdocs\sendgrid-php\smtp-php-example.php on line 3.
So what should the solution be
Thanks & Regards
Prashanth
From: Scott Motte [mailto:[email protected]]
Sent: Thursday, May 08, 2014 11:31 PM
To: sendgrid/sendgrid-php
Cc: prashanthpanyam
Subject: Re: [sendgrid-php] CC and BCC not working (#83)
Hi @prashanthpanyam https://github.com/prashanthpanyam - take a look here for some working code examples:
https://github.com/sendgrid/sendgrid-php-example
But otherwise, if you follow the readme here:
https://github.com/sendgrid/sendgrid-php#installation
everything should work ok.
Don't use the example in this issue. It had to do with a different issue.
—
Reply to this email directly or view https://github.com/sendgrid/sendgrid-php/issues/83#issuecomment-42583351 it on GitHub. https://github.com/notifications/beacon/7523943__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxNTE5MTIzNCwiZGF0YSI6eyJpZCI6MjgxNTY5NTN9fQ==--c2aacca04cc5954856ab519577a75e53a7a4cb7d.gif
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
Hi @prashanthpanyam,
The example library is slightly different than the standard install. If using the sendgrid-php-example, you need to run composer. Are you doing that here:
https://github.com/sendgrid/sendgrid-php-example#usage
There's a command composer install. That will install all the dependencies - one of which is the Dotenv dependency that you are currently missing.
BUT, Dotenv is not required for the standard install - it's just part of the example for convenience.
I was just bitten by this as well. I'd suggest removing the methods from your interface or have them throw an exception as suggested above. Very confusing that this doesn't work as you would expect, especially for something that seems trivial like 'cc'.
We're experiencing similar issues.
Just wanted to add, it's strange that BCC isn't working especially since it exists as a method in your class. Please make the proper adjustments to let other users know, as soon as possible.
+1
I have to say, I ran into this again. While I "kinda" understand why you would get rid of Bcc, removing CC is slightly outrageous. In my line of work we have to send messages to entire teams of people, how are we supposed to achieve that without CC? And no, advising me to use yet another library / implementation is not acceptable.
This will be fixed in the upcoming v3.0.0 branch. We will be defaulting to
a web parameter for 'to' as opposed to the current usage of the smtpapi
header for 'to'.
On Monday, January 26, 2015, Serg Chernata [email protected] wrote:
I have to say, I ran into this again. While I "kinda" understand why you
would get rid of Bcc, removing CC is slightly outrageous. In my line of
work we have to send messages to entire teams of people, how are we
supposed to achieve that without CC? And no, advising me to use yet another
library / implementation is not acceptable.—
Reply to this email directly or view it on GitHub
https://github.com/sendgrid/sendgrid-php/issues/83#issuecomment-71574394
.
Eddie Zaneski
{"device": "mobile"}
Thanks for the quick response. If you get a chance, please let us know when that happens.
Just had everything setup and working nicely - my class setup, email formatted and bang... ->setBcc - with addTo or CC not working. What a big disappointment.
I went to your Github page, scrolled down to see it listed there as part of the documentation and scratched my head many times until I found this topic.
You really need to make it clear that this doesn't work with your php lib. I basically made my choice on this lib because of that.
It's been a year since this issue was put up - any news on progress on this?
Thanks a lot.
I am actively working on this on the 3.0.0 branch. It will be done very very shortly. So sorry for the delay.
I hit this one hard as well. Much time spent tracking down this bug. Thumbs up lanching version 3 as soon as possible.
Working on implementing BCC on SendGrid in another application of ours and having experienced this issue, I'd love to use the actual BCC function rather than a work-around if possible. Any ETA on the 3.0.0 branch?
I have a pre-release up of v3.0.0 that should fix all of these issues. Would love some testers to provide feedback.
I need to write up the changes and a better README, but here's a primer.
"sendgrid/sendgrid": "3.0.0-RC1" in composer.
https://github.com/sendgrid/sendgrid-php/releases/tag/v3.0.0-RC1
One of our developers (@animir) is currently testing this. /cc @animir
Is the new version the one used by parse's cloud module? Because there it does not seem to work.
@odrobnik I don't know which version Parse is using in their cloud module. I suggest you contact their support team. Thanks.
Most helpful comment
Thank you for the update and the code sample. Until the API changes, it might be worth throwing an exception if a web API call contains a CC or a BCC. There's no way a user would be able to figure this restriction out on their own.