代码之家  ›  专栏  ›  技术社区  ›  user9315107

mailchimp活动列表中保存数据的设置?

  •  1
  • user9315107  · 技术社区  · 7 年前
    ** I am building a emailing techniques with mailchimp i want to store
    data in the lists how can i insert data in the list of mailchimp
    campaign ?**
    

    是否有任何类型的api或其他我不熟悉的东西。 我正在使用laravel来做这件事。数据存储在mysql中,但如何开始将其保存在mailchimp列表中?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Pardeep Nagesh Katna    5 年前

    这对你有帮助

     class MailChimpController extends Controller
    {
    
        public function add( Request $request ) {
            $apikey="api key-us17";
            $server = "us17.";
            $listid = 'list id';
            if ( $request->isMethod( 'post' ) ) {
            //try {
                $request_data = $request->all();
                $email =$request_data['email'];
                $request_data['earlyprice'] = isset($request_data['earlyprice']) ? floatval($request_data['earlyprice']) : 0.0 ;
                $request->merge(['earlyprice' => $request_data['earlyprice']]);
                $request_data['gaprice'] = isset($request_data['gaprice']) ? floatval($request_data['gaprice']) : 0.0 ;
                $request->merge(['gaprice' => $request_data['gaprice']]);
                $this->validate( $request, [
                    'title'       => 'required|max:255',
                    'location'    => 'required|max:255',
                    'starttime'   => 'required',
                    'category'    => 'required',
                    'type'        => 'required',
                    'image'       => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:min_width=360,min_height=261',
                    'description' => 'required|max:1000',
                    'fullname'    => 'required|max:255',
                    'phone'       => 'required|max:255',
                    'email'       => 'required|max:255',
                    'website'     => 'required',
                    'socialmedia' => 'required'
                ] );
    
                $event     = new \App\CustomerEvent();
                $imageName = "";
                if ( $request->hasFile( 'image' ) ) {
                    $imageName = md5( time() ) . '.' . $request->image->getClientOriginalExtension();
                    $request->image->move( public_path( 'events_images' ), $imageName );
    
                }
    
                $requestData             = $request->all();
                $requestData['image']    = $imageName;
                $requestData['status']   = "D";
                $requestData['eventkey'] = $this->generate_key();
                $event->fill( $requestData );
                $x = $event->save();
    
                    $auth = base64_encode( 'user:'.$apikey );
                    $data = array(
                        'apikey'        => $apikey,
                        'email_address' => $email,
                        'status'        => 'subscribed',
    
                    );
                    $json_data = json_encode($data);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, 'Pathto ur trigger');
                curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: application/json','Authorization: Basic '.$auth));
                curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
    
    
                //return redirect()->back()->with( 'status', 'Event created' );
            } else {
                return view( 'events.host.index' );
            }
    
        }