I am sending my code but it gives following error to send email.
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: 1554
Code is as following.
email.php file is a following.
<?php
class Email extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('form');
}
public function index()
{
$this->load->view('contact');
}
public function send()
{
$this->load->library('email');
$name=$this->input->post('name');
$form=$this->input->post('form');
$subject=$this->input->post('sub');
$msg=$this->input->post('message');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl:/gamil.smtp.com';
$config['smtp_port'] = 25;
$config['smtp_user'] ='rameshjadav133#gmail.com';
$config['smtp_pass'] ='jadav4545';
$this->load->library('email',$config);
$this->email->from($form,$name);
$this->email->to('rameshjadav133#gmail.com');
$this->email->subject($subject);
$this->email->message($msg);
if($this->email->send())
{
$data = array('message' =>'Email send success fulll....' );
}
else
{
$data = array('message' => 'Email not send' );
}
$this->load->view('contact',$data);
}
}
?>
contact.php file is as following.
<!DOCTYPE html>
<html>
<head>
<title>Contact form</title>
</head>
<body>
<?php
if(isset($message))
{
echo $message;
}
echo "<h1>Contact form </h1>";
echo form_open("email/send");
echo form_label("Name : ");
echo form_input("name");
echo "<br>";
echo form_label("From : ");
echo form_input("from");
echo "<br>";
echo form_label("Subject : ");
echo form_input("sub");
echo "<br>";
echo form_label("Message");
$data = array('name' => 'message','rows'=>5,'cols'=>32 );
echo form_textarea($data);
echo "<br>";
echo form_submit('submit','send Email');
echo form_close();
?>
</body>
</html>
Related
I have login page but i am dont know where i can take this alerts ,
i will take my script like this
echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('Your Login Succesfully ,'); window.location.href='home'; </SCRIPT>");
but i dont know how to make if else condition on my query in the model and contoller .I using num_rows but its didnt work .
my controller
public function login()
{
$u = $this->input->post('username');
$p = $this->input->post('password');
$data = $this->app_model->getlogindata($u,$p);
return $data;
}
my model
public function getlogindata($username,$password)
{
$u = $username;
$p = md5($password);
$cek_login = $this->db->get_where('login', array('username' => $u,'password'=>$p));
if(count($cek_login->result())>0)
{
foreach ($cek_login->result() as $qck)
{
if($qck->level=='puskesmas')
{
// $ambil_data = $this->db->get_where('puskesmas',array('id_puskesmas' => $u));
$this->db->select('*');
$this->db->from('puskesmas');
$this->db->join('login', 'puskesmas.id_puskesmas=login.id_puskesmas');
$this->db->where('username', $u);
$ambil_data = $this->db->get();
foreach ($ambil_data->result() as $qad)
{
$sess_data['logged_in'] = 'yes';
$sess_data['id_puskesmas'] = $qad->id_puskesmas; //
$sess_data['nama_puskesmas'] = $qad->nama_puskesmas;
$sess_data['alamat_puskesmas'] = $qad->alamat_puskesmas;
$sess_data['nama_petugas'] = $qad->nama_petugas;
$sess_data['nomor'] = $qad->nomor;
$sess_data['email'] = $qad->email;
$sess_data['level'] = $qad->level;
$this->session->set_userdata($sess_data);
}
header('location:'.base_url().'puskesmas');
} //xammp mu aktif?
elseif($qck->level=='dinas')
{
//$ambil_data = $this->db->get_where('dinas',array('id_dinas' => $u));
$this->db->select('*');
$this->db->from('dinas');
$this->db->join('login', 'dinas.id_dinas=login.id_dinas');
$this->db->where('username', $u);
$ambil_data = $this->db->get();
foreach ($ambil_data->result() as $qad)
{
$sess_data['logged_in'] = 'yes';
$sess_data['id_dinas'] = $qad->id_dinas;
$sess_data['nama_dinas'] = $qad->nama_dinas;
$sess_data['alamat_dinas'] = $qad->alamat_dinas;
$sess_data['kode_pos'] = $qad->kode_pos;
$sess_data['level'] = $qad->level;
$this->session->set_userdata($sess_data);
}
header('location:'.base_url().'dinas');
}
elseif($qck->level=='admin')
{
//$ambil_data = $this->db->get_where('admin',array('id_admin' => $u));
$this->db->select('*');
$this->db->from('admin');
$this->db->join('login', 'admin.id_admin=login.id_admin');
$this->db->where('username', $u);
$ambil_data = $this->db->get();
foreach ($ambil_data->result() as $qad)
{
$sess_data['logged_in'] = 'yes';
$sess_data['id_admin'] = $qad->id_admin;
$sess_data['nama_admin'] = $qad->nama_admin;
$sess_data['alamat_admin'] = $qad->alamat_admin;
$sess_data['status'] = $qad->status;
$sess_data['level'] = $qad->level;
$this->session->set_userdata($sess_data);
}
header('location:'.base_url().'admin');
}
else{
echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('Record Updated Successfully'); window.location.href='web'; </SCRIPT>");// i add this and still didnt work
}
}
}
}
in this script i just didnt know where i can take this alerts and what a parameter can i use to add this alerts . like if num_rows = 1 , echo = blablabla
thanks you sir
you have to use flash data in code igniter or you can use ajax callback in success you can alert what you want and redirect to whatever you like.
Controller
$this->session->set_flashdata('error_message', 'Incorrect Username or Password ! Please try again.');
redirect(URL.'backend/login');
View
<?php
if ($this->session->flashdata('error_message'))
{
?>
<div class="alert alert-danger" style="color: #fff;">
<!-- <button class="close" data-close="alert"></button> -->
<span><?php echo $this->session->flashdata('error_message'); ?></span>
</div>
<?php
}
if ($this->session->flashdata('ok_message'))
{
?>
<div class="alert alert-success">
<!-- <button class="close" data-close="alert"></button> -->
<span><?php echo $this->session->flashdata('ok_message'); ?></span>
</div>
<?php
}
?>
try this.i hope it will help you.
else{
echo '<script language="javascript">';
echo 'alert("Record Updated Successfully")';
window.location.href = 'web';
echo '</script>';
}
i m learning a tutorial on fileupload in laravel.
my file is not being uploaded.
there seems to be problem at this code.
//move uploaded file
$destinationPath = 'uploads';
$file = move($destinationPath,$file->getClientOriginalName());
and where exactly i need to create a destination path
These are my full codes
uploadfile.php
<body>
<?php
echo Form::open(array('url' => '/uploadfile','files' => 'true'));
echo "Select the file to upload!";
echo Form::file('image');
echo Form::submit('Upload File');
echo Form::close();
?>
</body>
FileUploadController.php
<?php
namespace FirstProject\Http\Controllers;
use Illuminate\Http\Request;
class FileUploadController extends Controller
{
public function index(){
return view('uploadfile');
}
public function showUploadFile(Request $req){
$file = $req->file('image');
//display the fullname
echo "File Name: " .$file->getClientOriginalName();
echo "<br>";
//display file extension
echo "File Extension: " .$file->getClientOriginalExtension();
echo "<br>";
//display file realpath
echo "File Real Path: " .$file->getRealPath();
echo "<br>";
//display file size
echo "File Size: " .$file->getSize();
echo "<br>";
//display file mime type
echo "File Mime Type: " .$file->getMimeType();
//move uploaded file
$destinationPath = 'uploads';
$file = move($destinationPath,$file->getClientOriginalName());
}
}
?>
web.php
Route::get('/uploadfile','FileUploadController#index');
Route::post('/uploadfile','FileUploadController#showUploadFile');
I want to save the image path through a form, but the path of the image is not saved.
i've tried with this but i don't know where to put the code
MultimediaController:
public function add()
{
$multimedia = $this->Multimedia->newEntity();
if ($this->request->is('post')) {
$multimedia = $this->Multimedia->patchEntity($multimedia, $this->request->data);
$file = $_FILES['url'];
$path = 'files/' .$_FILES['url']['name'];
move_uploaded_file($this->data['url']['tmp_name'], $path);
if ($this->Multimedia->save($multimedia)) {
$this->Flash->success('The multimedia has been saved.');
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The multimedia could not be saved. Please, try again.');
}
}
$categories = $this->Multimedia->Categories->find('list', ['limit' => 200]);
$this->set(compact('multimedia', 'categories'));
$this->set('_serialize', ['multimedia']);
}
add.ctp
<?= $this->Form->create($multimedia, array('enctype' => 'multipart/form-data')); ?>
<fieldset>
<legend><?= __('Add Multimedia') ?></legend>
<?php
echo $this->Form->input('title');
echo $this->Form->input('description');
echo $this->Form->input('mime_type');
echo $this->Form->input('filename');
echo $this->Form->input('url', array('type' => 'file'));
echo $this->Form->input('category_id', ['options' => $categories]);
echo $this->Form->input('created_by');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
I'm new to cakephp 3 and am a bit lost. Please help.
Update:
already achieved to save the image:
$file = $_FILES['url'];
$path = "webroot\\files\\" .$_FILES['url']['name'];
print_r($file);
move_uploaded_file($_FILES['url']['tmp_name'], $path);
if ($this->Multimedia->save($multimedia)) {
$this->Flash->success('The multimedia has been saved.');
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The multimedia could not be saved. Please, try again.');
}
But now the "url" is not saved in the database
I hope this help you, the script here has some improvements like using the short deceleration for arrays:
The Controller code:
//don't forget to import the Folder class
use Cake\Filesystem\Folder;
public function add()
{
$multimedia = $this->Multimedia->newEntity();
if ($this->request->is('post')) {
$multimedia = $this->Multimedia->patchEntity($multimedia, $this->request->data);
//upload script start here
$mm_dir = new Folder(WWW_ROOT . 'upload_dir', true, 0755);
$target_path = $mm_dir->pwd() . DS . $this->request->data('url.name');
move_uploaded_file($this->request->data('url.tmp_name'), $target_path);
//save the file name in the field 'url'
$multimedia->url= $this->request->data('url.name');
//the script ends here
if ($this->Multimedia->save($multimedia)) {
// ............
} else {
// .........
}
}
// ..........
}
add.ctp // improvement
<?= $this->Form->create($multimedia, ['type' => 'file']); ?>
echo $this->Form->input('url', ['type' => 'file']);
I am using Facebook PHP SDK with Codeigniter to do login and registration using Facebook. For this I am using This tutorial
my controller 'facebooktest.php' code is:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Facebooktest extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('input');
$this->load->library('session');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security');
}
function Facebooktest() {
parent::Controller();
$cookies = $this->load->model('facebook_model');
}
function index() {
$this->load->view('facebooktest/test2');
}
function test1() {
$data = array();
$data['user'] = $this->facebook_model->get_facebook_cookie();
$this->load->view('facebooktest/test1', $data);
}
function test2() {
$data['friends'] = $this->facebook_model->get_facebook_cookie();
$this->load->view('facebooktest/test2', $data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>
view 'test2.php' has code as:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Kent is Learning CodeIgniter - Test 2</title>
</head>
<body>
<fb:login-button autologoutlink="true"
onlogin="window.location.reload(true);"></fb:login-button>
<div style="width:600px;">
<?
if(isset($friends)){
foreach($friends as $friend){
?>
<img src="http://graph.facebook.com/<?=$friend['id'];?>/picture" title="<?=$friend['name'];?>" />
<?
}
}
?>
</div>
<p><?=anchor('facebook_connect/page4','Go back to page 4 of the tutorial');?></p>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '457228377680583', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
window.location.reload(true);
} else {
// The user has logged out, and the cookie has been cleared
}
});
</script>
</body>
</html>
And model 'facebook_model.php' has code:
<?php
class Facebook_model extends CI_Model {
function __construct() {
parent::__construct();
}
function get_facebook_cookie() {
$app_id = '457228377680583';
$application_secret = '01f660b73bc085f0b78cd22322556495';
if (isset($_COOKIE['fbs_' . $app_id])) {
echo "dfgdsf";exit;
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
} else {
return null;
}
}
function getUser() {
$cookie = $this->get_facebook_cookie();
$user = #json_decode(file_get_contents(
'https://graph.facebook.com/me?access_token=' .
$cookie['access_token']), true);
return $user;
}
function getFriendIds($include_self = TRUE) {
$cookie = $this->get_facebook_cookie();
$friends = #json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$cookie['access_token']), true);
$friend_ids = array();
foreach ($friends['data'] as $friend) {
$friend_ids[] = $friend['id'];
}
if ($include_self == TRUE) {
$friend_ids[] = $cookie['uid'];
}
return $friend_ids;
}
function getFriends($include_self = TRUE) {
$cookie = $this->get_facebook_cookie();
print_r($cookie);
$friends = #json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$cookie['access_token']), true);
if ($include_self == TRUE) {
$friends['data'][] = array(
'name' => 'You',
'id' => $cookie['uid']
);
}
return $friends['data'];
}
function getFriendArray($include_self = TRUE) {
$cookie = $this->get_facebook_cookie();
$friendlist = #json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$cookie['access_token']), true);
$friends = array();
foreach ($friendlist['data'] as $friend) {
$friends[$friend['id']] = array(
'name' => $friend['name'],
'picture' => 'http://graph.facebook.com/'.$friend['id'].'/picture'
);
}
if ($include_self == TRUE) {
$friends[$cookie['uid']] = 'You';
}
return $friends;
}
}
?>
The problem is that, in model, it is coming inside 'getFriends()'. From there it is going inside 'get_facebook_cookie()'. But it is not going inside if(isset($_COOKIE['fbs_' . $app_id])))
and hence, it is nor displaying data that I want.
So, if possible, please let me know whats wrong with my code.
Thanks in advance....
Its been two days I'm working with these guys. Need help here.
here is my view
$username = json_decode($this->session->userdata('users'), TRUE);
foreach ($username AS $key => $value) {
<?php echo $value['username']; ?>
<?php echo $value['firstname']; ?>
<?php echo $value['lastname']; ?>
<?php $u = $value['username']; ?>
<?php echo "<a href=".base_url()."index.php/bets/un_sess/$u /> X </a> " ?>
<?php } ?>
here is my controller
$user1 = json_decode($this->session->userdata('users'), TRUE);
foreach ($user AS $key => $value) {
$index = array_search($username, $user);
unset($user[$index]);
$this->session->set_userdata('users', $user);
array from user_data
{"username":"user1","firstname":"name1","lastname":"name2"},
{"username":"user2","firstname":"test","lastname":"test"}
the output of this is when the first time i click the
username its working but when i click another username it gives error like this
A PHP Error was encountered
Severity: Warning
Message: Illegal offset type in isset or empty
Filename: libraries/Session.php
Line Number: 433 A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: controllers/bets.php
Line Number: 290
ok since there is no answering in my questions. Here is my solutions
$user = json_decode($this->session->userdata('users'), TRUE);
foreach ($user AS $key => $value) {
if ($username == $value['username']){
unset($user[$key]);
}
}
$this->session->set_userdata('users', json_encode($user));