Contact form mail not sending in codeigniter - codeigniter

Hi I am newer in codeigniter.. In my website i add contact form and send a mail to gmail. I try this in my local xampp server its working fine. But once i host in godaddy server i am getting a error like
Severity: Warning
Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection timed out)
Filename: libraries/Email.php
Line Number: 2063
This Is my view code :
<div id="contactform">
<form id="contact" action="contactform" method="post">
<fieldset>
<div class="row">
<div class="five columns">
<label for="name" id="name_label">Your Name: <span class="required">*</span></label>
<input type="text" name="name" id="name" size="50" value="" class="text-input" required=""/>
<label for="email" id="email_label">Your Email Address: <span class="required">*</span></label>
<input type="email" name="email" id="email" size="50" value="" class="text-input" required/>
<label for="subject" id="subject_label">Subject</label>
<input type="text" name="subject" id="subject" value="" class="text-input" />
</div>
<div class="seven columns">
<label for="msg" id="msg_label">Your Message: <span class="required">*</span></label>
<textarea cols="60" name="msg" id="msg" class="text-input" required></textarea>
<br />
<input type="submit" name="submit" class="button" id="submit_btn" value="Send Message"/>
<br class="clear" />
</div>
</div>
</fieldset>
</form>
</div>
This is my controller code
public function contactform(){
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('msg');
//set to_email id to which you want to receive mails
$to_email = 'antoalexander#gmail.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'antoalexander#gmail.com';
$config['smtp_pass'] = 'xxxxxxx';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
//$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Thanks For Contacting Us! We Will Contact You Very Soon..</div>');
$this->load->view('layouts/head');
$this->load->view('contact');
$this->load->view('layouts/footer');
}
else
{
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
$this->load->view('layouts/head');
$this->load->view('contact');
$this->load->view('layouts/footer');
}
}

Related

Contact form not doing anything in laravel 5.7 even not showing any error

This was my contact form and here is the form action
<form action="{{ route('contact.send')}}" method="post" class="contactForm">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage"></div>
<div class="row">
<div class="span4 form-group">
<input type="text" name="name" id="name" placeholder="Your Name"data-rule="required" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="span4 form-group">
<input type="email" name="email" id="email" placeholder="Your Email" data-rule="required" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="span4 form-group">
<input type="text" name="phone" id="phone" placeholder="Your Phone"data-rule="required" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="span6 form-group">
<input type="text" name="subject" id="subject" placeholder="Subject" data-rule="required" data-msg="Please enter at least 8 chars of subject" />
<div class="validation"></div>
</div>
<div class="span6 form-group">
<input type="text" name="dateandtime" id="dateandtime" placeholder="Date and Time" data-rule="required" data-msg="Please Select a EST time and Date." />
<div class="validation"></div>
</div>
<div class="span12 margintop10 form-group">
<textarea name="message" rows="12" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
<p class="text-center">
<button class="btn btn-large btn-theme margintop10" type="submit">Submit message</button>
</p>
</div>
</div>
</form>
Bellow is the route and controller
Route::post('/contact','ContactController#sendMessage')->name('contact.send');
and the controller was
public function sendMessage(Request $request)
{
$this->validate($request,[
'name'=>'required',
'phone'=>'required',
'email'=>'required|email',
'subject'=>'required',
'messase'=>'required'
]);
$contact =new \App\contact();
$contact->name = $request->name;
$contact->email = $request->email;
$contact->phone = $request->phone;
$contact->subject = $request->subject;
$contact->date_and_time = $request->dateandtime;
$contact->message = $request->message;
$contact->status = false;
$contact->save();
Toastr::success('You Message Sent Successfully We will contact you soon!','Success',["positionClass" => "toast-top-center"]);
return redirect()->back();
}
And then the migration was as bellow
public function up()
{
Schema::create('contacts', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('phone');
$table->string('email');
$table->string('date_and_time');
$table->text('message');
$table->boolean('status');
$table->timestamps();
});
}
But when I clicking on my submit button after filling up the form that not showing any error or not doing anything. Please help me to solve this problem.
If you are using laravel 5, here is what you need to do for showing success message:
In your controller file:
return redirect()->back()->with('success', 'your message,here');
In your blade file:
#if (\Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{!! \Session::get('success') !!}</li>
</ul>
</div>
#endif
If you want to show error message than in your controller:
return Redirect::back()->withErrors(['msg', 'The Message']);
In your blade file:
#if($errors->any())
<h4>{{$errors->first()}}</h4>
#endif

Data Not Submitting to Database

