Codeigniter sending contact form message - codeigniter

I am working on sending email. I am on windows 7.
Here is my controller:
public function ilet(){
$name = $this->input->post("name");
$email = $this->input->post("email");
$message = $this->input->post("message");
$config = array(
"protocol" => "smtp",
"smtp_host" => "mail.pratikesnaf.com",
"smtp_port" =>"587",
"smtp_user" =>"deste#pratikesnaf.com",
"smtp_password" =>"********",
"starttls" =>true,
"charset" =>"utf-8",
"mailtype" =>"html",
"wordwrap" => true,
"newline" =>"\r\n",
);
$this->load->library("email", $config);
$this->email->from("mail.pratikesnaf.com");
$this->email->to("mail.pratikesnaf.com");
$this->email->subject("Müşteri bilgi mesajı");
$this->email->message("Kişinin Adı - " . $name .
" - Kişinin Email Adresi - " . $email . " - Kişinin Mesajı - " . $message);
$send = $this->email->send();
if($send)
{
echo "Mail gönderme işlemi başarılı";
}
else {
echo "Başarısız";
echo $this->email->print_debugger();
}
}
after that i fulfill the inputs and i submit the button. it says an error like this:
Başarısız220 server.tescilmerkezi.net ESMTP Exim 4.76 Tue, 10 Jul 2018 18:00:47 +0300
hello: 250-server.tescilmerkezi.net Hello www.pratikesnaf.com [185.85.237.26]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
Can you please help me how can i fix this error?

try to change these lines:
$this->email->from("mail.pratikesnaf.com");
$this->email->to("mail.pratikesnaf.com");
to
$this->email->from("yoursenderemail#pratikesnaf.com");
$this->email->to("receiveremail#blabla.com");

Related

How can I send sms using codeigniter 4?

I'm trying to send SMS using CodeIgniter 4 but something went wrong any help or another way to send?
This is my code:
public function message()
{
/*Check submit button */
if ($this->request->getPost()) {
$email = $this->input->post('email');
$data=$this->users_model->getUserByEmail($email);
$phone=$data['phone'];
$authKey = "3456655757gEr5a019b18";
/*Multiple mobiles numbers separated by comma*/
$mobileNumber = $phone;
/*Sender ID,While using route4 sender id should be 6 characters long.*/
$senderId = "ABCDEF";
/*Your message to send, Add URL encoding here.*/
$message = "From Codeigniter 4";
/*Define route */
$route = "route=4";
/*Prepare you post parameters*/
$postData = array(
'authkey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
'route' => $route
);
/*API URL*/
$url="https://control.msg91.com/api/sendhttp.php";
/* init the resource */
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
/*,CURLOPT_FOLLOWLOCATION => true*/
));
/*Ignore SSL certificate verification*/
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
/*get response*/
$output = curl_exec($ch);
/*Print error if any*/
if (curl_errno($ch)) {
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo "Message Sent Successfully !";
}
}
After run the code above my web page return "Message Sent Successfully!", but nothing received in my phone. What is the problem?
What does the cURL call responds in the $output variable?
You already put the output in it and i think it will guide you to the reason why the SMS is not sending out to your phone.

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.

getting error while sending email with multiple attachment in codeigniter

