What does this email from SendGrid is refering to in PHP API? - php

a few days a go we received a email from sendgrid stating they are going to change some behaviors in their API, I've done research but I have not found concretly what they are refering to, currently we are using the PHP API, and atleast for the 2) I think we are OK as we use SendGrid classes to build the emails
Check your code that uses the mail send endpoint and ensure that the
“enable” parameter is included under the filter when applicable.
What do you need to do?
To avoid disruption to your mail send service, please be sure to make
the following actions before August 10, 2021
Check your code that uses the mail send endpoint and ensure that the
“enable” parameter is included under the filter when applicable.
Check your mail send header to ensure that you are using just one
X-SMTPAPI header and address header of the same kind. Remove multiple
headers of the same kind, so you have only 1 header of the same kind.
For example, if you are currently using multiple “from” headers, you
should modify your code so that you have a single “from” header.
Check your code to ensure that you are not applying any
personalization block substitution to your custom argument fields.
But what about the third item? we have substitions of following fashion: $mail->personalization[0]->addSubstitution('%url%', $link);
But I havent found anything like a "block sustitution in custom arguments"
And the first item also worries me, I haven't found anything like that neither, so I'm afraid that perhaps there is something that the PHP API does behind the scenes.
This a example of the code we use.
$sendgrid = new SendGrid(env('SENDGRID_APIKEY'));
$from_m = new SendGrid\Email(null, $from);
$to_m = new SendGrid\Email(null, $from);
$content = new SendGrid\Content("text/html", $body);
$mail = new SendGrid\Mail($from_m, '.', $to_m, $content);
$mail->personalization[0]->addBcc($tos);
$mail->personalization[0]->setSubject($subject);
$mail->personalization[0]->addSubstitution('%MemberName%', $name);
$mail->personalization[0]->addSubstitution('%url%', $hash_url);
$mail->setTemplateId($template_id);
$sendgrid->client->mail()->send()->post($mail);
We are using sendgrid/sendgrid: ~6.2

Twilio SendGrid developer evangelist here.
From my reading of your code and the guidelines you've been sent, you should be ok.
You don't appear to be using anything that needs to be enabled via the API, though you can check all the mail_settings and tracking_settings in the API reference here.
As you are using the library and calling the API you don't appear to be sending any extra headers.
You don't seem to be using any custom arguments, so you aren't applying any substitutions to them.
I do recommend that you upgrade your PHP helper library to version 7 from 6. That will ensure that the underlying library is also using the API in the most up to date manner.

Related

Amazon SES not working with eu_west_1 but ok using us_east_1 PHP

Im rewriting a few scripts to make use of the new v4 signature for Amazon AWS.
I am trying to send an email using the code on this page:
https://github.com/okamos/php-ses
When I use his code exactly as it is just adding secret keys etc I get an error saying my email address isnt verified on us_east_1. This makes sense as all my things are on EU_WEST_1.
So Ive tried adding the EU endpoint as a third parameter but get this error:
'Warning: SimpleEmailService::sendEmail(): 6 Could not resolve host: EU_WEST_1'
This is the line of code which seems to work but connecting to the wrong endpoint
$ses = new SimpleEmailService('apikey', 'secretkey');
print_r($ses->sendEmail($m));
I have tried adding the new endpoint as the third parameter like this
$ses = new SimpleEmailService('apikey', 'secret','eu-west-1');
But that just generates the error.
Can anyone tell me the correct code to use to set the eu-west-1 endpoint to send emails through?
Thanks
I had faced the same problem with AWS PHP library for uploading files to S3. Even though I was setting up the region from us-east-1 to eu-west-1 it was still taking us-east-1 as by default. I would suggest you to look for region configurations in library and how it is overriding.
SES Email Host for us-east-1 and eu-west-1 are different. So even though if you are passing correct API and Secret, it might not work because of default region.
If this debug process doesn't work can share the screenshot of what you region you are getting before email dispatch. I would love to explore further.
I found the problem.
Looks like there was a typo within the code on github, it had these 3 lines in the file 'SimpleEmailServices.php:
const AWS_US_EAST_1 = 'email.us-east-1.amazonaws.com';
const AWS_US_WEST_2 = 'email.us-west-2.amazonaws.com';
const AWS_EU_WEST1 = 'email.eu-west-1.amazonaws.com';
He'd missed the underscore in the AWS_EU_WEST1.

