Jump to content

Problem with file_get_contents and Sendy


kiridos

Recommended Posts

Hello,

 

I need some help.

 

I am using Sendy from Sendy.co and the Simple Ajax Script which can be found here: http://sendy.co/api

 

Scenario A - working

Sever: Local XAMPP server

Script: Simple Ajax Script from above, is working like it should

allow_url_fopen: local -> On master -> Off

file_get_contents: returns the full strings of the API of Sendy. 

 

Scenario B - not working

Sever: HostEurope Webserver

Script: Same code, I am copying it from the folder of the XAMPP server, but it is not working

allow_url_fopen: local -> On master -> Off

file_get_contents: returns an empty string

 
What I have tried:
- moving Sendy installation to another server, and changing the URL in the script, so that the server
is not calling the function file_get_contents with the url of itself. I read that the DNS server could have
some problems with it. Well... the problem still exists.

- changing the url setting of the url from ipv6 to ipv4

- asking hoster HostEurope, but with no real help...

 

 

So, I am going to ask you. Maybe you can help me. I have no idea, why the same code is running 

on my local xampp server, but not on the HostEurope webserver.

 

Do you know this problem?

 

I also googled... a lot... but haven't found something that helped me.

 

 

Code:

	//------------------- Edit here --------------------//
	$sendy_url = ''; //here is the url of the sendy installation, which is right 
	$list = ''; //here is my list id, which is right
	//------------------ /Edit here --------------------//

	//--------------------------------------------------//
	//POST variables
	$name = $_POST['name'];
	$email = $_POST['email'];
	
	//subscribe
	$postdata = http_build_query(
	    array(
	    'name' => $name,
	    'email' => $email,
	    'list' => $list,
	    'boolean' => 'true'
	    )
	);
	$opts = array('http' => array('method'  => 'POST', 'header'  => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
	$context  = stream_context_create($opts);
	$result = file_get_contents($sendy_url.'/subscribe', false, $context);
	//--------------------------------------------------//
	
	echo $result;
?>

$(document).ready(function() {
	$("#signup-form").submit(function(e){
		e.preventDefault(); 
		
		var $form = $(this),
		name = $form.find('input[name="name"]').val(),
		email = $form.find('input[name="email"]').val(),
		url = $form.attr('action');
		
		$.post(url, {name:name, email:email},
		  function(data) {
		      if(data)
		      {
		      	if(data=="Some fields are missing.")
		      	{
			      	$("#status").text("Please fill in your name and email.");
			      	$("#status").css("color", "red");
		      	}
		      	else if(data=="Invalid email address.")
		      	{
			      	$("#status").text("Your email address is invalid.");
			      	$("#status").css("color", "red");
		      	}
		      	else if(data=="Invalid list ID.")
		      	{
			      	$("#status").text("Your list ID is invalid.");
			      	$("#status").css("color", "red");
		      	}
		      	else if(data=="Already subscribed.")
		      	{
			      	$("#status").text("You're already subscribed!");
			      	$("#status").css("color", "red");
		      	}
		      	else
		      	{
			      	$("#status").text("You're subscribed!");
			      	$("#status").css("color", "green");
		      	}
		      }
		      else
		      {
		      	alert("Sorry, unable to subscribe. Please try again later!");
		      }
		  }
		);
	});
	$("#signup-form").keypress(function(e) {
		    if(e.keyCode == 13) {
		    	e.preventDefault(); 
				$(this).submit();
		    }
		});
	$("#submit-btn").click(function(e){
		e.preventDefault(); 
		$("#signup-form").submit();
	});
});
Link to comment
Share on other sites

Thanks!

 

I tried to use cURL. It is working with my old webhosting provider, but not with Host Europe. I don't know what is wrong with this webhosting package... hotline support said, that the cURL script can't work because I POSTed a wrong email address to Sendy (it was something like hshhs@dhh.com)... 

 

Well I will switch my webhosting provider and hope that I can get out of this contract.

 

This topic can be closed, as I am not going to see it happen on this webhosting package. I will switch everything to my hold webhosting provider and see if I can find another, Sendy compatible hoster.

 

Maybe SendyPHP could work, but I am fine with switching to my old provider for now, using cURL.

 

Best regards,

kiridos

Edited by kiridos
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.