Code is working but can't send many files.... only images can be sended controller
public function sende(){
$from = $_POST['from'];
$address = $_POST['address'];
$to_name = $_POST['to_name'];
$to_email = $_POST['to_email'];
$cc = $_POST['cc'];
$subject = $_POST['subject'];
$mesg = $_POST['mesg'];
$start = $_POST['start'];
$end = $_POST['end'];
$mid1 = $_POST['mid1'];
$mid2 = $_POST['mid2'];
$message = $start.$mid1.$mesg.$mid2.$end;
$config = array(
'useragent' => 'CodeIgniter',
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => '***',
'smtp_pass' => '**',
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => '\r\n'
);
$this->load->library('email',$config);
$this->email->set_newline('\r\n');
$this->email->from($address,$from);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
$this->email->cc($cc);
$path = $this->config->item('server_root');
$file = $path.'/mshaadi/';
$this->load->library('upload');
$m = count($_FILES['atta']['name']);
$files = $_FILES;
for($i=0; $i< $m; $i++){
$_FILES['atta']['name']= $files['atta']['name'][$i];
$_FILES['atta']['type']= $files['atta']['type'][$i];
$_FILES['atta']['tmp_name']= $files['atta']['tmp_name'][$i];
$_FILES['atta']['error']= $files['atta']['error'][$i];
$_FILES['atta']['size']= $files['atta']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload('atta');
$a = $files['atta']['name'][$i];
$mm = base_url().'images/'.$a;
$this->email->attach($mm);
}
if($this->email->send()){
redirect('Email');
}else{
show_error($this->email->print_debugger());
}
}
private function set_upload_options(){
$config = array();
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png|pdf|sql|docx|pptx';
$config['max_size'] = '10000';
$config['overwrite'] = TRUE;
return $config;
}
Error while sending multiple attachment of docx, pptx
220-gator3150.hostgator.com ESMTP Exim 4.85 #2 Thu, 19 Nov 2015 00:10:43 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
220-gator3150.hostgator.com ESMTP Exim 4.85 #2 Thu, 19 Nov 2015 00:10:43 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
hello: 250-gator3150.hostgator.com Hello 127.0.0.1 [112.196.141.163]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250 HELP
from: 250 OK
to: 501 <>: missing or malformed local part
The following SMTP error was encountered: 501 <>: missing or malformed local part
data: 503-All RCPT commands were rejected with this error:
503-501 <>: missing or malformed local part
503 Valid RCPT command must precede DATA
The following SMTP error was encountered: 503-All RCPT commands were rejected with this error: 503-501 <>: missing or malformed local part 503 Valid RCPT command must precede DATA
500 unrecognized command
The following SMTP error was encountered: 500 unrecognized command
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Thu, 19 Nov 2015 07:10:37 +0100
From: "" <>
Return-Path: <>
Subject: =?ISO-8859-1?Q??=
Reply-To: "" <>
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <564d67dddeddc>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_564d67dddeddc"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_564d67dddeddc
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
--B_ALT_564d67dddeddc
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
--B_ALT_564d67dddeddc--
$this->load->library('email');
$this->load->helper('path');
$this->load->helper('directory');
//setting path to attach files
$path = set_realpath('assets/your_folder/');
$file_names = directory_map($path);
$this->email->clear(TRUE);
$this->email->to($address);
$this->email->from('your#example.com');
$this->email->subject('Here is your info '.$name);
$this->email->message('Hi Here is the info you requested.');
foreach($file_names as $file_name)
{
$this->email->attach($file_name);
}
$this->email->send();
For multiple attachments you can use the same function multiple times,On your code you haven't used multiple times and not given loop too.
Try using the full path instead of just the url-
$this->email->attach('C:\Users\xyz\Desktop\images\abc.png');
or
$attched_file= $_SERVER["DOCUMENT_ROOT"]."/uploads/".$file_name;
$this->email->attach($attched_file);
also try changing the charset as-
$config['charset'] = 'iso-8859-1';
Codeigniter send email with attach file
https://ellislab.com/codeigniter/user-guide/libraries/email.html

Email Attachment not working in codeigniter

Mail function with attachment file is not working in codeigniter, i m not receiving any mail with attachment.. before i received the mail without attachment but after i used "$_SERVER["DOCUMENT_ROOT"]."/admin/assets/image/order_complete_file/".$image_name;", i didnt receive any mail.. kindly help me.. Here my coding is
$image_name = "some_name";
$content = "some content";
$subject = "Subject Name";
$this->load->helper('email');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from('abc#gmail.com');
$this->email->to('xxx#gmail.com');
$this->email->subject($subject);
$this->email->message($content);
$attched_file = $_SERVER["DOCUMENT_ROOT"]."/admin/assets/image/order_complete_file/".$image_name;
$this->email->attach($attched_file);
$this->email->send();
You should use config parameter for email library, and set 'mailtype' to 'html'(Default Value is 'text'). If it still fails, you should use the print_debugger() function to see why.
$config = Array(
'mailtype' => 'html'
);
$image_name = "some_name";
$content = "some content";
$subject = "Subject Name";
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('abc#gmail.com');
$this->email->to('xxx#gmail.com');
$this->email->subject($subject);
$this->email->message($content);
$attched_file = $_SERVER["DOCUMENT_ROOT"]."/admin/assets/image/order_complete_file/".$image_name;
$this->email->attach($attched_file);
if($this->email->send()){ echo 'Email send.';}
else {show_error($this->email->print_debugger()); }

