APNS on Godaddy unable to connect - apple-push-notifications

I have a godaddy dedicated server on which I have installed SSL certificate from godaddy.
I am using following script for sending push notification
$passphrase = 'pass';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '../folder/file/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
//echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => 1,
'category' => 'NOTIFICATION'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
fclose($fp);
When I run this code from the browser I receive notification but when i run this same code from cron job it gives me unable to connect error.
I ran the script from terminal it gives me the following error
stream_socket_client(): Failed to enable crypto
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)

Check if the correct port is open -
http://www.canyouseeme.org. (You are looking for port 2195)
If it is not open then you need to call GoDaddy and ask them to open port 2195 on your dedicated server. (They will not open the port for shared hosting)

Here are a few tips that should can help you out:
Go to entrust.net/downloads/root_request.cfm and download entrust_2048_ca.cer
Add following code:
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
Make sure if path is right: '../folder/file/ck.pem' ?
Switch and try both the sandbox and live ssl links.

Related

Apple Push Notification not receiving

I am using following PHP script for APNS
function send_push_ios_test($msg)
{
// Put your device token here (without spaces):
$deviceToken = '6778601ee2fd7809a90f2eaf709d5bbbbd3bec38c5b35e1428d7857f4b6ec0a7';
//$deviceToken = '6778601e e2fd7809 a90f2eaf 709d5bbb bd3bec38 c5b35e14 28d7857f 4b6ec0a7';
// Put your private key's passphrase here:
$passphrase = 'Pass#123';
// Put your alert message here:
$message = $msg;
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '../uploads/ios_pns/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
//$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => array(
'body' => $message,
'action-loc-key' => 'Bango App',
),
'badge' => 2,
'sound' => 'oven.caf',
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
}
The script shows connected to APNS & then message delivered successfully, but I am not getting push message on my device. Can anybody help me out with this.
Push notification is enabled on my device for sample app as well as from XCODE.

Laravel 4.2 sending a sms to mobile phone with twilio

