This might be a simple question but I've searched and searched and can't find an answer.
I'd like to log the message ID for each email sent so I can more accurately do bounce handling.
I'm using the AWS PHP SDK to send my emails. How can I get the message ID after I send an email?
Found the answer...
I'm able to retrieve the MessageID from the response object I get upon sending an email with SES.
$response->body->SendEmailResult->MessageId
Updated answer:
sendEmail returns a Guzzle\Service\Resource\Model.
You can get the value of MessageId with $response->get('MessageId')
More info: http://docs.aws.amazon.com/aws-sdk-php/guide/latest/feature-models.html
Amazon SES change Message-ID, see first comment
You can get the response from amazon into a variable and then parse the xml;
$res = $this->amazon_ses->send();
$xml = new SimpleXMLElement($res);
$email_id = (string) $xml->SendEmailResult[0]->MessageId;
This worked well for me
Related
The following code I am using to send mails from php.
<?php
require 'vendor/autoload.php';
$email->setFrom("test#example.com", "Example User");
$email->setSubject("Sending with SendGrid is Fun");
$email->addTo("test#example.com", "Example User");
$email->setOpenTracking(true, "--sub--");
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
$response = $sendgrid->send($email);
?>
Here I am setting Open Tracking for web-hook, When an email is opened the open event trigger and response coming to my given URL. Here I am getting web-hook every time when ever that email is opened by client. But I want Unique Open tracking.
I tried this which not working and may be invalid method:
$email->setUniqueOpenTracking(true, "--sub--");
Is there any setting or parameters That I need to configure.
Thanks in Advance
After call conversation with send grid, they are not providing Unique open tracking.
I have to maintain the opened web-hooks in a table and check every time, whether the web-hook is already received or not.
I am trying to send a "reply" message using Gmails API and PHP. I can send the message, and even upload documents to send with the message, but I can find ZERO articles, docs, zip, nothing on how to reply to a message using Gmails API and including the original documents. If you have any suggestions, please advise. Here is my current code:
$gMail = new \Google_Service_Gmail($googleClient);
$msg = new \Google_Service_Gmail_Message();
$msg->setThreadId($threadId);
$messageObj = $gMail->users_messages->send("me", $msg);
There is a ton of code as well that I have not included because it doesn't need to be. Best case, if anyone could point me to the docs that explain how to attach original files (without having to download them and re-upload them to the email), this would be great.
Thanks.
Recently I'm trying to received sms to plivo number. when i sent a sms from outsite plivo then it sent and plivo log status will show delivered. But i need to save data into database. It does not trigger to my controller function.
I already sent sms through another function. it sent and saved into my database but problem is, when anyone reply into this number.
controller function:
public function index()
{
// Sender's phone numer
$from_number = $this->input->get("From"); // $this->input->post("From"); dosen't work.
// Receiver's phone number - Plivo number
$to_number = $this->input->get("To"); // $this->input->post("To"); dosen't work.
// The SMS text message which was received
$text = $this->input->get("Text"); // $this->input->post("Text"); dosen't work.
// Output the text which was received to the log file.
// error_log("Message received - From: ".$from_number.", To: ".$to_number. ", Text: ".$text);
$arr = array("from" => $from_number, "to" => $to_number, "text" => $text);
$this->receive_model->add($arr);
}
Plivo application URL :
http://xxxxxxx.com/receive_sms
Message Method : GET
Message Method : POST // Dosen't work.
Codeigniter Config:
$config['allow_get_array'] = TRUE;
In plivo log status delivered.
any help?
Plivo started their Stop DND protocol a few days ago (i.e. June 2016). When a message comes back in response to a text from a Plivo phone number that says Stop... all further messages from Plivo are blocked.
The Plivo number sends a message and the recipient responds with Stop.
There is no do over. From then on, NO messages from Plivo will be delivered to that recipient as the recipients Stop message is interpreted as a request that all further messages be blocked.
Plivo offers no way of turning message delivery back on. That user has no way of correcting the Stop if sent in error. There is no do over.
All solutions lead to using a new different phone number.
A band aid... Incoming messages to that Plivo number still get received so there is the possibility of sending outgoing response messages from a second Plivo or other number. In theory looks OK BUT in reality this is at best a short term fix.
Most users naturally depend on sending messages by replying. Replying to the wrong new incoming number, instead of sending to the original phone number, just sets up another set of problems and issues to deal with. Not the least of those is what ever reason that caused the stop message in the 1st place or accidentally doing it again. Ends up like cutting your finger off 1/16th of an inch at a time.
At the first time i load plivo library class on the sms received controller, it was a problem. I just erase those line from controller and then it works fine.
We have to follow:
Plivo application always get data for codeigniter function. Codeigniter Config: $config['allow_get_array'] = TRUE; SMS received controller only load Codeigniter library file, nothing else.
It works for me.
I am sending emails via SendGrid with this inside the x-smtpapi header
$json_string = array(
'unique_args' => array (
'email_id' => 1
)
);
It all seems to send okay, inside SendGrid I can view the "email_id" in the Email activity under Unique Args.
However when I try to use the API to look at this email, I cannot find a way to actually get these unique arguments from the API.
I am using this to try and get the headers returned with the bounced emails.
$request = 'https://api.sendgrid.com/api/bounces.get.json&api_user=username&api_key=password'
All I get is just the email addresses that have bounced, not the header information (the unique arguments)
I want to know, is it possible to get the unique arguments from the API. I have read it multiple times to no avail.
I hope this makes sense.
Thanks
At present there's no way request to lookup specific events by unique_arg with the Web API.
However, the SendGrid Event Webhook will give you granular data on each event, such as a bounce as it happens. The Event Webhook POSTs data to your server every time an action is taken upon an email (e.g. open, click, bounce).
Once you receive it, you're responsible for storing this, although it's not a typical API it gives very specific data on events which you can then compile and rehash however you like.
To get started using the webhook, you'll do something like the following, and have SendGrid POST to the following script:
<?php
$data = file_get_contents("php://input");
$events = json_decode($data, true);
foreach ($events as $event) {
// Here, you now have each event and can process them how you like
process_event($event);
}
[Taken from the SendGrid Webhook Code Example]
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