GMail API - Getting certain message headers or fields

I have successfully connected GMail API via G Suite account and service account. I can get a message list and I can retrieve messages by IDs. I'm working with PHP.
What I'm having problems with is to get for example the FROM or TO headers, SUBJECT or the snippet field.
$optParam = array('format' => 'metadata', 'metadataHeaders'=>['subject','from'], 'fields'=>['snippet','labelIds']);
$fullMessage = $service->users_messages->get($user, $id, $optParam);
This will return the snippet, but not the subject or from or the labelIds.
If I use the GMail "Try this API" and use the id of the message and use "snippet" in the "fields" entry, I just get the snippet back as:
{
"snippet": "Short snippet of the message"
}
If I use:
$optParam = array('format' => 'metadata', 'metadataHeaders'=>['subject','from','to']);
I do get the 3 headers, but I also get a lot more information, including the labels and snippet - about 3K for each message.
I just can't seem to be able to specify a small subset of the data. All I need is to show messages as a list with the subject, date/time, from/to.
I don't care so much about the amount of data, but it takes on average about 3.5 seconds to retrieve the data for just 14 message!
Is there a way to restrict this so I don't get all the "extra" data or speed the retrieval up somehow?
Sending the request would involve specifying the metadata keys as well as the parameter names of the fields you want to obtain. You can use an HTTP GET request with the URI to get the ‘to’, ‘from’, ‘subject’ and ‘snippet’ with https://www.googleapis.com/gmail/v1/users/me/messages/<MESSAGE_ID>?format=metadata&metadataHeaders=to&metadataHeaders=from&metadataHeaders=subject&fields=snippet%2C+payload%2Fheaders, which will also limit the headers you obtain.
In PHP you can use this:
$optParam = array('format' => 'metadata', 'metadataHeaders'=>['subject', 'from', 'to'], 'fields'=>'payload/headers,snippet');
Note that the fields parameter needs to be sent as a string and not an array.
Also be aware there is a known issue with the Gmail API where using the https://www.googleapis.com/auth/gmail.metadata scope will not return the snippet.
You’ll need to use https://www.googleapis.com/auth/gmail.readonly instead.
You can also make a batch of requests in one network call which will help speed up overall execution time as documented here.

PHP-EWS: UploadItem using PHP for .EML-Files

