** 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列表中开始保存?
答案 0 :(得分:0)
这会对你有所帮助
class MailChimpController extends Controller
{
//
// public $mailchimp;
// public $listId = 'list key';
// public function __construct(\Mailchimp $mailchimp)
// {
// $this->mailchimp = $mailchimp;
// }
// public function manageMailChimp()
// {
// return view('mailchimp');
// }
// public function subscribe(Request $request)
// {
// $this->validate($request, [
// 'email' => 'required|email',
// ]);
// try {
// $this->mailchimp
// ->lists
// ->subscribe(
// $this->listId,
// ['email' => $request->input('email')]
// );
// return redirect()->back()->with('success','Email Subscribed successfully');
// } catch (\Mailchimp_List_AlreadySubscribed $e) {
// return redirect()->back()->with('error','Email is Already Subscribed');
// } catch (\Mailchimp_Error $e) {
// return redirect()->back()->with('error',$e->getMessage());
// }
// }
// public function sendCompaign(Request $request)
// {
// $this->validate($request, [
// 'subject' => 'required',
// 'to_email' => 'required',
// 'from_email' => 'required',
// 'message' => 'required',
// ]);
// try {
// $options = [
// 'list_id' => $this->listId,
// 'subject' => $request->input('subject'),
// 'from_name' => $request->input('from_email'),
// 'from_email' => 'hardik@itsolutionstuff.com',
// 'to_name' => $request->input('to_email')
// ];
// $content = [
// 'html' => $request->input('message'),
// 'text' => strip_tags($request->input('message'))
// ];
// $campaign = $this->mailchimp->campaigns->create('regular', $options, $content);
// $this->mailchimp->campaigns->send($campaign['id']);
// return redirect()->back()->with('success','send campaign successfully');
// } catch (Exception $e) {
// return redirect()->back()->with('error','Error from MailChimp');
// }
// }
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' );
}
}