I'm making a contact page but the form data is not saving to the database. What's the solution?
ContactController.php
public function contact()
{
if($request->isMethod('post'))
{
$data = $request->all();
}
$contact = new Contact;
$contact->name = $data['contact_name'];
$contact->email = $data['contact_email'];
$contact->subject = $data['contact_subject'];
$contact->body = $data['description'];
$category->save();
return redirect()->back()->with('flash_message_success',
'Your message has been sent successfully');
}
contact.blade.php
<form action="{{ url('/contact') }}" id="main-contact-form" class="contact-form row" name="contact-form" method="post">
{{ csrf_field() }}
<div class="form-group col-md-6">
<input type="text" name="contact_name" class="form-control" required="required" placeholder="Name">
</div>
<div class="form-group col-md-6">
<input type="email" name="contact_email" class="form-control" required="required" placeholder="Email">
</div>
<div class="form-group col-md-12">
<input type="text" name="contact_subject" class="form-control" required="required" placeholder="Subject">
</div>
<div class="form-group col-md-12">
<textarea name="description" id="message" required="required" class="form-control" rows="8" placeholder="Your Message Here"></textarea>
</div>
<div class="form-group col-md-12">
<input type="submit" name="submit" class="btn btn-primary pull-right" value="Submit">
</div>
</form>
Routes:
Route::get('contact', function(){
return view('contact');
});
Route::post('contact', function(){
return view('contact');
});
Use $contact->save(); not $category->save(); and also remove the if statement (for now): if($request->isMethod('post')) {
Your route should be:
Route::post('contact', 'ContactController#contact')->name('contact');

Vue.js Asp.NET core Form validation

I am currently learning vuejs with asp .net core right now.
I am doing some form validation and adding some error messages.
The error messages are from the Server side here is my sample code:
[HttpPost]
public async Task<IActionResult> AddUser([FromBody] UserModel user)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (_context.Users.Any(u => u.UserName == user.UserName))
{
ModelState.AddModelError("UserName", "Username is already in used");
return BadRequest(ModelState);
}
try
{
var userDto = new User
{
FirstName = user.FirstName,
LastName = user.LastName,
Password = user.Password,
UserName = user.UserName
};
_context.Users.Add(userDto);
await _context.SaveChangesAsync();
}
catch(Exception e)
{
ModelState.AddModelError("Saving Error", string.Format("Error in saving user. \nDetails:\n {0}", e.Message));
return BadRequest(ModelState);
}
return Ok();
}
And in the view:
<form v-on:submit.prevent="SaveUser()">
<div class="form-group">
<label for="userName">User Name</label>
<input class="form-control" type="text" id="userName" placeholder="Username" v-model="userName" required :disabled="isEditMode" />
</div>
<div class="form-group">
<label for="userName">First Name</label>
<input class="form-control" type="text" id="firstName" placeholder="First Name" v-model="firstName" required />
</div>
<div class="form-group">
<label for="userName">Last Name</label>
<input class="form-control" type="text" id="lastName" placeholder="Lastname" v-model="lastName" required />
</div>
<div v-if="!isEditMode">
<div class="form-group">
<label for="userName">Password</label>
<input class="form-control" type="password" id="password" placeholder="Password" v-model="password" required />
</div>
</div>
<!--TODO: Distribute to each control-->
<div v-if="hasError">
<ul v-for="error in errors">
<li style="color: red;" v-for="detail in error">{{detail}}</li>
</ul>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" #click="backToList()" class="btn btn-danger">Cancel</button>
</form>
Basically I am doing the validations from the server-side.
Currently the error messages are displayed below the controls
And I need to distribute all the error message inline with the inputs.
Can you help me with this?
Thanks in advance.

what am I doing wrong with form_validation messages name field access?

