I tried to look things up but I am unable to find anything quite similar.
So I have an external file. That file uses $_GET in order to enable bidirectional text order confirmations.
I am trying to modify order status based on that specific $_GET response, but I am now unable to generate any sort of error in my error logs and cannot quite tell what I am doing wrong. Please bear with me as I am not very experience with this.
Here's what I have done so far:
<?php
define( 'WP_USE_THEMES', false );
require_once( $_SERVER[ 'DOCUMENT_ROOT' ] . '/wp-load.php' );
/*
Receiving SMS using 2-Way SMS & PHP
if ((isset($_GET["sender"])) and
(isset($_GET["receiver"])) and
(isset($_GET["message"])) and
(isset($_GET["timestamp"])) and
(isset($_GET["network_id"])) and
(isset($_GET["network_name"]))
)
{
/*
The Sender of the SMS (ie. 07xyzzzzzz)
*/
$sender = $_GET["sender"];
/*
The Shortcode on which the SMS was sent (ie. 17xy, 18xy, 37xy, 38xy etc.)
*/
$receiver = $_GET["receiver"];
/*
The Message sent by the Sender to the Shortcode
*/
$message = $_GET["message"];
/*
The Timestamp in which the Message was received on the Shortcode, in UNIX Timestamp format.
*/
$timestamp = $_GET["timestamp"];
/*
The Network ID in which the Sender is located, with the following possible values:
1 for Vodafone Romania
2 for Orange Romania
3 for Telekom Romania Mobile / Telekom Romania
5 for Digimobil (RCS-RDS)
*/
$network_id = $_GET["network_id"];
/*
The Network Name corresponding to the Network ID
*/
$network_name = $_GET["network_name"];
/*
Write the SMS received to a text file
Please note that this is for example purpose only and the file(s) below must be not be publicly accessible. If you will
choose to store the SMS received to file(s) you must enable access restrictions and deny access from public to the respective
file(s) and you must disable directory listing on the directory where the files are stored.
We recommend you storing the SMS received to a database.
$handler = fopen("sms-mobile-originated-".date("d-m-Y", $timestamp)."txt", "a+");
fwrite($handler,
"SMS Received: From ".$sender.", ".
"Receiver ".$receiver.", ".
"Network ID: ".$network_id.", ".
"Network Name: ".$network_name.", ".
"Date / Time: ".date("d-m-Y H:i:s", $timestamp).", ".
"Message: ".$message.
"\r\n"
);
fclose($handler);
/*
Return the response to the request
For each received SMS you may send a SMS response to the sender (mobile subscriber) using any of the following methods:
(1) Using SMSLink - SMS Gateway API, such as SMS Gateway (HTTP), SMS Gateway (SOAP), SMS Gateway (JSON) or SMS Gateway (BULK)
(2) Using the output of this script, by writing the desired response below, if you enable this coresponding option in 2-Way SMS,
2-Way SMS Campaigns - Settings. In this case the SMSLink will read the script output and will send an SMS to the sender with
the output text. Please note that the output should be plain text (you should not output any HTML code).
*/
function sms_confirmation(){
if (substr(trim(urldecode($message)), 0, strlen("CF ETIN")) == "CF ETIN")
{
global $woocommerce;
$order = new WC_Order($order_id);
$phone = $order->get_billing_phone();
if (((strlen($phone) == 10) and ($phone == $sender)) or
((strlen($phone) == 9) and ("0".$phone == $sender)) or
((strlen($phone) == 11) and ($phone == "4".$sender)) or
((strlen($phone) == 13) and ($phone == "004".$sender)) or
((strlen($phone) == 12) and ($phone == "+4".$sender))
)
{
$order->update_status('confirm-sms', __('Approved by the customer', 'woocommerce') );
}
}
};
echo "Message Successfuly Received."
}
else
{
echo "Invalid Request.";
}
?>
Related
I have customized the default welcome e-mail send out by WordPress when you add a user, but when I change the default "From" information it no longer gets delivered to #gmail.com e-mailaddresses. I have tried it with multiple accounts, but always the same results. I haven't had any problems with #hotmail.com or any custom domain e-mailaddresses.
Below is the function I used to alter the default e-mail:
// Change the default welcome e-mail
add_filter( 'wp_new_user_notification_email', 'welcome__email', 10, 3 );
function welcome__email( $wp_new_user_notification_email, $user, $blogname ) {
$wp_new_user_notification_email['subject'] = sprintf(__( 'Company Name | Complete registration' ), $blogname, $user->user_login );
// Set password link
$key = get_password_reset_key( $user );
// Build the email
$message = sprintf(__('Welcome!')) . "\r\n\r\n";
$message .= 'By clicking the link below you can activate your account:' . "\r\n";
$message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . "\r\n\r\n";
$message .= "After setting a password you can login." . "\r\n";
$wp_new_user_notification_email['message'] = $message;
// Change header information
$wp_new_user_notification_email['headers'] = 'From: Company Name <noreply#example.com>';
return $wp_new_user_notification_email;
}
If I comment out the last part about the 'headers' the e-mail with link to set a password does get delivered to #gmail.com e-mailaddresses, but ofcourse the default name and e-mailaddress are show then.
I can't see what I am missing out here to make sure the e-mails get delivered to #gmail.com addresses, so I'm hoping anybody here is able to help me in the right direction.
PS: I do not have any SMPT plug-in set-up.
I just noticed the e-mails are not send to #gmail.com addresses because the sender e-mailaddress does not belong to the same domain as where the website is on. Once these match, there no longer is an issue.
My Goal:
Use AddStringAttachment() to send a auto-generated base64 string as a .pdf file to another email address.
Coding Environment:
I'm working on WordPress with a ajax call passing a base64 string to the server. The size of the string is usually around 30kbs, it can be guaranteed not exceeding over 50kbs. I have MAX_EXECUTION_TIME 120s.
What I've Been Working Through:
I succeeded:
Sending plain text body
Sending a small .txt file
I failed:
Sending base64 string using AddStringAttachment(). The server returns me a 504 Gateway Time-out error most of time, even if $mail->send() function passes through, I can only receive a corrupt .pdf file with 10kbs bigger than original size.
Sending a already exist .pdf file with AddAttachment(), The server also returns me a 504 Gateway Time-out error, and I also get a warning like Resource interpreted as Document but transferred with MIME type application/pdf
My Code:
function sendPdf() {
$mail = new PHPMailer(true);
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.hostinger.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'janice#popper.ga'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipient
$mail->SetFrom('janice#popper.ga');
$mail->AddAddress( 'xxxxxxxx#gmail.com' );
$pdf_base64 = $_POST[pdfString];
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject= ' New Application Form ';
$mail->Body= ' New Application Form From WordPress site ';
//Attachment
//$mail->AddStringAttachment($pdf_base64, $_POST[clientName].'_Application.pdf', 'base64', 'application/pdf');
//$mail->AddAttachment(dirname(__FILE__)."/Qian_Zhong_Application.pdf", 'Qian_Zhong_Application.pdf');
$error = '';
if(!$mail->send()){
$error = 'Mail error: '.$mail->ErrorInfo;
echo $error;
}else{
echo 'Message has been sent.';
}
exit; // This is required to end AJAX requests properly.
}
The data you pass in to addStringAttachment should be raw binary, not encoded in any way, as PHPMailer will take care of that for you. It will also set the encoding and MIME type from the filename you provide, so you do not need to set them manually.
Using a debugger would allow you to watch the script as it runs so you would be able to see exactly what it’s having trouble with. Any error 500s will cause errors to be logged in your web server logs and will usually provide more info.
I would also recommend against using $_POST[clientName] like that without any filtering or validation - you should never trust user input like that.
I want to send a total of 1650 mails on Christmas eve from a WordPress website.
This is my current code:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=" . get_bloginfo('charset') . "" . "\r\n";
$customers = get_users($args);
$cus_arr = array();
foreach($customers as $customer){
array_push($cus_arr,$customer->data->user_email);
}
wp_mail($cus_arr, $subject, $message, $headers);
/*another way*/
...
foreach($customers as $customer){
wp_mail($customer->data->user_email, $subject, $message, $headers);
}
Question 1 : Is the above way a good choice for sending a mail to this amount of customers? May there be any problem? Is there any better way of doing it?
Also I dont want customers to see each others mail. This is my current code:
wp_mail(array("BCC: xyz#xyz.com","BCC: abc#abc.com"), $subject, $message, $headers);
But it does not work. Without BCC: the mails are actually sent.
Question 2. How can I prevent users from seeing other mail ids?
Question 1: It's good practice to use a rate limit(throttling), e.g. max 100 mails/10 minutes. You can do this by storing the recipients in a database, and use a cronjob to send mail every 10 minutes. Another option is to use a 3rd party mail service, such as Mandrill or Sendgrid, they'll handle throttling for you.
Question 2: Your current code calls wp_mail for each recipient, so they'll never see other mail addresses (no need for BCC headers). However if you decide to use wp_mail to send to multiple recipients in 1 call, you need to use bcc headers, e.g.:
wp_mail('', $subject, $message, array("BCC: xyz#xyz.com","BCC: abc#abc.com"));
Hey there I think your code is a bad idea because of the following reasons:
The script may exceed the max execution time or the memory limit of the server
it may work, but wp_mail is just not a good solution for sending this huge amount of emails
What I would recommend is to use a library for sending bulk e-mails. There are existing WordPress Plugins for this purpose however you can easily do it yourself - here is my solution with the classic, well tested PHPMailerLibrary (https://github.com/PHPMailer/PHPMailer):
In your functions.php:
require("libs/phpmailer/PHPMailerAutoload.php");
/**
#param $from: The senders E-Mail
#param $from_name: The senders Name
#param $subject: The E-Mail subject
#param $mesesage: The E-Mail content HTML
#param $to: An array of receivers
*/
function my_custom_send_mass_mail($from,$from_name,$subject,$message,$to) {
// first use PHPMailer to send all the emails
$email = new PHPMailer();
$email->isSMTP();
$email->CharSet = 'utf-8';
$email->From = $from;
$email->FromName = $from_name;
$email->Subject = $subject;
$email->Body = $message;
$email->IsHTML();
if(is_array($to)) {
foreach($to as $t) {
$email->addBCC($t);
}
}
$ac = time();
update_option('mailsent-'.$ac,$email);
$success = $email->send();
if($success) {
update_option('mailsent-suc-'.$ac,"yes");
return "Bulk E-Mail successfully sent.";
}
update_option('mailsent-suc-'.$ac,$email->ErrorInfo);
return "Bulk E-Mail Error: Please contact admin.";
}
Just call this function and make sure $to is the array of receiver e-mails.
This is the solution I am using for a customer sending a 10000 E-Mail newsletter weekly and it works great so far.
Can anyone help to configure this its doing my nut in now.
This will be useful: https://developers.fortumo.com/cross-platform-mobile-payments/
I have the secret key and the widget set up i just need it add the stuff to my database e.g coins + 1 in a query but the code inserted into the successful payment bit wont run. So time to start again fresh.
Any help will be appreciated.
<?php
// check that the request comes from Fortumo server
if(!in_array($_SERVER['REMOTE_ADDR'],
array('1.2.3.4', '2.3.4.5'))) {
header("HTTP/1.0 403 Forbidden");
die("Error: Unknown IP");
}
// check the signature
$secret = ''; // insert your secret between ''
if(empty($secret) || !check_signature($_GET, $secret)) {
header("HTTP/1.0 404 Not Found");
die("Error: Invalid signature");
}
$sender = $_GET['sender'];//phone num.
$amount = $_GET['amount'];//credit
$cuid = $_GET['cuid'];//resource i.e. user
$payment_id = $_GET['payment_id'];//unique id
$test = $_GET['test']; // this parameter is present only when the payment is a test payment, it's value is either 'ok' or 'fail'
//hint: find or create payment by payment_id
//additional parameters: operator, price, user_share, country
if(preg_match("/completed/i", $_GET['status'])) {
// mark payment as successful
}
// print out the reply
if($test){
echo('TEST OK');
}
else {
echo('OK');
}
function check_signature($params_array, $secret) {
ksort($params_array);
$str = '';
foreach ($params_array as $k=>$v) {
if($k != 'sig') {
$str .= "$k=$v";
}
}
$str .= $secret;
$signature = md5($str);
return ($params_array['sig'] == $signature);
}
?>
The first lines of the code example validates that the request comes from Fortumo IP address, if not then it the script dies.
// check that the request comes from Fortumo server
if(!in_array($_SERVER['REMOTE_ADDR'],
array('1.2.3.4', '2.3.4.5'))) {
header("HTTP/1.0 403 Forbidden");
die("Error: Unknown IP");
}
Write to support#fortumo.com to get the latest IP addresses to validate (and replace the example values 1.2.3.4 with them).
Meanwhile you can comment out the ip check and continue building your script.
Xively provisioning - how does an app request a device feed ID and key?
On the "Provisioning" page it says:
"8 An application prompts the user for the serial number of the device they have just activated, the application uses a Master Key and the device serial number to request the device Feed ID and key from Xively."
This seems to suggest there's an API to do this, but I can't find it!
Does anyone know where this is in the docs or how to do this?
To get a feed ID for the device one need to make a Read Device request.
Go to Account | Settings | Add a master key
with Read/Update all permissions.
2) Note down the master key. Now to read all the devices (instances) created for a product (template) use API and key from (1)
URL: https://api.xively.com/v2/products/product_id/devices
X-ApiKey: The key you created in (1)
This API will return all devices with feedId and device keys.
A working example with Curl
include ('sensorui.inc');
include(APP_CLASS_LOADER);
// script to list all devices for a product
$url = "https://api.xively.com/v2/products/XwYNEGj4epo7HXNM0DGK/devices" ;
// API KEY
// This is master key API (from Account | settings page)
// for some reason (bug?) READ only key does not work!
$xheaders = array("X-ApiKey" => "your_master_key");
$cookies = array();
$curl = new \com\yuktix\util\curl\Wrapper($url,$cookies,$xheaders) ;
$curl->setCookies($cookies);
$curl->setXHeaders($xheaders);
// $curl->setDebug();
$response = $curl->doGet();
print_r($response);
$code = ($response["code"] != 200) ? 1 : 0 ;
return $code ;
Returns
rjha#kubuntu13:~/code/bitbucket/sensorui/scripts/xively$ php list-product.php
Array
(
[code] => 200
[response] => {"totalResults":2,"itemsPerPage":30,"startIndex":1,"devices":[{"serial":"SVSN001","activation_code":"xxx","created_at":"2014-02-02T15:05:37Z","activated_at":"2014-02-02T15:12:41Z","feed_id":xxx,"api_key":"xxx"},{"serial":"SVSN002","activation_code":"xxxx","created_at":"2014-02-02T15:05:37Z","activated_at":null,"feed_id":xxxx}]}