i run php to send email list using third party smtp. I want to show Receipt(TO:) with my customer email. So i need to loop call php email function follow:
$emailList = explode("\n",file_get_contents('/list1.txt'));
foreach ($emailList as &$value) {
$email = new Email();
$email->setFrom("info#xxx.net");
$email->setToList($value);
$email->setSubject("360’s Got Talent");
$email->setHtmlContent($str);
$apiClient = new ApiClient("edm#xxx.net", "xxx");
$response = $turboApiClient->sendEmail($email);
var_dump($response);
echo ":: $value has been sent.<br />";
}
unset($value);
Is it standard way to do ?
Are there anyway to sent one time but can show TO: one by one ?
because when I run this, PHP is waiting total process and then writing report (echo). Sometime server is showing 504 Gateway Timeout.
or Can I make PHP run one by one ? report every line once it done, not waiting the whole process like a batch process.
Please guide.
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 use Sendgrid to send emails. Emails are sent using their web API and I use an endpoint to get each email events.
Here is the code of this endpoint (that Sendgrid call each time when an event occur, after sending an email).
I would like to get the status code of each event (eg : 5.1.1 for a bounce).
Here is what I tried so far :
$data = file_get_contents("php://input");
$events = json_decode($data, true);
foreach ($events as $event) {
$sg_message_id = $event['sg_message_id']; //OKAY
$event = $event['event']; //OKAY (eg : "bounce")
$status = $event['status']; //NOT OKAY ("undefined index")
//and if I try :
$status = $event['event']['status']; //I get the first letter of the event (eg : "b" for bounce)
}
the documentation (here : https://sendgrid.com/docs/API_Reference/Webhooks/event.html, Bounce part) says there is a field "status" (eg : 5.1.1), and I don't understand why it doesn't work,
Any idea?
I understood the problem :
I tried to simulate a bounce error using a fake user email like
user#gmail1.com
but Sendgrid didn't process the email (host not reacheable) and returned a "dropped" event.
Instead, if I send an email to:
another-user-unknow#gmail.com
then sendgrid return a process event and then a bounce event, with the bounce status code:)
We have an app on appstore, and with registered push notifications. They have successfully worked all the time, but we now tried to send a 'global' push, and something weird happened. This is what we have in our server-side .php file:
//Loop through tokens in tokenArray
$i = 0;
$t = 0;
foreach($tokenArray as $token)
{
$t++;
// Make notification
$msg = chr(0) . pack('n', 32) . pack('H*', $token) . pack('n', strlen($payload)) . $payload;
// Send
$result;
if($message != null)
{
$result = fwrite($fp, $msg, strlen($msg));
}
if ($result)
$i++;
}
// Close the connection to the server
fclose($fp);
if($i == 0)
{
echo 'The message was not delivered to anyone out of '.$t.'.';
}
else
{
echo 'The message was delivered to '.$i.' out of '.$t.'.';
}
The code before this has always worked, and it kind of still does. The tokenArray contains the table with tokens, as in SELECT Token FROM Tokens; from our SQL. This works.
During development, when only our own tokens were registered, it always said "The message was delivered to 4 out of 4", even though we had deleted our apps from our phones. Now we tried to send to all ≈1100 registered tokens with this code.
The message was sent, and the output was "The message was delivered to 588 out of 1194."
And we did not receive the notification ourselves!
What does that mean?
After about 5 minutes, I switched out the tokenArray with an array only containing my own tokens and sent a new push, and I received that one on my phone. I also know for a fact that the 'working' token exist in the previous 'tokenArray' which failed(I checked).
Is push notification a game of chance!? What does it mean when if($result) fails? And why did it fail over 500 times?
The certificates and .pem and .p12 etc are all working, the only thing I did different from push1 to push2 was to use another table which is a clone from the original table in my SQL-server. Table2 only have my tokens, and it worked. No other changes was made. Only SELECT Token FROM Tokens2, and later I proved that all the tokens in Tokens2 exist in Tokens
I have no idea if anyone got the push at all, or if the 'lucky' 588 of the 1200 that still has the app installed received it.
What causes this? We don't dare send another one in case half of them already received it.. Is there some limit to how fast I can send pushes at once? Or what are we doing wrong?!
Please help, thanks.
Well, I don't know php, so your code doesn't help me. However, based on your description it's likely some of the device tokens in your DB are invalid. When Apple's server gets a notification with an invalid device token it closes the socket. If you already wrote more messages after the one with the bad token, they won't reach Apple. Only after you detect that the socket was closed and open a new one your messages will reach Apple. If you don't use the enhanced notification format, it would be a good idea to start using it - this way you can get from Apple the id of the invalid message and clean your DB from invalid tokens. However, even using the enhanced format doesn't guarantee that you'll detect all the errors (unless you are willing to send the messages really slowly, and check for error responses from Apple after each message you send).
Your main loop does not take into account cases in which Apple will close socket connections. As mentioned by Eran, if you send an invalid token, Apple closes the connection at which point, any further writes using fwrite will fail. So if your 589th token is invalid, no other push will be sent to Apple.
Here's a simple fix for that that fits into your logic; this part replaces the if statement in the main loop:
if ($result) {
$i++;
} else {
fclose($fp);
// Add code here to re-open socket-connection with Apple.
}
Besides the enhanced notification format mentioned by Eran, you can also use the APNS Feedback API to query Apple for invalid tokens and purge them from your database. You can find more infomation on that here: http://bit.ly/14RPux4
There is no limit to how many push notifications you can send at once. I've sent thousands in a few seconds. The only real limitation is the connection between you and the APNS servers.
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
I have a custom app that i built which relies on a cron job to check for new email every 5 minutes. If there is a new email it then performs an action. What I would like to do is have a callback fired off when a new email arrives and then perform the action.
I could set the cron job to 1min intervals ( currently it is set to 5min ) but this seems like a waste of resources. The app is built in php and any help would be appreciated, i am just not sure what direction i should be looking at them moment.
M
You could use something like MailGun or SendGrid's Parse API which will receive your email for you and callback to an endpoint you specify.
very basic mail pipe script:
#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin","r");
$email = "";
while ( !feof($fd) ){
$email .= fread($fd,1024);
}
fclose($fd);
?>
what you do with $email, depends on what you need