404 not found twitter api 1.1 codeginter

I've been working on upgrading from v 1 to 1.1 for a few days now. I have 100s of users that can't see their followers in my dashboard.
I followed all the steps by changing /1/ to /1.1/ still not working.
Getting error 404 (Not Found)
Controller:
function twitter_auth()
{
if ( !$this->tweet->logged_in() )
{
die('some how you are not logged in');
}
$tokens = $this->tweet->get_tokens();
$this->tweet->enable_debug(TRUE);
$user = $this->tweet->call('get', 'account/verify_credentials');
var_dump($user);
}
$options = array(
'count' => 10,
'page' => 2,
'include_entities' => 1
);
$timeline = $this->tweet->call('get', 'statuses/home_timeline');
var_dump($timeline);
}
Jobs:
function get_twitter_subscribers($args)
{
$rate = #file_get_contents('http://api.twitter.com/1.1/application/rate_limit_status.json');
$rate = #json_decode($rate);
if($rate->remaining_hits == 0):
$status = 'retask';
else:
$new_data = #file_get_contents('http://api.twitter.com/1.1/users/show.json? screen_name='.$args['account_id'].'&include_entities=true');
$new_data = #json_decode($new_data);
if(isset($new_data->followers_count)){
$insert_args = array(
'account_id' => $args['account_id'],
'metric' => 'subscribers',
'value' => $new_data->followers_count,
'platform' => 'twitter'
);
$insert = $this->CI->metrics_model->insert_metric($insert_args);
if (isset($insert)) { $status = 'complete'; }
}else{
$this->send_error_email("Function: get_twitter_subscribers - new_data->followers_count not set for account id: " . $args['account_id'] . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
}
endif;
if(!isset($status)){
$this->send_error_email("Function: get_twitter_subscribers - status not set." . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json? screen_name='.$args['account_id'].'&include_entities=true');
$status = 'error';
}
return $status;
controllers:
function auth($platform)
{
if($platform == 'facebook'):
echo 'auth facebook';
elseif($platform == 'twitter'):
$this->load->library('tweet');
// current key in php page
$tokens = array(
'oauth_token' => 'xxxxxxxxxxxxx',
'oauth_token_secret' => 'xxxxxxxxxxxx'
);
$this->tweet->set_tokens($tokens);
if ( !$this->tweet->logged_in() ) :
$this->tweet->set_callback(site_url('manage/auth/twitter'));
$this->tweet->login();
else:
echo 'Twitter logged in. Return to manager';
endif;
endif;
}
What am I doing wrong?
This issue has been resolved. I created my own cURL library.
function get_twitter_subscribers($args){
$request = curl_init();
$bearer = "AAAAAAAAAAAAAAAAAAAAAJ%2xxxxxxxxxxxxxxx0000x0x0x0x0";
curl_setopt($request, CURLOPT_SSLVERSION, 1);
curl_setopt($request, CURLOPT_URL, 'https://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
curl_setopt($request, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$bearer));
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$new_data = json_decode($file_get_contents = curl_exec($request));
curl_close($request);
if(isset($new_data->followers_count)){
$insert_args = array(
'account_id' => $args['account_id'],
'metric' => 'subscribers',
'value' => $new_data->followers_count,
'platform' => 'twitter'
);
$insert = $this->CI->metrics_model->insert_metric($insert_args);
if (isset($insert)) { $status = 'complete'; }
}else{
$this->send_error_email("Function: get_twitter_subscribers - new_data->followers_count not set for account id: " . $args['account_id'] . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'https://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
}
if(!isset($status)){
$this->send_error_email("Function: get_twitter_subscribers - status not set." . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
$status = 'error';
}
return $status;
}

Resources