a [href] not working in phpmailer - yii

I have used phpmailer as the library for sending email using YiiMail extension. I have use layout that contains several text including the link such as Test
But when I include that link My Email status is sending success but I don't get any email coming.
When I not included Email it successfully sent.
What the problems I got? Anyone can help
[Edited]
This is my code and I have tested that it return true
$link=Yii::app()->createAbsoluteUrl('user/resetpassword',array('h'=>$this->Hash));
$message='<div style="clear:both"></div>
<h2 style="float:none">Reset Password - Lawang Code</h2>
<div class="hr biru"></div>
<p>
Seseorang telah berusaha untuk mereset password anda <br/>
Jika memang aksi ini benar silahkan ikuti tautan berikut ini <hr/>
<div style="margin:0 auto;width:200px">
<a style="display:block;width:100px;background:#09C;color:white;padding:10px;text-decoration:none" href="'.$link.'">Reset Password</a>
</div>
</p>';
$mail = new YiiMailer('notification', array(
'judul' => "Reset Password - Lawang Code",
'pesan'=>'Seseorang telah berusaha untuk mereset password anda <br/>
Jika memang aksi ini benar silahkan ikuti tautan berikut ini <hr/>',
'link'=>$link,
'linkLabel'=>"Reset Password",
));
//render HTML mail, layout is set from config file or with $mail->setLayout('layoutName')
$mail->render();
$from=Yii::app()->params->adminEmail;
//set properties as usually with PHPMailer
$mail->From = trim($from);
$mail->FromName = "Lawang Code";
$mail->Subject = "Aksi Reset Password - Lawang Code";
$mail->AddAddress(trim($this->Email));
//send
if ($mail->Send()) {
$mail->ClearAddresses();
return true;
//echo 'Success.';
} else {
//echo 'Error while sending email: '.$mail->ErrorInfo;
return false;
}
It has

Try to enable IsHTML by passing true
$mailer->IsHTML(true);
check this https://stackoverflow.com/a/5686798/829533

Related

Empty post value : CodeIgniter

While uploading the file through codeigniter, I am getting the following error:
My file upload result is:
My Controller function is below:
public function Upload files($data='')
{
ini_set("display_errors",1); // I added so it would help me show errors
error_reporting(E_ALL);
print_r($_POST);exit('I am in the tp');
$config['upload_path'] = 'assets/images/uploads/';
//$config['allowed_types'] = 'gif|jpg|png';
//$config['max_size'] = 100;
//$config['max_width'] = 1024;
//$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);exit('The first loop');
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
print_r($data);exit();
$this->load->view('upload_success', $data);
}
}
And my view file:
<div id="Upload_div">
<?php //echo $error;?>
<form action="<?php echo site_url() ?>/Admin/Upload_files/" method="POST" enctype="multipart/form-data">
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="userfile"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</div>
Can anyone help me figure out why post value is empty?
Thanks
$_POST does not contain any file data.
Remove the line
print_r($_POST);exit('I am in the tp');
And then tell us what happens.

Joomla 3.3 MVC file/pdf upload in custom component backend

