this seems pretty straightforward but i just can't get mailchimp to get the emails. I have a checkbox and all I want to do is say, if check then subscribe.
I get an error 500 and I have no idea where to go with this.
<?php echo CHtml::CheckBox('[subscribe]',true, array ( 'value'=>'yes',)); ?>
if ( $_POST['subscribe'])
{
Yii::import('application.vendors.mailchimp');
$mailchimp = new Mailchimp(Yii::app()->params['mailchimp']['key']);
$listId = '*******';
$email = array(
'email' => trim($_POST['User']['email']));
$subscriber = $mailchimp->list->subscribe(
$listId,
$email,
$merge_vars=null,
false,
false
);
}
Related
I'm trying verify online payment.
After I connect to bank getway by using function actionToken and pay, bank send me some information to verify payment with POST method, but I can't receive the information with POST method.
Here is my payment controller, function actionToken is for send data from my website such as amount ,and function actionVerify is for verifying payment that I have receive bank information. Here is my problem, that I don't know what do I have to do.
<?php
namespace frontend\controllers;
use Yii;
use common\models\Order;
class PaymentController extends \yii\web\Controller {
public function actionRequest() {
include_once('lib/nusoap.php');
$terminalId = "xxxx"; // Terminal ID
$userName = "xxxx"; // Username
$userPassword = "xxxxxxx"; // Password
$orderId = time(); // Order ID
$amount = $amount.'0'; // Price / Rial
$localDate = date('Ymd'); // Date
$localTime = date('Gis'); // Time
$additionalData = $model['notes'];
$callBackUrl = "http://dastsazkala.com/payment/verify?id=".$id; // Callback URL
$payerId = $id;
$parameters = [
'terminalId' => $terminalId,
'userName' => $userName,
'userPassword' => $userPassword,
'orderId' => $orderId,
'amount' => $amount,
'localDate' => $localDate,
'localTime' => $localTime,
'additionalData' => $additionalData,
'callBackUrl' => $callBackUrl,
'payerId' => $payerId];
$client = new \nusoap_client('https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl');
$namespace='http://interfaces.core.sw.bps.com/';
$result = $client->call('bpPayRequest', $parameters, $namespace);
}
public function actionVerify($id = null, $check = null) {
//my promblem is in this function, that I cant receive posts.
if ($_POST['ResCode'] == '0') {
//payment is correct
include_once('lib/nusoap.php');
$client = new nusoap_client('https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl');
$namespace='http://interfaces.core.sw.bps.com/';
$terminalId = "xxxx"; // Terminal ID
$userName = "xxxxx"; // Username
$userPassword = "xxxxx"; // Password
$orderId = $_POST['SaleOrderId']; // Order ID
$verifySaleOrderId = $_POST['SaleOrderId'];
$verifySaleReferenceId = $_POST['SaleReferenceId'];
$parameters = [
'terminalId' => $terminalId,
'userName' => $userName,
'userPassword' => $userPassword,
'orderId' => $orderId,
'saleOrderId' => $verifySaleOrderId,
'saleReferenceId' => $verifySaleReferenceId];
// Call the SOAP method
$result = $client->call('bpVerifyRequest', $parameters, $namespace);
if($result == 0) {
//verify is correct
echo 'The transaction was successful';
} else {
//error in pyament
}
} else {
//error in pyament
}
}
}
In this function I receive nothing.
Do I have to do something in behavior of my controller or something else?
Why I can't receive any posts in my controller?
General chrome:
Request URL: http://dastsazkala.com/payment/verify
Request Method: POST
Status Code: 301 Moved Permanently
Remote Address: 138.201.30.123:80
Referrer Policy: no-referrer-when-downgrade
Here what I receive:
The problem was this: my website url has www in the beginning, but there was no www in callBackUrl.
So I changed
$callBackUrl = "http://www.dastsazkala.com/payment/verify?id=".$id; //add www. in the beginning
instead of
$callBackUrl = "http://dastsazkala.com/payment/verify?id=".$id;
and I can receive Form Data with POST method from bank getway.
dastsazkala.com/payment/verify Redirects to www.dastsazkala.com/payment/verify notice the www!
the query result:
Status Code: 301 Moved Permanently
clearly hints that there might be a redirection going on
I'm using the Mailchimp v.2 API PHP wrapper to handle subscriptions... https://bitbucket.org/mailchimp/mailchimp-api-php however if a subscriber already exists on the list or the subscriber was unsubscribed, it returns an error, and I want to know a way I can code this to where if either of those cases exist, it will continue running the code without displaying an error. I apologize if this is a simple question.
$api_key = "XXXXXXXXX";
$list_id = "XXXXXX";
require('Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$merge_vars = array('FNAME'=>htmlentities($_POST['stripeFirstName']), 'LNAME'=>htmlentities($_POST['stripeLastName']) );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['stripeEmail']) ), $merge_vars );
You'll want to make use of try and catch. Mailchimp is pretty verbose about what goes wrong.
try {
$result = $Mailchimp_Lists->subscribe(
$list_id,
array(/* ... */), // primary subscriber data
array(/* ... */), // merge fields
'html', // email-type preference
false // double-opt-in
);
// Action for successful subscribe attempt.
} catch (\Exception $e) {
if ($e instanceof \Mailchimp_List_AlreadySubscribed) {
// In case they are already subscribed:
$errors[] = $e->getMessage();
} else {
// In case something else went wrong.
$errors[] = 'There was an error adding your email to the list. Would you mind trying again?';
}
// Debug time!
var_dump($errors);
}
I am trying to send email to multiple recipient address in cake php 3.
my codes are :
$this->loadModel('AsIndividualDetails');
$EmailDetails = $this-> AsIndividualDetails->find('all',['fields'=>'email']);
$EmailDetails = $EmailDetails->toArray();
foreach ($EmailDetails as $key => $a) {
$this->loadModel('DomainEmailDetails');
$DomainEmailDetails = $this-> DomainEmailDetails->find('all')->first();
$DomainEmailDetails = $DomainEmailDetails->toArray();
$host = 'ssl://'.$DomainEmailDetails['host_name'];
$username = $DomainEmailDetails['user_name'];
$password = $DomainEmailDetails['user_password'];
$port = $DomainEmailDetails['port'];
$email_to = $a['email'];
$senderName = 'abc';
$email_id ='xyz110#gmail.com';
Email::configTransport('WebMail', [
'className' => 'Smtp',
'host' => $host,
'port' => $port,
'timeout' => 30,
'username' => $username,
'password' => $password,
'client' => null,
'tls' => null,
]);
////////// SEND MAIL
$email = new Email('WebMail');
$email ->template('default','default')
->emailFormat('both')
->from([$username => $senderName])
->to($email_to)
->replyTo($email_id)
->subject('Client Message');
$response = $email->send('My msg');
if($response){
echo 'success';
}else{
echo 'failed';
}
}
When I run this script just only one mail send successfully and after that an error has come :
Cannot modify an existing config "WebMail"
How to solve this error and send mail to all recipient mail address.
If you really need set the config inside a loop, you could delete it before rewrite the config:
use Cake\Mailer\Email;
Email::dropTransport($key);
See Class Email API for more info
Make your email configuration outside of the loop. You don't want to try and establish the configuration every time you send the emails - just one time. Then send all the emails based on that one configuration.
I've followed this tutorial to implement mailchimp API v2.0 on my website.
It works great, however the double_optin option that I wanted to add and set to false (so that users don't need to validate their registration via e-mail) doesn't seem to be working. It's like if it was not taken into consideration at all, users still need to validate the registration via e-mail.
Is 'double_optin' => false placed at the wrong place? I had a look at mailchimp documentation but my level in programmation is not good enough to identify what is wrong.
Thanks for your help
<?php
$api_key = "12345486-us8";
$list_id = "123";
require('Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']),'double_optin' => false ) );
if ( ! empty( $subscriber['leid'] ) ) {
echo "success";
}
else
{
echo "fail";
}
?>
According to this (admittedly unofficial-looking) Mailchip_Lists documentation, you'll want to pass FALSE as the 5th parameter to subscribe().
Example:
$double_optin = FALSE;
$subscriber = $Mailchimp_Lists->subscribe(
$list_id,
array('email' => htmlentities($_POST['email'])),
NULL, // merge_vars
'html', // email_type
$double_optin
);
I am using this code to subscribe the posted email.
<?
$api_key = "apikey";
$list_id = "listid";
$gotemail = $_POST['email'];
require('src/Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => $gotemail ) );
?>
Now, What should I do to check if there is any error, and if it is, block it from exiting the script (killing it and printing the error on screen)? Like just save it in a variable and use it later.
Thank you in advance!