I'm trying to get a contact form to send information(name, email and message) to a personal email, but it keeps returning "AN ERROR OCCURRED: ERROR" and I've hit a wall on what I am doing incorrectly.
It should just submit the form to my personal email, but when trying to select the 'submit' button it gives me the above message and doesn't display anything else.
Here is the html:
<form name="ajax-form" id="ajax-form" action="mail-it.php" method="post">
<div class="eight columns">
<label for="name">
<span class="error" id="err-name">please enter name</span>
</label>
<input name="name" id="name" type="text" placeholder="Your Name: *"/>
</div>
<div class="eight columns">
<label for="email">
<span class="error" id="err-email">please enter e-mail</span>
<span class="error" id="err-emailvld">e-mail is not a valid format</span>
</label>
<input name="email" id="email" type="text" placeholder="E-Mail: *"/>
</div>
<div class="sixteen columns">
<label for="message"></label>
<textarea name="message" id="message" placeholder="What's on your mind"></textarea>
</div>
<div class="ten columns offset-by-six">
<div id="button-con"><button class="button-primary" id="send"><span data-hover="submit">submit</span></button></div>
</div>
<div class="clear"></div>
<div class="error text-align-center" id="err-form">There was a problem validating the form please check!</div>
<div class="error text-align-center" id="err-timedout">The connection to the server timed out!</div>
<div class="error" id="err-state"></div>
</form>
Here is the mail-it.php markup:
<?php
$send_to = "enter#youremail.com";
$send_subject = "ajax form";
$f_name = cleanupentries($_POST["name"]);
$f_email = cleanupentries($_POST["email"]);
$f_message = cleanupentries($_POST["message"]);
$from_ip = $_SERVER['REMOTE_ADDR'];
$from_browser = $_SERVER['HTTP_USER_AGENT'];
function cleanupentries($entry) {
$entry = trim($entry);
$entry = stripslashes($entry);
$entry = htmlspecialchars($entry);
return $entry;
}
$message = "This email was submitted on " . date('m-d-Y') .
"\n\nName: " . $f_name .
"\n\nE-Mail: " . $f_email .
"\n\nMessage: \n" . $f_message .
"\n\n\nTechnical Details:\n" . $from_ip . "\n" . $from_browser;
$send_subject .= " - {$f_name}";
$headers = "From: " . $f_email . "\r\n" .
"Reply-To: " . $f_email . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if (!$f_email) {
echo "no email";
exit;
}else if (!$f_name){
echo "no name";
exit;
}else{
if (filter_var($f_email, FILTER_VALIDATE_EMAIL)) {
mail($send_to, $send_subject, $message, $headers);
echo "true";
}else{
echo "invalid email";
exit;
}
}
?>
Related
I'm uploading multiple images on server but instead of saving images in database and folder a 403 error occured. so please help me how to resolve it.
This is the Form & Controller code:
<form method="POST" action="{{ route('AddImages') }}" id="smart" enctype="multipart/form-data">
#csrf
<input type="hidden" name="id" value="{{$id}}">
<div class="form-body">
<div class="form-row">
<div class="section col-6">
<label for="bname" class="field-label">Image</label>
<label for="bname" class="field prepend-icon">
<input type="file" name="image[]" class="gui-input" multiple required>
<span class="field-icon"><i class="fas fa-circle"></i></span>
</label>
</div><!-- end section -->
</div>
</div><!-- end .form-body section -->
<div class="form-footer">
<button type="submit" class="button btn-primary"> Save</button>
<button type="reset" class="button"> Cancel</button>
</div><!-- end .form-footer section -->
</form>
$images = $request->file('image');
$num = 0;
foreach ($images as $im) {
$files = $im->getClientOriginalExtension();
foreach ($request->image as $file) {
$image = new ClassImage();
$file_name = time() . rand(1, 999) . '.' . $file->getClientOriginalExtension();
$path = base_path('backend/images/class_images/');
$image->image = $file_name;
$image->class_id = $request->id;
try {
$file->move($path, $file_name);
$image->save();
$num++;
} catch (Exception $e) {
echo $e;
}
}
}
return redirect('ShowImages/'.$request->id);
I don't know what is the error in this code because on local server this code working fine but on server the problem 403 (Access denied) Occured.
I'm new at using codeigniter and I'm trying to update the item value in my database but it's not working. I can't figure out what to do because when I clicked the save button, the page redirects to the /packages(where the list of packages are displayed) but the item isn't updated. Here's my controller
public function update_package($id)
{
$this->form_validation->set_rules('title', 'Package Name', 'required');
$this->form_validation->set_rules('tour_location', 'Inclusions', 'trim');
$this->form_validation->set_rules('description', 'Description', 'trim|required');
$this->form_validation->set_rules('cost', 'Price', 'required');
$this->form_validation->set_rules('status', 'Status', 'required');
if ($this->form_validation->run() == true) {
$current_image = $this->input->post('current_image');
$new_image = $_FILES['image']['name'];
if ($new_image == TRUE) {
$update_image = time() . "-" . str_replace(' ', '-', $_FILES['image']['name']);
$config = [
'upload_path' => './images',
'allowed_types' => 'gif|jpg|png',
'file_name' => $update_image,
];
$this->load->library('upload', $config);
if (!$this->upload->do_upload('image')) {
if (file_exists('./images' . $current_image)) {
unlink('./images' . $current_image);
}
}
} else {
$update_image = $current_image;
}
$packageData = array(
'title' => $this->input->post('title'),
'tour_location' => $this->input->post(htmlentities('tour_location')),
'description' => $this->input->post(htmlentities('description')),
'cost' => $this->input->post('cost'),
'status' => $this->input->post('status'),
'upload_path' => $update_image
);
$img = new Admin_model;
$img->update($packageData, $id);
$this->session->set_flashdata('status', 'Package InsertedSuccesfully');
redirect(base_url('admin/edit_package/'.$id));
} else {
return $this->edit_package($id);
}
}
My model
public function update($data, $id) {
// Update member data
return $this->db->update("packages", $data ,array('id' => $id));
}
View
<div class="card-body">
<small><?php echo validation_errors(); ?></small>
<form action="<?= base_url('admin/packages') ?>" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="name" class="control-label">Package Name</label>
<input type="text" class="form-control mb-3" name="title" placeholder="Enter Package Name" value="<?php echo !empty($packages->title) ? $packages->title : ''; ?>">
</div>
<div class="form-group">
<label for="short_name" class="control-label">Inclusions</label>
<textarea id="compose-textarea" class="form-control" name="tour_location" style="height: 300px;"><?php echo !empty($packages->tour_location) ? $packages->tour_location : ''; ?></textarea>
</div>
<div class="form-group">
<label for="short_name" class="control-label">Description</label>
<textarea id="compose-textarea2" class="form-control" name="description" style="height: 300px;"><?php echo !empty($packages->description) ? $packages->description : ''; ?></textarea>
</div>
<div class="form-group">
<label for="price" class="control-label">Price</label>
<input type="number" step="any" class="form-control form" required name="cost" value="<?php echo !empty($packages->cost) ? $packages->cost : 0; ?>">
</div>
<div class="form-group">
<label for="status" class="control-label">Status</label>
<select name="status" id="status" class="custom-select select">
<option value="1" <?php echo isset($status) && $status == 1 ? 'selected' : '- Select Status -' ?>>Active</option>
<option value="0" <?php echo isset($status) && $status == 0 ? 'selected' : '- Select Status -' ?>>Inactive</option>
</select>
</div>
<div class="form-group">
<label for="short_name" class="control-label">Images</label>
<div class="custom-file">
<label class="btn custom-file-label text-light" for="customFile">Choose file
<input type="hidden" name="current_image" value="<?php echo !empty($packages->upload_path) ? $packages->upload_path : ''; ?>">
<input type="file" class="form-control custom-file-input" id="customFile" name="image" multiple accept="image/*">
<small><?php if (isset($error)) {
echo $error;
} ?></small>
</label>
</div>
</div>
<div class="col-md-4">
<img src="<?php echo base_url('images/'.$packages->upload_path) ?>" alt="Package Image" class="w-100 h-100">
</div>
<div class="card-footer">
<input type="submit" name="packageData" class="btn btn-success " value="Save">
<a class="btn btn-flat btn-default" href="admin/packages">Cancel</a>
</div>
</form>
</div>
<script>
$("#submit").click(function(e) {
e.preventDefault();
$('#packageData').submit();
});
</script>
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');
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');
}
}
This is the predefined post function inside Magento controller.
public function postAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
$translate = Mage::getSingleton('core/translate');
/* #var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
try {
$postObject = new Varien_Object();
$postObject->setData($post);
$error = false;
if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
//$error = true; //orignal code
$error = false;
}
if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}
Mage::log($post['producturl']);
if (!Zend_Validate::is(trim($post['producturl']) , 'NotEmpty')) {
$error = true;
}
//if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
// $error = true;
//}
Mage::log($error);
Mage::log($postObject);
if ($error) {
throw new Exception();
}
$mailTemplate = Mage::getModel('core/email_template');
/* #var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
if (!$mailTemplate->getSentSuccess()) {
throw new Exception();
}
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
$this->_redirect('');
return;
} catch (Exception $e) {
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
When I log the producturl attribute, it prints the correct view.But I do not get that value in my email. How to get that value binded so it gets send to the email?
My form looks like this:
<form action="<?php echo $this->getUrl('contacts/index/post'); ?>" id="contactForm" method="post">
<div class="row">
<div class="col-sm-12">
<!--<label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>-->
<div class="input-box">
<input name="name" id="name" placeholder="Name*" title="<em>*</em><?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
</div>
</div>
<div class="col-sm-12">
<!--<label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>-->
<div class="input-box">
<input name="email" id="email" placeholder="Email*" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
</div>
</div>
<div class="col-sm-12">
<!--<label for="telephone" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Mobile') ?></label>-->
<div class="input-box">
<input name="telephone" id="telephone" placeholder="Mobile*" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text required-entry" type="text" />
</div>
</div>
<div class="col-sm-12">
<div class="input-box">
<input name="producturl" id="producturl" placeholder="Product URL*" title="<?php echo Mage::helper('contacts')->__('ProductURL') ?>" value="url hai bhai" class="input-text required-entry" type="text" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<!--<label for="comment" class=""><?php echo Mage::helper('contacts')->__('Comment') ?></label>-->
<div class="input-box input-textarea">
<textarea name="comment" id="comment" rows="3" placeholder="Message" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class=" input-text" placeholder="<?php echo Mage::helper('contacts')->__('Comment') ?>" style="width: 100%; height: 15%;resize:none;"></textarea>
</div>
</div>
</div>
<div class="row" style="text-align: center">
<div class="col-sm-12" style="padding-top:2%">
<input type="text" name="hideit" id="hideit" value="url hai bhai" style="display:none !important;" />
<button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('BOOK A DESIGNER') ?></span></span></button>
</div>
</div>
</div>
</div>
So, the emails templates are html files that you can actually find in the folder app/locale/[some_locale]/template/ if your locale is english of the US then some_locale will be en_US, if that is french from Belgium, then it will be fr_BE, so that is the language code on 2 letter as defined by ISO 639-1 then an underscore _ and country code as defined by ISO 3166-1 alpha-2.
And the name of the file will be something you could find if you do a global search on the handle of the template you actually stated in you comment.
So here contacts_email_email_template is actually defined in app/code/core/Mage/Contacts/etc/config.xml as being the file contact_form.html :
<template>
<email>
<contacts_email_email_template translate="label" module="contacts">
<label>Contact Form</label>
<file>contact_form.html</file>
<type>text</type>
</contacts_email_email_template>
</email>
</template>
So if you go and edit app/locale/en_US/template/email/contact_form.html that I reproduced here below and in which I added your product url value, that should work :
<!--#subject Contact Form#-->
<!--#vars
{"var data.name":"Sender Name",
"var data.email":"Sender Email",
"var data.telephone":"Sender Telephone",
"var data.comment":"Comment"}
#-->
Name: {{var data.name}}
Email: {{var data.email}}
Telephone: {{var data.telephone}}
Comment: {{var data.comment}}
<!-- this below line is actually what you are after -->
Product URL : {{var data.producturl}}
data, actually being the key of the array you are passing as the fifth argument of the function sendTransactional
Well if you wish add the product URL to the email you first need to get the product key and wrap it around the static getUrl function.
Mage::getUrl($_product->getUrlKey())
Next just assign the above code to a variable and use some jQuery / Javascript to append the url to the end of the content of the message body. Honestly I would not recommend you to do this.