I want to upload a pdf from a custom component from backend in the edit mode.
the state now is,
1.- either the pdf is uploaded correctly but the file name is not written in the database,
2.- or the file name is written in the data base, but the pdf is not seen by JFactory::getApplication()->input;
I found out is has with enctype="multipart/form-data" to do.
In case 1.- enctype="multipart/form-data" is in and the pdf is uploaded
in case 2.- the pdf file name is written in the data base.
What to do know ? I need both, of course.
Here so code, it is a little component com_job with MVC structure under Joomla! 3.3:
here just the part file administrator/components/com_job/views/tmpl/edit.php
with the enctype="multipart/form-data"
<form method="post" action="<?php echo JRoute::_('index.php?option=com_job&layout=edit&id='.(int) $this->item->id); ?>" id="adminForm" name="adminForm" enctype="multipart/form-data">
<fieldset class="adminform">
<legend><?php echo JText::_( 'Details' ); ?></legend>
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('title'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('title'); ?>
</div>
</div>
....
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('upload_pdf'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('upload_pdf'); ?>
</div>
</div>
........
here a part of the xml file administrator/components/com_job/models/forms/job.xml
<?xml version="1.0" encoding="utf-8"?>
...
<field
id="title"
name="title"
type="text"
required="true"
label="Title"
description="title_Desc"
class="inputbox"
size="40"/>
<field
id="upload_pdf"
name="upload_pdf"
type="file"
required="false"
label="Upload_pdf"
description="upload_pdf_Desc"
class="inputbox"
size="40"
accept="application/pdf"/>
.....
here the controller administrator/components/com_job/controllers/job.php
jimport('joomla.application.component.controlleradmin');
jimport('joomla.application.component.controllerform');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
class JobControllerJob extends JControllerForm
{
public function save()
{
$jinput = JFactory::getApplication()->input;
$files = $jinput->files->get('jform', null);
$files['upload_pdf']['name'] = JFile::makeSafe($files['upload_pdf']['name']);
if (!empty($files['upload_pdf']['name'])) {
$pdf_path = JPATH_ROOT . '/images/upload_pdf';
if (!JFolder::exists($pdf_path)) {
$status = JFolder::create($pdf_path);
if (!$status) {
JError::raiseWarning(100, JText::_('could not create directory pdf'), '');
}
}
$file_path = JPath::clean($pdf_path . '/' . strtolower($files['upload_pdf']['name']));
$status = JFile::upload($files['upload_pdf']['tmp_name'], $file_path);
if (!$status) {
JError::raiseWarning(100, JText::_('could not copy pdf'), '');
}
}
return parent::save();
}
}
where is the error ? I tried to put enctype="multipart/form-data" in the form in job.xml (models), but it didn't work.
I found a temporally solution, in the save function in the controller, I add this code:
//$jform = $jinput->get(jform, null);
$pdf_filename = JFile::makeSafe($files['upload_pdf']['name']);
$jform = $_POST['jform'];
$tmp_pdf_filename = array('upload_pdf' => $pdf_filename);
$merged_jform = array_merge($jform,$tmp_pdf_filename);
$jinput->post->set('jform',$merged_jform);
the first line with $jinput didn't work. I tried many ways with $jinput, but nothing worked. So finally I used directly $_POST. Of course, it is not the right way, but at least it works.
here the full function save:
public function save()
{
$jinput = JFactory::getApplication()->input;
$files = $jinput->files->get('jform', null);
$pdf_filename = JFile::makeSafe($files['upload_pdf']['name']);
if (!empty($pdf_filename)) {
$pdf_path = JPATH_ROOT . '/images/upload_pdf';
if (!JFolder::exists($pdf_path)) {
$status = JFolder::create($pdf_path);
if (!$status) {
JError::raiseWarning(100, JText::_('could not create directory pdf'), '');
}
}
$file_path = JPath::clean($pdf_path . '/' . strtolower($files['upload_pdf']['name']));
$status = JFile::upload($files['upload_pdf']['tmp_name'], $file_path);
if ($status) {
//$jform = $jinput->get(jform, null);
$jform = $_POST['jform'];
$tmp_pdf_filename = array('upload_pdf' => $pdf_filename);
$merged_jform = array_merge($jform,$tmp_pdf_filename);
$jinput->post->set('jform',$merged_jform);
} else {
JError::raiseWarning(100, JText::_('could not copy pdf'), '');
}
}
return parent::save();
}
$jinput = JFactory::getApplication()->input;
$files = $jinput->files->get('jform');
$file = $files['upload_pdf'];
Try this...it is true method!!!
That should do the trick. The $file array then holds the following keys:
error
name
size
tmp_name
type

Unable to alert before redirecting to another php script using header()

I was trying to create a dummy social networking site for practice. I'm stuck in a script which is sending friend request..
i've created a form(with a single text input, a hidden input and submit button) in which a logged in user can enter email address of a friend. When he clicks on the search button, he gets name and email of his friend(fetched using sql)..
With that i have added an anchor tag(named as Send request) displayed near the details. When a user clicks on the anchor tag, he is redirected to a new script which sends friend request to his friend. The second script only deals with mysql.
On sql completion, a user either gets "Friend Request Sent Successfully" alertbox or "Friend Request Already Sent" alertbox based on sql queries. Now i want to redirect the user to the first script after the execution of alertbox.
I tried to use header("Location: send_request.php") after the alertbox. But now it is redirecting user to the first script without showing alertbox.
Here is my first script(named as find_friends.php)
<?php
if(isset($_SESSION)) session_start();
require('header.php');
echo "<form method='POST' action=''>";
echo "<input type='text' name='search_user'/>";
echo "<input type='hidden' name='search_form_status' value='sent'/>";
echo "<input type='submit' value='Search User'/>";
echo "</form>";
if(isset($_POST['search_form_status']) && $_POST['search_form_status']=='sent'){
$search_user = $_POST['search_user'];
$sql_search_user = "SELECT id, name, email FROM registration where email=\"$search_user\"";
$query_search_user = mysql_query($sql_search_user);
$user_check = mysql_num_rows($query_search_user);
if($user_check==1){
$results_search_user = mysql_fetch_assoc($query_search_user);
echo $_SESSION['searched_id'] = $results_search_user['id'];
echo $_SESSION['searched_name'] = $results_search_user['name']."<br/>";
echo $_SESSION['searched_email'] = $results_search_user['email'];
echo "</br/><a href='send_request.php'>Send Request</a>";
}
}
?>
And here is second script(named as send_request.php)
<?php
$db1 = mysql_connect("localhost", "root", "");
mysql_select_db("test", $db1);
$db2 = mysql_connect("localhost", "root", "", true);
mysql_select_db("friends", $db2);
if(!isset($_SESSION)) session_start();
$searched_email = $_SESSION['searched_email'];
$searched_id = $_SESSION['searched_id'];
$user_name = $_SESSION['name'];
$user_email = $_SESSION['email'];
$sql_table_check = "SHOW TABLES LIKE 'friends_".$searched_id."'";
$table_check = mysql_num_rows(mysql_query($sql_table_check, $db2));
if($table_check==1){
$sql_insert_values = "INSERT INTO friends_".$searched_id." VALUES(\"\", \"$user_name\", \"$user_email\", 0)";
if(mysql_query($sql_insert_values)){
echo "<script>alert('Friends Request Sent Successfully')</script>";
header("Location: find_friends.php");
}
else{
echo "<script>alert('Friends Request Already Sent')</script>";
header("Location: find_friends.php");
}
}else{
$sql_create_table = "CREATE TABLE friends_".$searched_id." (friend_id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, friend_name VARCHAR(30) NOT NULL, friend_email VARCHAR(50) NOT NULL UNIQUE, active TINYINT NOT NULL)";
$sql_insert_values = "INSERT INTO friends_".$searched_id." VALUES(\"\", \"$user_name\", \"$user_email\", 0)";
mysql_query($sql_create_table, $db2);
if(mysql_query($sql_insert_values, $db2)){
echo "<script>alert('Friends Request Sent Successfully')</script>";
}
}
?>
Try this:
if(mysql_query($sql_insert_values)){
echo "<script>
alert('Friends Request Sent Successfully');
window.location.href='find_friends.php';
</script>";
}

How to get file tmp_name using JInput

I'm a bit stuck with this. I have this bit of code which manages to get the filename of my file:
class AControllerA extends JControllerForm
{
function save()
{
//Upload file
jimport('joomla.filesystem.file');
$jinput = JFactory::getApplication()->input;
$store_form = $jinput->get('jform', null, 'array');
$file = $store_form['img_url'];
echo $file;
}
}
*The file field has a name of jform[img_url];
However I cannot seem to get the 'tmp_name' for the file. Anyone know what I'm missing out? I'm a bit confused as to how jinput works...jrequest worked quite easily. Thanks!
models/forms/a.xml
<form enctype="multipart/form-data">
<fieldset>
<field
name="img_url"
type="file"
label=""
description=""
size="40"
class="inputbox"
default=""
/>
</fieldset>
</form>
How about like this:
$files = $input->files->get('jform', null);
$filename = $files['img_url']['tmp_name'];
echo $filename;
Check out documentation for Retrieving file data using JInput
Supposing you are using JForm and the file input type, then you can access the file using this:
$files = $jinput->files->get('jform');
$file = $files['img_url']['tmp_name']
Also make sure your form has the enctype="multipart/form-data" set, otherwise it will not work.
In your model you should have sth like this
public function getForm($data = array(), $loadData = false)
{
/**
* Get the Form
*/
$form = $this->loadForm('com_mycomponent.mycomponent', 'mycomponent',
array('control' => false, 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
Note that $loaddata and 'control' is set to false, when 'control' is false you can get file parameters as according to the name specified in your xml i.e the output form is like:
<input name="name in xml file" type="file" />
If 'control' => 'jform'
<input name="jform[name in xml file]" type="file" />
$loaddata= false means you dont need to fetch any data from the database to the form.
in your view.html.php you should have sth like this
public function display($tpl = null)
{
$this->formData = $this->get('Form');
$this->addToolbar();
parent::display($tpl);
}
Lets suppose I'll receive the requested file in "upload" method of "mycomponent" controller then it should have sth like this:
class MycomponentControllerMycomponent extends JControllerAdmin
{
public function upload()
{
//Retrieve file details from uploaded file, sent from upload form
$file = JFactory::getApplication()->input->files->get('name in xml
**$tmp_name** = $file['tmp_name'];
}
}
$tmp_name is Your required name

vBulletin 4.x External Page Login and Variables

I've been searching around and experimenting with this for hours, with no success.
I'm trying to login to vBulletin from an external page. I've managed to get this to work. However what I can't get to work is showing the username and any of the $vbulletin variables.
I've included global.php chdir() to the forum etc etc, but I just can't get it to work.
Does anyone know how to go about this?
This is working example i'm using it. Its working fine. Its show user name and logout button on External page.
I don't know why -vote it.
<?php
$curdir = getcwd();
#Add your root dir below where it says "ADD ROOT" Example: /home/server/public_html/mainsite/forums
#Do not end with a "/" leave it open like above example.
chdir('ADD ROOT');
require_once('ADD ROOT/global.php');
chdir($curdir);
if ($vbulletin->userinfo['userid'] == 0) {
#Form Display Code, You can edit the way the Form is layed out here.
echo "<form id=\"login\" action=\"/forums/login.php?do=login\" method=\"post\" onsubmit=\"md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)\">
<script type=\"text/javascript\" src=\"clientscript/vbulletin_md5.js?v=364\"></script>
Register
<label for=\"navbar_username\">Username</label>
<input type=\"text\" class=\"bginput\" style=\"font-size: 11px\" name=\"vb_login_username\" id=\"navbar_username\" size=\"10\" accesskey=\"u\" tabindex=\"101\" onfocus=\"if (this.value == 'User Name') this.value = '';\" />
<label for=\"navbar_password\">Password</label>
<input type=\"password\" class=\"bginput\" style=\"font-size: 11px\" name=\"vb_login_password\" id=\"navbar_password\" size=\"10\" tabindex=\"102\" />
<label for=\"cb_cookieuser_navbar\"><input type=\"checkbox\" name=\"cookieuser\" value=\"1\" tabindex=\"103\" id=\"cb_cookieuser_navbar\" accesskey=\"c\" />Remember Me?</label>
<input type=\"submit\" class=\"button\" value=\"Login\" tabindex=\"104\" title=\"Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself.\" accesskey=\"s\" />
<input type=\"hidden\" name=\"s\" value=\"\" />
<input type=\"hidden\" name=\"do\" value=\"login\" />
<input type=\"hidden\" name=\"vb_login_md5password\" />
<input type=\"hidden\" name=\"vb_login_md5password_utf\" />
</form>";
#End Form Display Code
} else {
#Display after login completed
echo "Welcome Back, <b>".$vbulletin->userinfo['username']."</b>";
if ($vbulletin->userinfo['usergroupid'] == '6' ) {
echo " | My Profile";
echo " | AdminCP";
echo " | ModCP";
}
}
?>