I have a script which should scrap selected email from the inbox. Everything works except BODY. Subject, date, sender and etc.. were scraped without problems but the body were returned like this:
VG9kYXkncyBGcmVlIGFuZCBCYXJnYWluIEJvb2tzCgpVcGRhdGUgUHJlZmVyZW5jZXM6ICBodHRw
Oi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9wcmVmZXJlbmNlcz9oPTZjNTgxNDEyYjkzMTdiMWZlNjc1
ZDcwNDFjODJhYTc5Ckludml0ZSBGcmllbmRzOiBodHRwOi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9p
bnZpdGU/aD02YzU4MTQxMmI5MzE3YjFmZTY3NWQ3MDQxYzgyYWE3OQpVbnN1YnNjcmliZTogaHR0
cDovL3d3dy5ib29rZ29yaWxsYS5jb20vdW5zdWJzY3JpYmU/aD02YzU4MTQxMmI5MzE3YjFmZTY3
NWQ3MDQxYzgyYWE3OQoKQWxsIHByaWNlcyB3ZXJlIHZlcmlmaWVkIGJ5IEJvb2tHb3JpbGxhIHBy
aW9yIHRvIHRoaXMgZW1haWwgYmVpbmcgc2VudCwgYnV0IHByaWNlcyBtYXkgY2hhbmdlIHdpdGhv
dXQgbm90aWNlIHNvIHBsZWFzZSB2ZXJpZnkgdGhhdCB0aGUgYm9vayBpcyBzdGlsbCBmcmVlIG9y
IGJhcmdhaW4gcHJpY2VkIGJlZm9yZSBjb25maXJtaW5nIHlvdXIgb3JkZXIuIFNvbWUgYm9va3Mg
bWF5IG5vdCBiZSBmcmVlIG91dHNpZGUgdGhlIFVuaXRlZCBTdGF0ZXMuIFdlIHdlbGNvbWUgeW91
ciBmZWVkYmFjaywgc28gcGxlYXNlIHJlcGx5IHRvIHRoaXMgZW1haWwgaWYgeW91IGhhdmUgYW55
IGNvbW1lbnRzIG9yIHN1Z2dlc3Rpb25zIHlvdSB3b3VsZCBsaWtlIHRvIHNoYXJlIHdpdGggdXMu
CgoKCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCg0KRG9uJ3Qg
bWlzcyB0aGlzIEJFU1QgUFJJQ0UgRVZFUiBvbiBEZWJiaWUgTWFjb21iZXIncyBjbGFzc2ljIERl
Y2VtYmVyIDIwMTMgcmVsZWFzZSE8YnIgLz48YnIgLz5GcmllbmRzLS1BbmQgVGhlbiBTb21lPGJy
IC8+KERlYmJpZSBNYWNvbWJlciBDbGFzc2ljcykNCkJ5IERlYmJpZSBNYWNvbWJlcjxiciAvPjxi
ciAvPjY3JSBQcmljZSBDdXQgVGhpcyBXZWVrIQ0KDQoqKioqKiBTVEFSUkVEIFRJVExFICoqKioq
CgogT25lIG9mIGFjY2xhaW1lZCBhdXRob3IgRGViYmllIE1hY29tYmVy4oCZcyBjbGFzc2ljIG5v
dmVscywgdGhpcyB0ZW5kZXIgc3Rvcnkgb2YgdHdvIHBlb3BsZSBkYXJpbmcgdG8gYmUgbW9yZSB0
aGFuIOKAnGp1c3QgZnJpZW5kc+KAnSBpcyBhdmFpbGFibGUgZm9yIHRoZSBmaXJzdCB0aW1lIGlu
IHRoZSBLaW5kbGUgc3RvcmUhDQoNClRvZGF5J3MgQmFyZ2FpbiBQcmljZTogJDAuOTkNCg0KR2V0
IEl0IE5vdw0KaHR0cDovL3d3dy5ib29rZ29yaWxsYS5jb20vbGluaz9sPWh0dHAlM0ElMkYlMkZ
And I have no idea why is it? This is a code I'm using:
$inbox_details = $this->email_main->getInboxDetails($data['inbox_id']); // select inbox data by inbox id
$message_id = $inbox_details['last_sended_email_id'] + 1;
$imap = imap_open('{'. $data['inbox_data']['inbox_server'] .'}INBOX', ''. $data['inbox_data']['inbox_email'] .'', ''. $data['inbox_data']['inbox_password'] .'');
if (!$imap)
$this->email_main->insertError(imap_last_error(), $data['inbox_data']['id']);
$header = imap_header($imap, $message_id);
$message = array(
'subject' => $header->subject,
'fromname' => $header->fromaddress,
'fromaddress' => $header->from[0]->mailbox.'#'.$header->from[0]->host,
'toaddress' => $header->toaddress,
'date' => $header->date,
'timestamp' => $header->udate,
'body' => imap_qprint(imap_fetchbody($imap, $message_id, 2)), // $message_id = 1
);
any ideas folks?
Your content is encoded in base64.
base64_decode($content);
Will decode it :)
Edit:
Decoded with http://www.base64decode.org/ to get 'Today's Free and Bargain Books'
Related
I want to send premium emojis by Telegram bot (I have a premium account and created a bot with it), but when I try to send it (I send emojis to the premium account), unfortunately, the emoji is sent normally.
my code:
<?php
$entities = [
'type' => 'custom_emoji',
'offset' => 4,
'length' => 2,
'custom_emoji_id' => '5877565553761062314'
];
$url = "https://api.telegram.org/BotToken";
$url .= "/sendMessage?chat_id=UserChatId";
$url .= "&text=Hi 💻";
$url .= "&parse_mode=html";
$url .= "&entities=" . json_encode($entities);
echo $url;
file_get_contents($url);
Message should be like this:
This feature will be activated in the future.
https://telegram.org/faq_premium#q-can-i-buy-a-premium-subscription-for-my-bots
We are attempting to send an email to multiple recipients using the Mailgun PHP API.
We are running MG PHP lib version 2.8.1.
Our code does the following:
note: email address and domain changed for privacy reasons
log_debugger('g1', 'g1');
$params = array(
'from' => $msg_org . " <" . EMAIL_SENDER . ">",
'to' => array('joe#gmail.com'),
'subject' => 'Hey %recipient.first%',
'text' => 'If you wish to unsubscribe, click http://example.com/unsubscribe/%recipient.id%',
'recipient-variables' => '{"joe#gmail.com": {"first":"Joe", "id":1}}'
);
log_debugger('g1', 'g2');
# Make the call to the client.
$mgresult = $mgClient->messages()->send(MAILGUN_DOMAIN, $params);
log_debugger('g1', 'g3');
// if the email was accepted by Mailgun then indicate the member message was delivered
if ($mgresult->http_response_code >= 200 && $mgresult->http_response_code < 300) {
log_debugger('mgr', $mgresult->http_response_code);
// else the email was not accepted by mailgun so indicate the member message failed to be delivered
} else {
log_debugger('g1', 'g4');
}
The call is successfully getting to MG, but we are not getting any return from MG. We have been sending to MG successfully for sometime and now we are attempting to send to multiple email addresses at one time. Below is the data we are passing in as recorded by our debug log.
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g2
Here is the MG documentation - Notice the error: messages()-send should be messages()->send
require 'vendor/autoload.php';
use Mailgun\Mailgun;
// Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
$params = array(
'from' => 'Excited User <YOU#YOUR_DOMAIN_NAME>',
'to' => array('bob#example.com, alice#example.com'),
'subject' => 'Hey %recipient.first%',
'text' => 'If you wish to unsubscribe, click http://example.com/unsubscribe/%recipient.id%',
'recipient-variables' => '{"bob#example.com": {"first":"Bob", "id":1},
"alice#example.com": {"first":"Alice", "id": 2}}'
);
// Make the call to the client.
$result = $mgClient->messages()-send($domain, $params);
Any help getting this to work would be greatly appreciated. Logged a ticket with MG, but no reply as of yet.
Method documented by MG for sending message is not quite correct. I had to change the call from:
$mgresult = $mailgun_client->messages()->send(MAILGUN_DOMAIN, array(
to:
$mgresult = $mailgun_client->sendMessage(MAILGUN_DOMAIN, array(
I am working with a wordpress site that imports all data from API to the site automatically via cron job. However, I'm now on the part of saving the field data from the API. The problem is update_post_meta and update_fields are both not working.
I already tried interchanging between the two methods of saving but both doesn't work. No error prompts and no results as well (which is pretty weird for me). I checked the built-in plugin of the site and it uses update_post_meta.
add_action('wp_ajax_nopriv_get_properties_from_api','get_properties_from_api');
add_action('wp_ajax_get_properties_from_api','get_properties_from_api')
function get_properties_from_api(){
$file = get_stylesheet_directory() . '/report.txt';
$current_page=(! empty($_POST['current_page'])) ? $_POST['current_page'] : 1;
$properties = [];
$results = wp_remote_retrieve_body(wp_remote_get('https://www.realestateview.com.au/listing_api?rm=search&company=castlemain&code=29GKRRSgkVdQVM&CID=5813&json=1&ptr=r&con=S&portalview=residential&rn=1&pg='. $current_page));
file_put_contents($file, "Current page: ". $current_page. "\n\n", FILE_APPEND);
$results=json_decode($results, true);
if(!is_array($results['Listings']) || empty($results['Listings'])){
return false;
}
$properties[]=$results;
foreach($properties[0] as $property){
$property_slug = sanitize_title($property->TitleNoHTML, '-', $property->OrderID);
$inserted_property = wp_insert_post([
'post_name' => $property_slug,
'post_title' => $property->TitleNoHTML,
'post_type' => 'property',
'post_status' => 'publish',
]);
if(is_wp_error($inserted_property)){
continue;
}
$fillable=[
//Basic information
get_the_title($inserted_property) => 'TitleNoHTML',
'REAL_HOMES_property_price' => 'PriceText',
'REAL_HOMES_property_size' => 'LandSizeText',
'REAL_HOMES_property_bedrooms' => 'BedroomsCount',
'REAL_HOMES_property_bathrooms' => 'BathroomsCount',
'REAL_HOMES_property_garage' => 'LockUpGaragesCount',
'REAL_HOMES_featured' => 'FeaturedProperty',
//$this->REAL_HOMES_property_id =
//$this->REAL_HOMES_property_year_built =
//Location on Map
'REAL_HOMES_property_address' => 'AddressText',
'REAL_HOMES_property_location' => 'Suburb',
'REAL_HOMES_property_map' => 'DisplayTrueAddress',
//Gallery
'REAL_HOMES_property_images' => 'PhotoOriginalURL',
//Floor Plans
//$this->inspiry_floor_plan_name =
'inspiry_floor_plan_price' => 'PriceText',
//$this->inspiry_floor_plan_price_postfix =
// $this->inspiry_floor_plan_size =
// $this->inspiry_floor_plan_size_postfix =
'inspiry_floor_plan_bedrooms' => 'BedroomsCount',
'inspiry_floor_plan_bathrooms' =>'BathroomsCount',
// $this->inspiry_floor_plan_descr =
'inspiry_floor_plan_image' => 'FloorplanThumbURL',
//Property Video
'inspiry_video_group_image' => 'PhotoThumbURL',
//$this->inspiry_video_group_title =
'inspiry_video_group_url' => 'VideoURL',
//DEPRECATED FIELDS
// $this->REAL_HOMES_360_virtual_tour =
// $this->REAL_HOMES_tour_video_url_divider =
// $this->REAL_HOMES_tour_video_url =
// $this->REAL_HOMES_tour_video_image =
//Agent
//$this->REAL_HOMES_agent_display_option =
'REAL_HOMES_agents' => 'ContactAgentName',
//Energy Performance
// $this->REAL_HOMES_energy_class =
// $this->REAL_HOMES_energy_performance =
// $this->REAL_HOMES_epc_current_rating =
// $this->REAL_HOMES_epc_potential_rating =
//Misc
// $this->REAL_HOMES_sticky =
// $this->inspiry_property_label =
// $this->inspiry_property_label_color =
// $this->REAL_HOMES_attachments =
'inspiry_property_owner_name' => 'ClientName',
//$this->inspiry_property_owner_contact =
'inspiry_property_owner_address' => 'ClientAddress',
// $this->REAL_HOMES_property_private_note =
// $this->inspiry_message_to_reviewer =
//Homepage slider
// $this->REAL_HOMES_add_in_slider =
// $this->REAL_HOMES_slider_image =
// $this->REAL_HOMES_page_banner_image =
//Additional fields
'inspiry_InspectionDateandStartTime' => 'ISOInspectionStart',
'inspiry_InspectionDateandFinishTime' => 'ISOInspectionFinish',
];
foreach($fillable as $key => $TitleNoHTML){
update_post_meta($inserted_property, $key, $property->$TitleNoHTML);
}
}
$current_page = $current_page + 1;
wp_remote_post(admin_url('admin-ajax.php?action=get_properties_from_api'), [
'blocking' => false,
'sslverify' => false,
'body' => [
'current_page' => $current_page
]
]);
What I'm already expecting is it should be already save some data, if not, it should produce an error but for some weird reason, there isn't. I tried to var_dump some variables and I think it should be working. Would anyone be able to help me find out where I gone wrong?
In order to replace the Wordpress cron with a real cron job you will need to set a cron job which will fetch data from a webpage using wget. First you will need to create a Wordpress page which will contain your PHP code then fetch the content with cron using wget.
The real cron job command will look like this:
wget -q -O - http://yourdomain.com/your_cron_page >/dev/null 2>&1
-q tells wget to operate quietly (ie. to not output the usual status information)
-O /dev/null tells it to output to /dev/null
Keep in mind that everyone can access this page so you might want to set some restrictions.
in there i have been create function for send an email, here my code like this :
$row=DB::table('orders')
->join("cms_members","cms_members.id","=","orders.id_cms_members")
->select("orders.*","cms_members.email as email","cms_members.name as name","cms_members.phone as phone")
->where('orders.id',$id_order)
->first();
$datas = array(
'name' => 'test',
'detail'=> 'test',
'sender' => 'adamprojo#gmail.com'
);
$customPaper = array(0,0,800,800);
$pdf = PDF::loadView('testing', $data)->setPaper($customPaper);
Mail::send('emails.temp', $datas, function($message) use($pdf)
{
$message->from("no-reply#crocodic.net","Invoice HOP Daily rent Orders");
$message->to($row->email)->subject('Invoice');
$message->attachData($pdf->output(), "invoice.pdf");
});
here my problem when ever i want to send an email i get response
Address in mailbox given does not comply with RFC 2822, 3.6.2.
but if i try to print the email its give me the email address. what should i do ?
Kindly, can someone give me any solution for mentioned problem?
This will be your code:
$row=DB::table('orders')
->join("cms_members","cms_members.id","=","orders.id_cms_members")
->select("orders.*","cms_members.email as email","cms_members.name as name","cms_members.phone as phone")
->where('orders.id',$id_order)
->first();
$datas = array(
'name' => 'test',
'detail'=> 'test',
'sender' => 'adamprojo#gmail.com'
);
$customPaper = array(0,0,800,800);
$pdf = PDF::loadView('testing', $data)->setPaper($customPaper);
Mail::send('emails.temp', $datas, function($message) use($pdf, $row)
{
$message->from("no-reply#crocodic.net","Invoice HOP Daily rent Orders");
$message->to($row->email)->subject('Invoice');
$message->attachData($pdf->output(), "invoice.pdf");
});
You need to set use($pdf, $row) by the Mail::send(), this will get the $row data that you use in the $message->to().
Hope this works!
I am trying to write a PHP script that will generate a PDF and email it. My PDF generator works perfectly as an independent URL, but for some reason when I try to make the script email the generated PFD, the received file can't be opened. Here is the code:
include_once('Mail.php');
include_once('Mail/mime.php');
$attachment = "cache/form.pdf";
// vvv This line seems to be where the breakdowns is vvv
file_put_contents( $attachment, file_get_contents( "http://www.mydomain.com/generator.php?arg1=$arg1&arg2=$arg2" ) );
$message = new Mail_mime();
$message->setTXTBody( $msg );
$message->setHTMLBody( "<html><body>$msg</body></html>" );
$message->addAttachment( $attachment );
$body = $message->get();
$extraheaders = array( "From" => $from,
"Cc" => $cc,
"Subject" => $sbj );
$mail = Mail::factory("mail");
$headers = $message->headers( $extraheaders );
$to = array( "Jon Doe <jon#mydomain.com>",
"Jane Doe <jane#mydomain.com>" );
$addresses = implode( ",", $to );
if( $mail->send($addresses, $headers, $body) )
echo "<p class=\"success\">Successfully Sent</p>";
else
echo "<p class=\"error\">Message Failed</p>";
unlink( $attachment );
The line that I marked does generate a PDF file in the cache folder, but it will not open, so that seems to be a problem. However, when I try to attach a PDF file already exists, I have the same problem. I have tried $message->addAttachment( $attachment, "Application/pdf" ); as well, and it does not seem to make a difference.
Typically web server directories should have write permissions locked down. This is probably why you are experiencing problems with file_put_contents('cache/form.pdf').
// A working example: you should be able to cut and paste,
// assuming you are on linux.
$attachment = "/var/tmp/Magick++_tutorial.pdf";
file_put_contents($attachment, file_get_contents(
"http://www.imagemagick.org/Magick++/tutorial/Magick++_tutorial.pdf"));
Try changing where you are saving the pdf to a directory that allows write and read permissions to everyone. Also make sure this directory is not on your web server.
Also try changing the following three things
From
$message = new Mail_mime();
To
// you probably don't need this the default is
// $params['eol'] - Type of line end. Default is ""\r\n""
$message = new Mail_mime("\r\n");
From
$extraheaders = array(
"From" => $from,
"Cc" => $cc,
"Subject" => $sbj,
);
To
$extraheaders = array(
"From" => $from,
"Cc" => $cc,
"Subject" => $sbj,
'Content-Type' => 'text/html'
);
From
$message->addAttachment($attachment);
To
// the default second argument is $c_type = 'application/octet-stream'
$isAttached = $message->addAttachment($attachment, 'aplication/pdf');
if ($isAttached !== true) {
// an error occured
echo $isAttached->getMessage();
}
And you always want to make sure that you call
$message->get();
before
$message->headers($extraheaders);
or the whole thing wont work
I am pretty sure it must be an ini problem blocking file_get_contents(). However I came up with a better solution. I reworked the generator.php file and turned it in to a function definition. So I've got:
include_once('generator.php');
$attachment = "cache/form.pdf";
file_put_contents( $attachment, my_pdf_generator( $arg1, $arg2 ) );
...
$message->addAttachment( $attachment, "application/pdf" );
This way I do not need to write the file first. It works great (although I am still having slight issues with Outlook/Exchange Server, but I think that is a largely unrelated issue).