I want to try to valid confirm password matches with my confirm password, but it not then it will show me an error , but when I try to set up my messages for username then show me it cannot be accessed by it what am I doing wrong? but I try to change name filed in my username , but it doesn't work.
new_user controller
public function new_user(){
$first_name = $this->security->xss_clean(strip_tags($this->input->post('first_name')));
$last_name = $this->security->xss_clean(strip_tags($this->input->post('last_name')));
$profile_id = $this->security->xss_clean(strip_tags($this->input->post('profile_id')));
$password = $this->security->xss_clean(strip_tags($this->input->post('password')));
$username = $this->security->xss_clean(strip_tags($this->input->post('username')));
$data = array(
'first_name' => $first_name,
'last_name' => $last_name,
'profile_id' => $profile_id,
'password' => password_hash($password, PASSWORD_BCRYPT),
'username' => $username,
);
$this->form_validation->set_rules('first_name','first_name','trim|required');
$this->form_validation->set_rules('last_name','last_name','trim|required');
$this->form_validation->set_rules('username','username','trim|required|');
$this->form_validation->set_rules('password', 'password', 'trim|required');
$this->form_validation->set_rules('conf_password', 'conf_password', 'matches[password]|required');
$this->form_validation->set_message('first_name', 'Please enter First Name');
$this->form_validation->set_message('last_name', 'Please enter Last Name');
$this->form_validation->set_message('username', 'Please enter Username');
$this->form_validation->set_message('password', 'Please enter Password');
if ($this->form_validation->run() == FALSE) {
$this->json($this->form_validation->error_array());
}else{
$this->user->signup($data);
}
}
form
<form id="signup" method="post" onsubmit="return false;">
<h2 class="sr-only">New User</h2>
<div class="illustration">
<i class="icon ion-ios-locked-outline" style="color: rgb(251, 244, 244);"></i>
</div>
<div class="form-group">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="form-control"
required="required" />
</div>
<div class="form-group">
<input type="text" name="last_name" id="last_name" placeholder="Last Name" class="form-control"
required="required" />
</div>
<div class="form-group">
<select name="profile_id" id="profile_id" class="form-control" required="required">
<option value="">Select a Profile</option>
<?php foreach ($profile as $value): ?>
<option value="<?php echo $value['id'];?>">
<?php echo $value['profile']; ?>
</option>
<?php endforeach ?>
</select>
</div>
<div class="form-group">
<input type="text" name="username" id="username" placeholder="username" class="form-control"
required="required" />
</div>
<div class="form-group">
<input type="password" name="password" id="password" placeholder="***********" class="form-control"
required="required" />
</div>
<div class="form-group">
<input type="password" name="conf_password" id="conf_password" placeholder="***********" class="form-control"
required="required" />
</div>
<div class="form-group">
<button class="btn btn-primary btn-block" type="submit" style="background-color: rgb(41, 54, 78);">Ingresar</button>
</div>
</form>
output error
{username: "Unable to access an error message corresponding to your field name username.()"}
username
:
"Unable to access an error message corresponding to your field name username.()"
I think you should
Replace this
$this->form_validation->set_rules('username','username','trim|required|');
To:
$this->form_validation->set_rules('username','username','trim|required');

stripe token is not passing

I have an application built in Laravel 4 and uses this package
I am following this tutorial
This is the error I am getting http://postimg.org/image/c4qwjysgp/
My issue is $token is not correctly passing or the $token is empty.
I have already done a var_dump($token); die(); and get nothing but a white screen so not data is passing.
Here is the view
#extends('layouts.main')
#section('content')
<h1>Your Order</h1>
<h2>{{ $download->name }}</h2>
<p>£{{ ($download->price/100) }}</p>
<form action="" method="POST" id="payment-form" role="form">
<input type="hidden" name="did" value="{{ $download->id }}" />
<div class="payment-errors alert alert-danger" style="display:none;"></div>
<div class="form-group">
<label>
<span>Card Number</span>
<input type="text" size="20" data-stripe="number" class="form-control input-lg" />
</label>
</div>
<div class="form-group">
<label>
<span>CVC</span>
<input type="text" size="4" data-stripe="cvc" class="form-control input-lg" />
</label>
</div>
<div class="form-group">
<label>
<span>Expires</span>
</label>
<div class="row">
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-3">
<input type="text" size="2" data-stripe="exp-month" class="input-lg" placeholder="MM" />
</div>
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-3">
<input type="text" size="4" data-stripe="exp-year" class="input-lg" placeholder="YYYY" />
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg">Submit Payment</button>
</div>
</form>
#stop
Here is the route
Route::post('/buy/{id}', function($id)
{
Stripe::setApiKey(Config::get('laravel-stripe::stripe.api_key'));
$download = Download::find($id);
//stripeToken is form name, injected into form by js
$token = Input::get('stripeToken');
//var_dump($token);
// Charge the card
try {
$charge = Stripe_Charge::create(array(
"amount" => $download->price,
"currency" => "gbp",
"card" => $token,
"description" => 'Order: ' . $download->name)
);
// If we get this far, we've charged the user successfully
Session::put('purchased_download_id', $download->id);
return Redirect::to('confirmed');
} catch(Stripe_CardError $e) {
// Payment failed
return Redirect::to('buy/'.$id)->with('message', 'Your payment has failed.');
}
});
Here is the js
$(function () {
console.log('setting up pay form');
$('#payment-form').submit(function(e) {
var $form = $(this);
$form.find('.payment-errors').hide();
$form.find('button').prop('disabled', true);
Stripe.createToken($form, stripeResponseHandler);
return false;
});
});
function stripeResponseHandler(status, response) {
var $form = $('#payment-form');
if (response.error) {
$form.find('.payment-errors').text(response.error.message).show();
$form.find('button').prop('disabled', false);
} else {
var token = response.id;
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
$form.get(0).submit();
}
}
Here is the stripe.php in package
<?php
return array(
'api_key' => 'sk_test_Izn8gXUKMzGxfMAbdylSTUGO',
'publishable_key' => 'pk_test_t84KN2uCFxZGCXXZAjAvplKG'
);
Seems like the Config::get might be wrong.
It would have to be written this way.
Stripe::setApiKey(Config::get('stripe.api_key'));
I figured out the problem. In the source for the external javascript file, the "/" was missing at the beginning of the relative path. That is why the javascript file for the homepage was rendering fine but the /buy page was not rendering the javascript file.

Resources