*,
I want to upload daily some .EML-Files to my Exchange Server 2013. So I found from Google a PHP class from James Iarmes calles PHP-EWS.
https://github.com/jamesiarmes/php-ews
I tried some examples and I think, this class is good for me. There is only one problem: no example-code in this wiki and unfortunately I do not get it out :-(
Is there someone, who works with this class and can post a example to do uploads to Exchange-Servers using PHP-EWS?
Regards
Based on the answer given by Michael up above, I can't tell you how you'd do it in jamesaires/php-ews, but I can tell you how to do it in my ews library, garethp/php-ews. I'd highly recommend you look in to my library instead, as it's maintained and PSR-4 compatible. Here's how you'd do it using Michael's method
<?php
require_once "vendor/autoload.php";
use jamesiarmes\PEWS\API\Type;
use jamesiarmes\PEWS\Mail\MailAPI;
$api = MailApi::withUsernameAndPassword('server', 'username', 'password');
$message = new Type\MessageType();
$message->setMimeContent(file_get_contents('./file.eml'));
//Set the message as not a draft using extended property types
$extended = new Type\ExtendedPropertyType();
$fieldUri = new Type\ExtendedFieldURI();
$fieldUri->setPropertyTag("0x0E07");
$fieldUri->setPropertyType(\jamesiarmes\PEWS\API\Enumeration\MapiPropertyTypeType::INTEGER);
$extended->setExtendedFieldURI($fieldUri);
$extended->setValue(1);
$message->addExtendedProperty($extended);
//Pass it to the Send Mail function, but to SaveOnly without actually sending the email
$itemId = $api->sendMail($message, array('MessageDisposition' => 'SaveOnly'));
$inbox = $api->getFolderByDistinguishedId('inbox');
//Move the mail message from the sent folder to whatever folder we want to send it to
$api->getClient()->MoveItem(Type::buildFromArray(array(
'ToFolderId' => array('FolderId' => $inbox->getFolderId()->toArray()),
'ItemIds' => array(
'ItemId' => $itemId->toArray()
)
)));
I've never worked with PHP-EWS but I do know that you can put a .eml into Exchange.You won't be using the UploadItem operation. You'll use the CreateItem operation. Here's the workflow:
Create an email object.
Set the MimeContent property with the contents of your .eml file.
Set the PR_MESSAGE_FLAGS_msgflag_read property.
Use the CreateItem operation, or whatever the client-side equivalent is in PHP-EWS.
I'm fairly confident that this will work as I remember writing this in the official documentation.

Twilio sending message Using twilio library

Sending twilio message from my api returns this error
Twilio sending message The requested resource /2010-04-01/Accounts//Messages.json was not found
this is how I send a message. anyone incountered a problem?
$this->client = new \Services_Twilio($sid, $token);
return $this->client->account->messages->sendMessage($from ,$to, $message);
this is the documentation I followed
https://www.twilio.com/docs/api/rest/sending-sms
How do I create Messages.json
I used this https://github.com/twilio/twilio-php on laravel 4.2
Another Twilio developer evangelist here. Think I might be able to help.
The error message you got was this:
The requested resource /2010-04-01/Accounts//Messages.json was not found
The key point is the URL, particularly the double slash in the middle. That is where your Account Sid should be, thus leading to the 404 error.
In this case, I would double check how you are setting $sid. Make sure it is assigned before you try to create the Twilio client object.
Hi Twilio developer evangelist here.
Sorry to hear you're having trouble with your code.
You seem to not have posted your complete code, so I don't see where you actually require the library.
I have however written an example which worked for me.
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = 'AC';
$token = '01';
$client = new \Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
'+44', // From a valid Twilio number
'+44', // Text this number
"Hello monkey!"
);
I have removed some sensitive data on the code, but if you replace that with your token and numbers, you should be able to send a text message correctly.
Also, just in case you have the contents of the 'Services' folder elsewhere, make sure your paths are correct.
You have entered messages when it should be sms_messages.
CHANGE
$this->client->account->messages->sendMessage($from ,$to, $message);
INTO
$this->client->account->sms_messages->create($from ,$to, $message);
Also make sure that you are running this code inside a class otherwise you need to remove the $this-> from your code and use a local varible.

Collect data from email message

I want to collect data from email to mysql database using php.
If some one is sent a mail to their mail account to my mail id. I want that mail information to store in my database. for further operation. It is possible in PHP because I saw this feature in one hosting support application Kayako Fusion which developed by PHP.
So plese give some information to do this task.
If you want to parse with PHP the best way is to use a 3rd party API to revive the email and then send it to your PHP script with a HTTP Post.
I'd recommend using either sendgrid.com or mailgun.com
Both of these services will parse the email and send you the information in a http POST that you can then insert into mysql. API docs for both: MailGun Incoming Parse API / SendGrid Incoming Parse API
You can use the imap functions, for example:
<?php
$imap = imap_open("{server.example.com:143}INBOX" , 'login' , 'password');
if( $imap ) {
//Check no.of.msgs
$num = imap_num_msg($imap);
//if there is a message in your inbox
if( $num >0 ) {
//read that mail recently arrived
$the_message = imap_body($imap, $num);
//Do the stuff with $the_message
}
//close the stream
imap_close($imap);
}
You'll have to setup a cronjob (scheduled task on Windows) that connects to the Exchange or POP server, retrieve's all new emails sinds the last run and insert them into the DB.
In case of a POP mail server(I think POP will be easier), there is a comment here with all functions you need right -> here. If that doesn't work, try Googling for "PHP POP wrapper" or something similar.
In case of a Microsoft Exchange server, you'd have to use a PHP Exchange wrapper, found one here for you.
Goodluck!
You can pipe your email to a php script and then extract each part of email and store it in data base.
check this example
when you get content of email you can do what ever you want

Categories