I am setting up a forgotten password and reset form. When I send my email. I have 2 issues. One is the unique code is not showing up in URL on when click on link. And the other issue I am having it says Message: Undefined variable: message.
Everything else works fine but just the code not showing up in URL and $message error.
Why is it not picking up my $code in URL. And having error $message?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Forgotten extends MX_Controller {
private $error = array();
public function __construct() {
parent::__construct();
if ($this->user->hasPermissionAccess() == TRUE) {
$this->lang->load('admin/english', 'english');
$this->lang->load('admin/common/forgotten', 'english');
$this->load->library('settings');
$this->load->library('pagination');
$this->load->library('request');
$this->load->library('response');
$this->load->library('document');
} else {
redirect('admin/error');
}
}
public function index() {
$this->document->setTitle($this->lang->line('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->load->library('email');
$config['protocol'] = 'smpt';
$config['smpt_host'] = 'ssl://squid.arvixe.com';
$config['smpt_port'] = '465';
$config['smpt_user'] = '********'; // Username Blanked Out For Security
$config['smpt_password'] = '******'; // Password Blanked Out For Security
$this->email->initialize($config);
$this->email->from($config['smpt_user']);
$this->email->to($this->request->post['email']);
$subject = sprintf($this->lang->line('text_subject'), $this->settings->get('config_name'));
$this->email->subject($subject);
$code = sha1(uniqid(mt_rand(), true));
$this->load->model('admin/user/users_model');
$this->users_model->editCode($this->request->post['email'], $code);
$message .= sprintf($this->lang->line('text_greeting'), $this->settings->get('config_name')) . "\n\n";
$message .= $this->lang->line('text_change') . "\n\n";
$code = sha1(uniqid(mt_rand(), true));
$message .= site_url('admin/reset/', $code) . "\n\n";
$message .= sprintf($this->lang->line('text_ip'), $this->request->server['REMOTE_ADDR']) . "\n\n";
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => '<i class="fa fa-home"></i>' .' '. $this->lang->line('text_home'),
'href' => site_url('common/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('common/forgotten')
);
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['action'] = site_url('admin/forgotten');
$data['cancel'] = site_url('admin');
$data['heading_title'] = $this->lang->line('heading_title');
$data['text_your_email'] = $this->lang->line('text_your_email');
$data['text_email'] = $this->lang->line('text_email');
$data['entry_email'] = $this->lang->line('entry_email');
$data['button_reset'] = $this->lang->line('button_reset');
$data['button_cancel'] = $this->lang->line('button_cancel');
return $this->load->view('common/forgotten', $data);
}
public function validate() {
$this->load->model('admin/user/users_model');
if (!isset($this->request->post['email'])) {
$this->error['warning'] = $this->lang->line('error_email');
} elseif (!$this->users_model->getTotalUsersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->lang->line('error_email');
}
return !$this->error;
}
}
Found issue where the first $message . was it should just be $message no full stop. And for code problem I changed the site_url to base.
$message = sprintf($this->lang->line('text_greeting'), $this->settings->get('config_name')) . "\n\n";
$message .= $this->lang->line('text_change') . "\n\n";
$code = sha1(uniqid(mt_rand(), true));
$message .= base_url('admin/reset') . '/' . $code . "\n\n";
$message .= sprintf($this->lang->line('text_ip'), $this->request->server['REMOTE_ADDR']) . "\n\n";
$this->email->message($message);
Related
I have Yii2 project. And there I also have api written by Symfony.
In Symfony part I have method in the class which send request to Yii controller.
$buzz = $this->container->get('buzz');
$buzz->getClient()->setVerifyHost(false);
$buzz->getClient()->setVerifyPeer(false);
$buzz->getClient()->setTimeOut(false);
$url = $this->container->getParameter('integra_sync_prices');
$sendResult = $buzz->post($url, array('authorization' => $this->container->getParameter('load_token')), array('products' =>
json_encode($productPrices)));
$resultJson = json_decode($sendResult->getContent(), true);
if (isset($resultJson['error']))
throw new \Exception('Site: '.$resultJson['error'], 500);
class IntegraController extends Controller{
public function actionIndex()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$headers = Yii::$app->request->getHeaders();
foreach ($headers as $key => $value) {
if(strtolower(trim($key)) == 'authorization') {
$token = trim($value[0]);
break;
}
}
$products = json_decode(Yii::$app->request->post('products'));
$post_products = Yii::$app->request->post('products');
if('111' == $token) {
if(isset($post_products) && $products) {
foreach ($products as $product) {
echo $product->price." = ".$product->productId."<br>";
Yii::$app->db->createCommand("UPDATE oc_product SET quantity = '" . (int)$product->quantity . "', price = '" . (float)$product->price . "' WHERE product_id = '" . (int)$product->productId . "'")->execute();
}
$json['success'] = 'complete';
} else {
$json['error'] = 'empty data';
}
} else {
$json['error'] = 'authorization error';
}
Yii::$app->controller->enableCsrfValidation = false;
echo json_encode($json);
}
I expect that data in my database will be updated by this controller. But there in nothing changes.
What do I do wrong? Maybe I should send some another headers? Thanks a lot )
I have uploaded a cv successfully from a career page . Now i want to send this in email.
Upload part
if ($_FILES['filecv']['name'] != "") {
$sqldata['att_ment'] = uploadCVFile($_FILES['filecv']);
} else {
$sqldata['att_ment'] = '';
}
CV is uploaded successfully.
uploadCVFile function
function uploadCVFile($uploadedfile)
{
if (!function_exists('wp_handle_upload'))
require_once (ABSPATH . 'wp-admin/includes/file.php');
$upload_overrides = array('test_form' => false);
add_filter('upload_dir', 'cv_uploads_dir');
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
remove_filter('upload_dir', 'cv_uploads_dir');
if ($movefile) {
return basename($movefile['file']); //$uploadedfile['name'];
} else {
return "";
}
}
path set
function cv_uploads_dir($param)
{
$param['subdir'] = '/cvs';
$param['path'] = $param['basedir'] . $param['subdir'];
$param['url'] = $param['baseurl'] . $param['subdir'];
return $param;
}
now i want to send this in email using the wp_mail function. all other data is sent successfully but i dont know how to deal with the cv.
Mail function
function SendCareers_Email($pst)
{
$to = get_option('career_email');
$from = $pst['e-mail'];
$name = $pst['firstname'];
$cvname="/uploads/cvs/".$sqldata['att_ment'];
$subject = "Applying for the job " . $pst['title'];
$message= "Candidate Name:-" . $name . "<br/>";
$message .= "Job Title Applied:-" . $pst['title'] . "<br/>";
if(!empty($pst['country'])){
$message .= "Country Of Resindency:-" . $pst['country'] . "<br/>";
}
if(!empty($pst['nationlaity'])){
$message .= "Nationlaity:-" . $pst['nationlaity'] . "<br/>";
}
$attachments = array( WP_CONTENT_DIR . $cvname );
if(!empty($pst['mobileno'])){
$message .= "Phone Number:-" . $pst['mobileno'] . "<br/>";
}
add_filter('wp_mail_content_type', 'set_career_html_content_type');
$admin_headers = 'From: '.$name.' <'.$from .'>' . "\r\n\\";
wp_mail($to, $subject,$message , $admin_headers,$attachments);
remove_filter('wp_mail_content_type', 'set_career_html_content_type');
}
function set_career_html_content_type()
{
return 'text/html';
}
In your SendCareersEmail function change this part
$cvname="/uploads/cvs/".$_FILES['filecv']['name'];
$attachments = array(
$cvname
);
When inside a function only global variables or variables you pass into the function (in your case $pst) are available. So either pass in $sqldata to the function SendCVEmail($pst, $sqldata) or use the global call of $_FILES['filecv']['name']
I'm getting this error when trying to post from an AngularJS control to a PHP page to process. The object looks fine, but it keeps giving this error:
TypeError: Cannot read property 'protocol' of undefined
at urlIsSameOrigin (angular.js:17714)
at sendReq (angular.js:10225)
at serverRequest (angular.js:9944)
at processQueue (angular.js:14454)
at angular.js:14470
at Scope.$eval (angular.js:15719)
at Scope.$digest (angular.js:15530)
at Scope.$apply (angular.js:15824)
at HTMLFormElement.<anonymous> (jcs-auto-validate.min.js:6)
at HTMLFormElement.eventHandler (angular.js:3247)
Here is the code for the controller:
(function () {
angular
.module('contactApp')
.controller('FormCtrl', FormCtrl);
function FormCtrl ($http) {
/* jshint validthis: true */
var vm = this;
vm.formModel = {};
vm.success = false;
vm.error = false;
vm.onSubmit = function () {
console.log("I'm submitted");
console.log(vm.formModel);
$http({
method : 'POST',
URL : '/formProcess.php',
data : {
'name':vm.formModel.name,
'phoneNumber':vm.formModel.phoneNumber,
'email':vm.formModel.email,
'streetAddress':vm.formModel.streetAddress,
'cityStateZip':vm.formModel.cityStateZip,
'bedrooms':vm.formModel.bedrooms,
'bath':vm.formModel.baths,
'reason':vm.formModel.reason
},
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success(function(data, status, headers, config) {
vm.resultData = data;
alert("Message sent successfully. We'll get in touch with you soon.");
}).error(function(data, status, headers, config) {
vm.resultData = data;
alert("Sending message failed.");
});
/*.success( function(data, status, headers, config) {
if ( data.success ) {
vm.success = true;
console.log('happy');
} else {
vm.error = true;
console.log('sad');
}
});*/
}
}
FormCtrl.$inject = ['$http'];
})();
and for the PHP to send the email:
<?php
// ===========================================
// Define custom variables
// ===========================================
$emailTo = '---.com';
$nameTo = 'test';
$subject = 'test';
// ===========================================
// Validate and send email
// ===========================================
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$response = array( 'success' => false );
$formData = file_get_contents( 'php://input' );
$data = json_decode( $formData );
/*if ( $data->submit ) {*/
$name = $data->name;
$phoneNumber = $data->phoneNumber;
$email = $data->email;
$streetAddress = $data->streetAddress;
$cityStateZip = $data->cityStateZip;
$bedrooms = $data->bedrooms;
$baths = $data->baths;
$reason = $data->reason;
//check if any of the inputs are empty
if ( $name != '' && $phoneNumber != '' && $email != '' && $streetAddress != '' && $cityStateZip != '' && $bedrooms != '' && $baths != '' && $reason != '' ) {
$body = 'From: ' . $name . '\n';
$body .= 'Email: ' . $email . '\n';
$body .= 'Phone Number: ' . $phoneNumber . '\n';
$body .= 'Street Address: ' . $streetAddress . '\n';
$body .= 'City, State and Zip: ' . $cityStateZip . '\n';
$body .= 'Number of Bedrooms: ' . $bedrooms . '\n';
$body .= 'Number of Baths: ' . $baths . '\n';
$body .= 'Reason for Selling:\n ' . $reason . '\n\n';
$headers = 'From: '. $nameTo.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$success = mail($emailTo, $subject, $body, $headers);
if ( $success ) {
$response[ 'success' ] = true;
}
}
/*}*/
}
echo json_encode( $response );
?>
Any thoughts as to what I might be missing here?
Thanks!
I am having problems sending emails using the PHPMailer class for my registration form. I was wondering if the below code could be changed into a normal Mail class please.
<?php
require_once('PHPMailer_v5.1/PHPMailer.php');
class Email {
public $objUrl;
private $objMailer;
public function __construct($objUrl = null) {
$this->objUrl = is_object($objUrl) ? $objUrl : new Url();
$this->objMailer = new PHPMailer();
$this->objMailer->IsSMTP();
$this->objMailer->SMTPAuth = true;
$this->objMailer->SMTPKeepAlive = true;
$this->objMailer->SMTPSecure = 'ssl';
$this->objMailer->Host = "smtp.gmail.com";
$this->objMailer->Port = 465;
$this->objMailer->Username = "email here";
$this->objMailer->Password = "password here";
$this->objMailer->SetFrom("email here", "name here");
$this->objMailer->AddReplyTo("email here ", "name here");
}
public function process($case = null, $array = null) {
if (!empty($case)) {
switch($case) {
case 1:
// add url to the array
$link = "<a href=\"";
$link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
$link .= "\">";
$link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
$link .= "</a>";
$array['link'] = $link;
$this->objMailer->Subject = "Activate your account";
$this->objMailer->MsgHTML($this->fetchEmail($case, $array));
$this->objMailer->AddAddress(
$array['email'],
$array['first_name'].' '.$array['last_name']
);
break;
}
// send email
if ($this->objMailer->Send()) {
$this->objMailer->ClearAddresses();
return true;
}
return false;
}
}
public function fetchEmail($case = null, $array = null) {
if (!empty($case)) {
if (!empty($array)) {
foreach($array as $key => $value) {
${$key} = $value;
}
}
ob_start();
require_once(EMAILS_PATH.DS.$case.".php");
$out = ob_get_clean();
return $this->wrapEmail($out);
}
}
public function wrapEmail($content = null) {
if (!empty($content)) {
return "<div style=\"font-family:Arial,Verdana,Sans-serif;font-size:12px;color:#333;line-height:21px;\">{$content}</div>";
}
}
}
Any help is much appreciated
Thanks
I have tried to amend the code to the below code but all I get is a blank screen. I have checked on firefox and no error messages are displayed. Can anyone help fix the problem.
Thank you
<?php
//require_once('PHPMailer_v5.1/PHPMailer.php');
class Email {
public $objUrl;
//private $objMailer;
public function __construct($objUrl = null) {
$this->objUrl = is_object($objUrl) ? $objUrl : new Url();
$to = "qakbar26#gmail.com";
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: qakbar26#gmail.com";
}
public function process($case = null, $array = null) {
if (!empty($case)) {
switch($case) {
case 1:
// add url to the array
$link = "<a href=\"";
$link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
$link .= "\">";
$link .= SITE_URL.$this->objUrl->href('activate', array('code', $array['hash']));
$link .= "</a>";
$array['link'] = $link;
$subject = "Activate your account";
$message($this->fetchEmail($case, $array));
$address(
$array['email'],
$array['first_name'].' '.$array['last_name']
);
break;
}
// send email
if ($send()) {
$this->ClearAddresses();
return true;
}
return false;
}
}
public function fetchEmail($case = null, $array = null) {
if (!empty($case)) {
if (!empty($array)) {
foreach($array as $key => $value) {
${$key} = $value;
}
}
ob_start();
require_once(EMAILS_PATH.DS.$case.".php");
$out = ob_get_clean();
return $this->wrapEmail($out);
}
}
public function wrapEmail($content = null) {
if (!empty($content)) {
return "<div style=\"font-family:Arial,Verdana,Sans-serif;font-size:12px;color:#333;line-height:21px;\">{$content}</div>";
}
}
}
Just an update I have manged to get the PHPMailer ot work after I commented out the below line of code.
$this->objMailer->IsSMTP();
Not sure why but the IsSMTP(); is not letting the emails go through.
I have this form where I wan't people to sign up for receiving free stuff campaign. The form works fine and its send the details to the requested eMail.
Now this form should also write the details to a csv file that we can handle the data more easily.
I use this form:
$value) {
${"".$key} = $value;
}
if (!isset($email)) {
header( "Location: $formurl" );
exit;
}
if ($_POST['services']) {
foreach($_POST['services'] as $value) {
$check_msg .= "- $value\n";
}
}
function is_email($email) {
return ereg("^[^# ]+#[^#]+\.[^# ]+$", $email);
}
function validate_email($email) {
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*#([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("#",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
$formurl = "/sticker/index.php" ;
$errorurl1 = "/sticker/error.php" ;
$errorurl2 = "/sticker/error.php" ;
$thankyouurl = "/sticker/success.php#start" ;
$http_referrer = getenv( "HTTP_REFERER" );
// get POST && GET vars to run with 'register_globals off'
//foreach($_GET AS $key => $value) {
// ${"".$key} = $value;
//}
$messageproper =
"============================================================\n" .
"Sticker Request $firstname $lastname\n" .
"============================================================\n\n" .
"KUNDENDATEN\n\n" .
"Vorname: $firstname\n" .
"Nachname: $lastname\n" .
"Firma: $company\n" .
"Strasse: $street\n" .
"Strasse2: $street2\n" .
"PLZ: $zip\n" .
"City: $city\n" .
"Land: $country\n\n" .
"Telefon: $phone\n" .
"eMail: $email\n" .
"Facebook Name: $fbname\n\n" .
"--------------------------------------\n\n" .
"Bemerkung: $comment\n\n" .
"============================================================\n\n" ;
$myFile = "/sticker/sticker.txt";
$fh = fopen($myFile, 'a');
$stringData = "\r\n";
$x=0;
foreach($_POST AS $key => $value) {
$x!=0?$stringData=",".$stringData:'';
$stringData='"'.$firstname.'";"'.$lastname.'";"'.$company.'";"'.$street.'";"'.$street2.'";"'.$zip.'";"'.$city.'";"'.$country.'";"'.$phone.'";"'.$email.'";"'.$fbname.'";"'.$comment.'"'."\r\n";
$x++;
}
fwrite($fh, $stringData);
fclose($fh);
$mailto = 'email#domain.com' ;
$subject = "Free Sticker Campaign: $company - $firstname $lastname";
mail($mailto, $subject, $messageproper, "From: \"$firstname $lastname\" <$email>\nReply-To: \"$lastname\" <$email>\nX-Mailer: chfeedback.php 2.01" );
header( "Location: $thankyouurl" );
exit;
?>
As I said nothing gets written to the CSV File I declared in $myFile.
Would be great if someone could let me know what to do.
Thanks.