I am trying to send a message from my laravel app with trial but am getting an error which I cannot configure. Any ideas?
This is my controller
public function postSend() {
if (Input::has("message")) {
$sid = "AC792b6fee2aabbe52be63f22235b15ae5";
$token = "3c7fb18d1a615ac3f76b0b37f13d7177";
$http = new Services_Twilio_TinyHttp(
'https://api.twilio.com',
array('curlopts' => array(
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
))
);
$client = new Services_Twilio($sid, $token, $http);
$message = $client -> account -> messages -> sendMessage('+256 758 029980',
'+256 788 207331',
Input::get("message"));
return Redirect::route('booking')
->with(
array(
'success' => 'Message Send Successfully Message SID ::' . $message -> sid
)
);
}
else {
return Redirect::back()
->withErrors('did not send the message');
}
and the error I am getting is
Services_Twilio_TinyHttpException (E_ERROR)
SSL certificate problem: self signed certificate in certificate chain
What is your version of libcurl?
On this link, (making sure you have an up to date version of the helper library) it says that you have to Upgrade your version of libcurl:
https://github.com/twilio/twilio-php/blob/master/docs/faq.rst#ssl-validation-exceptions
If it does not work, you can try to Edit TinyHttp.php
by adding: CURLOPT_SSL_VERIFYPEER => FALSE, at $opts array
but it's not the optimal solution.

Can't send email from gmail in codeigniter, SMTP Authentication error

I'm trying to send an email in codeigniter, but something wrong and i dont know how to fix it.
It success when I send in localhost, but when I upload my app into host, it cant send. This is my code
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = '****';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->send();
echo $this->email->print_debugger();
And this is my error when I submit an email
Failed to authenticate password. Error: 535 Incorrect authentication data
*from: 250 OK
to: 550-Please turn on SMTP Authentication in your mail client, or login to the
550-IMAP/POP3 server before sending your message. mb2d247.vdrs.net
550-(hanghieunara.com) [112.78.2.247]:51939 is not permitted to relay through
550 this server without authentication.*
The following SMTP error was encountered: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message.
mb2d247.vdrs.net 550-(hanghieunara.com) [112.78.2.247]:51939 is not permitted to relay through 550 this server without authentication.
See if your email account is not active with difinições security for external access, if you need to grant access to your site's SMTP server (your email address) so you can perform authentication.
To send smtp gmail autenticated with codeigniter
1 - Be sure if openssl in your php instalation is enabled.
2- This command is fundamental to script works: $this->email->set_newline("\r\n");
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'gmail.login#googlemail.com',
'smtp_pass' => 'your_password',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('gmail.login#googlemail.com', 'Your Name');
$this->email->to('recipient#destination.tld');
$this->email->subject(' CodeIgniter Rocks Socks ');
$this->email->message('Hello World');
if (!$this->email->send())
show_error($this->email->print_debugger());
else
echo 'Your e-mail has been sent!';
Full solution link: https://ellislab.com/forums/viewthread/84689/

Email sent in localhost but not in server

When I try to send emails from localhost, everything works fine. But when I uploaded my app to the server, the email functionality doesn't work anymore! I uses a Gmail account.
Here is my config/email.php file:
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'myemail#gmail.com';
$config['smtp_pass'] = 'my_password';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 80;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
$config['sender_name'] = 'Name';
$config['from_email'] = 'myemail#gmail.com';
$config['to_email'] = 'myemail#gmail.com';
$config['email_subject'] = 'Email Subject';
And this is how I sent an email in my controller:
$this->load->library('email');
$this->email->from($this->config->item('from_email'), $this->config->item('sender_name'));
$this->email->to($this->config->item('to_email'));
$this->email->subject($this->config->item('email_subject'));
$this->email->message($string);
if (!$this->email->send())
{
$data['success'] = FALSE;
}
else
{
$data['success'] = TRUE;
}
$this->_example_output('layouts/sendemail_confirm.php', $data);
And this is the error I receive:
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to
ssl://smtp.googlemail.com:465 (Connection refused)
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection refused)
It's possible that your server's IP address is blacklisted by Google due to previous spamming attempts... Is it a shared hosting account? A cloud hosting account? Etc? All those are susseptable to stuff like this.
There might also be a reverse DNS lookup mismatch with the domain name and from address, or the domain's DNS might have SPF policy settings that are preventing Google from accepting mail, or an envelop issue with the host-name, or it's using 127.0.0.1 as the originating address.
Also check your php.ini settings to make sure you are using / or not-using sendmail_from= and mail.add_x_header= the same way on both systems.
Try using smtp host as "smtp.gmail.com"
$config['smtp_host'] = 'smtp.gmail.com';
Use this config options
$config['protocol'] = 'smtp';
$config['mail_path'] = 'ssl://smtp.googlemail.com';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
And add this line, after loading email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$config = Array(
'protocol' => 'mail',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'iskpro.it#gmail.com', // change it to yours
'smtp_pass' => 'afycon#123', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($from); // change it to yours
$this->email->to($to);// change it to yours
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();

How do I send email to local system using xamp and windows7 in codeigniter?

I'm trying to run this code :
$this->load->library('email');
$this->email->from('anu1488#gmail.com', 'Anudeep');
$this->email->to('anu1488#gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
When I tried to send, I got this error:
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1553
What caused this? How can I resolve it?
It sounds like you do not have an SMTP server (mail server) set up on your local machine to send out email. It sounds like the libraries/Email.php file is referencing a hostname/port where a valid mail server does not live.
**I guess you need to setup email configuration and port number in config/email .**
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='abhi.abc#gmail.com';
$config['smtp_pass']='password';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['mailtype'] = "html";
**if every thing is correct from your side then you can just change 'smtp_port' number and then check it definitely it will work`enter code here`.**
try this,its working for me....
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'user#gmail.com',
'smtp_pass' => 'user password',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('user#gmail.com', 'User');
$this->email->to(sample#gmail.com);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if ($this->email->send()) {
$data['error'] = "Your email was sent";
} else {
show_error($this->email->print_debugger());
}
then open your php.ini and go to extension=php_openssl.dll and un comment this line .
after that restart ur wamp server.

Resources