Joomla routing engine - joomla

I have written a custom landing page that I want to incorporate to my website.
the website is using Joomla as a CMS.
so when I type a UTL www.mysite.com/myLandingPahe.php i get a 404 becuse the Joomla ruting engine kiks in and searches for the article in the DB..
this is the skeleton of the landing page (basic contac form):
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
can I reserve an address to point to my custom PHP file ?
Is there another way that this can be achieved ?

You have options,
Use com_contact with Overrides
copy the entire the components/com_contact/view/ to your templates/your_templates/html/com_contact/.
Then add your custom styles with following methods inside your view page
$doc = JFactory::getDocument();
$doc->addScript('js file full path');
$doc->addStyleSheet('css path');
It will load your custom styles Then you have to avoid header and footer for feeling it as a different page. this can be achieved by using appending tmpl=component with the url .
like your contact url is www.yourdomain.com/contact&tmpl=component.
Custom Page with Article
create an article page with any name and set the alias with required url. then add the form and its required CSS within the article content. Here you required some plugin for including styles and script inside your article content like this.
Then in your form action will be like follows.
<form action = "index.php?option=com_contact&task=contact.contactinfo">...</form>
This stands for inside your components/com_contact/controllers/contact.php have a function with contactinfo() when the form submit you will get all the post data inside this function.
for retrieving form data use Joomla default library like
$jinput = JFactory::getApplication()->input;
$name = $jinput->get('name', 'default_value', 'filter');
Also for sending email you can use.
$mail = JFactory::getMailer();
$mail->addRecipient($contact->email_to);
$mail->addReplyTo(array($email, $name));
$mail->setSender(array($mailfrom, $fromname));
$mail->setSubject($sitename.': '.$subject);
$mail->setBody($body);
$sent = $mail->Send();
after sending you can redirect back to the page with .
$this->setRedirect('url','message success/failed','type of message eg: error,info');
after setting this you can just append &tmpl=component like above for avoiding header and footer
Hope it make sense..

Related

Send single email according to Weblesson

I'm new to programming, currently searching for ways to only send a single email like what Web lesson had taught me (bulk email I don't want), here is the link:'How to Send Bulk Email in PHP using PHPMailer with Ajax JQuery'.
I have two places to run this function, one is index.blade.php, and one is ClientController.
index.blade.php
<form action="{{ route('clients.destroy',$client->id) }}" method="POST">
<a href="{{ route('clients.edit',$client->id) }}">
<i class="fas fa-pencil-alt"></i>
</a>
<button type="button" name="email_button" class="email_button"
id="{{ $client->_id }}"
method="post" action="single" email_data="{{ $client->email }}">
<i class="fas fa-envelope"></i>
</button>
#csrf
#method('DELETE')
<button type="submit"><i class="far fa-trash-alt"></i></button>
</form>
here's my JQuery and Ajax at the bottom of index.blade.php
<script>
$(document).ready(function(){
$('.email_button').click(function(){
$(this).attr('disabled', 'disabled');
var id = $(this).attr("id");
var action = $(this).data("action");
var email_data = $(this).data("email_data");
$.ajax({
url:'{{ route('send-email-test') }}',
method:'POST',
data:{email_button: email_data, _token: '{{csrf_token()}}'},
beforeSend:function(){
$('#'+id).html('Sending...');
$('#'+id).addClass('uk-text-danger');
},
success:function(data){
if(data = 'ok')
{
$('#'+id).text('Success');
$('#'+id).removeClass('uk-text-danger');
$('#'+id).removeClass('uk-text-info');
$('#'+id).addClass('uk-text-success');
}
else
{
$('#'+id).text(data);
}
$('#'+id).attr('disabled', false);
}
});
});
});
</script>
Here's my route and script
// Here's my script in layout
<script src="{{ asset('js/jquery.min.js') }}" type="text/javascript"></script>
// Here's my route
Route::post('send-email-test','ClientController#send_mail')->name('send-email-test');
After creating the index, I'm trying to use ajax to route to my controller.
ClientController
namespace App\Http\Controllers;
use App\Models\Company\Client\Client;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
class ClientController extends Controller
{
public function send_mail()
{
if(isset($_POST["email_data"]))
{
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
require 'class/class.phpmailer.php';
$output = '';
foreach($_POST['email_data'] as $row)
{
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = '587'; //Initially is 465, doesn't work
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxx#gmail.com';
$mail->Password = 'xxxxxxx';
$mail->SMTPSecure = 'tls'; //Initially is SSL, doesn't work either
$mail->From = 'xxxxxxxx#gmail.com';
$mail->FromName = 'Coverage Giant';
$mail->addAddress($row["email_data"]);
$mail->To($row["email_data"]);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = 'Welcome To Coverage Giant';
$mail->Body = '
<p>Sed at odio sapien. Vivamus efficitur</p>
';
$mail->AltBody = '';
$client_email = $mail->Send();
if($$client_email["code"] == '400')
{
$output .= html_entity_decode($client_email['full_error']);
}
}
if($output == '')
{
echo 'ok';
}
else
{
echo $output;
}
}
}
}
As you can see, I'm doing something opposite from the Web lesson because Webslesson uses index.php and send_mail.php, I'm using index.blade.php and ClientController. Since after applying what Websleeson has shown to me, it doesn't function well, so I reverse the engine a bit, thinking maybe it might work the other way round.
My problem now is, my JQuery and Ajax are functioning correctly, and it's able to route to ClientController from index.blade.php. Still, after routing to the controller, it seems that I can't send a single email using PHPMailer; maybe something is wrong with my controller and PHPMailer?
I was also wondering, is there a better way to send a single email?
BTW, I'm using MongoDB and Laravel. My UI is Uikit instead of Boostrap.
Since you're using Laravel, it is indeed easier to use Laravel's built-in mail classes, but you've got this far with PHPMailer so I'll help you clean this up...
You're loading two different copies of PHPMailer at the same time. This is very likely to cause major problems! class.phpmailer.php is from a very old version that you should not be using. It also looks like you have based your code on a very old PHPMailer example – use the latest ones from the repo.
If you're using composer properly (which you should be given you've set up a Laravel project), you should not need any of those require lines - the autoloader will load the classes for you if you added phpmailer/phpmailer to your composer.json requires, as described in the readme.
Port should be an integer, not a string:
$mail->Port = 465;
There is no To() method; call addAddress to add recipients.
When sending multiple messages in a loop, create the instance outside the loop, and re-use it for each message, remembering to call $mail->clearAddresses(); at the end of each iteration, as shown in the mailing list example.
This is peculiar code, and wrong because send() returns a boolean, not an array:
if($$client_email["code"] == '400')
and it doesn't provide code or full_error properties. You're looking for ErrorInfo, as shown in all the examples.
Overall, always refer to the original docs and examples when using any open source package – making up random stuff and expecting it to work is not going to serve you well.

how to open pdf file to another tab in browser using codeigniter

im making currently making my thesis about a record management of our university secretary.. in which all papers inside the office will be scanned and uploaded in the system.. i am using codeigniter..one of the feature in my system is to view the pdf file in other window of the browser. but my problem is, when i click the title. only blank page will be displayed in the other tab.. can you help me solve this one?? here is my code
controller:
function viewMinutesFile(){
if(isset($_GET['id'])){
$id = $_GET['id'];
$file = $this->minutes_model->getFile($id);
$fp= fopen($file->path, "r");
header("Cache-Control: maxage=1");
header("Pragma: public");
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$file->filename."");
header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");
header('Content-Length:' .filesize($file->path));
ob_clean();
flush();
while (!feof($fp)){
$buff = fread($fp,1024);
print $buff;
}
exit;
}
}
code to open the file: this is my syntax to be clicked by the user so that pdf file will be open in the new tab
File
index.php/admin/viewMinutesFile?
id=" target="_tab">
try this one with a static url. no need any extra words for that.
Show My Pdf
New Update
if its work for you then fetch pdf name from database and put the name in the view like
Show My Pdf
now in the controller
$this->load->helper('download');
if($this->uri->segment(3))
{
$data = file_get_contents('./file_path/'.$this->uri->segment(3));
}
$name = $this->uri->segment(3);
force_download($name, $data);
well, you could add a link to file with target="_blank", like
<a href="<?php echo base_url(). 'your_controller/viewMinutesFile'; ?>" target="_blank">
View Pdf
</a>
and in controller function:
function viewMinutesFile(){
....
$file = $this->minutes_model->getFile($id);
$this->output
->set_content_type('application/pdf')
->set_output(file_get_contents($your_pdf_file));
}
you can try this on your view :
Filename
and on your controller, you can try this, because this is works for me :
function viewfile(){
$fname = $this->uri->segment(3);
$tofile= realpath("uploaddir/".$fname);
header('Content-Type: application/pdf');
readfile($tofile);
}
hope this might help you...
Just create a link to a blank page and use this code in your controller:
public function myPdfPage(){
$url = base_url('assets/your.pdf');
$html = '<iframe src="'.$url.'" style="border:none; width: 100%; height: 100%"></iframe>';
echo $html;
}
Enjoy!
There is no any problem with your code you can open easily on next tab, like other pages only difference you have to change header description and it is make sure on your browser pdf reader add-ons are available, otherwise it will give you option to download.
You may just follow this.
<?php echo form_open_multipart('your_controller/your_function','target="_blank"') ;?>
//other input fields
<?php form_close();?>

How can I add an image to my payment method name on the payment choice section in magento?

I've created a module for a payment method. Since this method is not well-known, I would like to place an image next to the name in the payment block, and link that to our faq.
What's the best way to place that image there ?
Some posts suggested putting the HTML straight into the title of the name; that seems to work, but the name is also used in other places (for example in the admin) and it seems like a hack.
So far the best I came up with was to add some jquery code to inject the html into the onepage checkout page, but I can only make that work if I observe the steps through the carrousel and inject the html after the payment section expands, because magento resets the html for it.
Maybe create a function in your block that returns the name and optionally returns the image.
Here is some pseudocode:
function getName($addImage = 0){
$html = '<span class="my-payment-name">' . $this->getName();
if ($addImage == 1) :
$html = $html . '<img src="' . $this->getImage() . '" />';
endif;
$html = $html . '</span>;
return $thml;
}

Display Cross-domain feed RSS in Wordpress site

I need to display cross-domain feeds-rss (XML format)in my site, but i get a error because ajax cross-domain call are not allowed. I've been told about json-p...anyone knows how to use or have some good tutorial?
Thanks
the simplest way is just to create an widget for wordpress or download some kind of like your requirement.
Because json-p load data in JSON format if you want to get data from JSON format then the given link will help you :
getJSON
ajax
or you can access the rss feed with php like given example :
$xml = 'http://blog.webtech11.com/feed';
$doc = new DOMDocument();
$doc->load($xml);
$item = $doc->getElementsByTagName('item');
//$data = array();
for($i=0; $i<=3; $i++){
$title = $item->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$link = $item->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
echo '<h2>' . $title . '</h2>';
}
in this example i access latest 4 blog entries..
hope this will help you

Add WordPress featured image to RSS feed

I'm setting up an RSS to email campaign in MailChimp using my WordPress RSS Feed, and I want to include the featured image in my MailChimp template.
I've tried using this to add the image, which works, but it simply adds it to the content, which doesn't work for MailChimp section of the RSS code:
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float:left; margin:0 15px 15px 0;' ) ) . '' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
Apparently, MailChimp wants it's "own" unique image element. Here's an example of what they want: http://kb.mailchimp.com/article/how-can-i-format-the-image-content-in-my-rss-to-email-campaigns
but it looks like it's in a different RSS format. Here's what my RSS is outputting: http://pacmissions.org/dev/missions/zimbabwe-2012/feed/
I often have to create custom feeds for MailChimp, and find that a lot of the time I have to make somewhat 'hacky' changes like putting custom values into the limited standard fields that MailChimp supports.
Because of this I like to use the method described at Yoast ( http://yoast.com/custom-rss-feeds-wordpress/ ) to create a page that outputs a custom RSS feed.
There are couple of tweaks to make in order to get the featured image included as a field that MailChimp will recognise.
Firstly, you need to add the Media RSS namespace, which I usually do by adding to the opening <rss> tag:
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
Then in order to include the featured image inside the item:
<?php if(get_the_post_thumbnail()): ?>
<media:content url="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" medium="image" />
<?php endif; ?>
If you need to specify a particular image size to include, you'll need to use this code inside the item instead:
<?php if(get_the_post_thumbnail()): ?>
<media:content url="<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'imageSize'); echo $image[0]; ?>" medium="image" />
<?php endif; ?>
You can then grab this in MailChimp using the *|RSSITEM:IMAGE|* or *|FEEDITEM:IMAGE|* merge tags.
There seem to be plenty of examples of how to add the image to the top of the content in the feed, but not too many where you're creating a new tag. One potential issue is that creating a custom tag or something similar won't be a valid RSS format. If you're creating an XML document for your own usage it doesn't matter so much if the feed validates. Here's what I did, and you should easily be able to modify it slightly for the MailChimp use case.
In functions.php add (inside the theme folder: wp-content/themes/{your-active-theme-folder}):
function insertImageRSS() {
global $post;
preg_match("/(http:\/\/.*(jpg|jpeg|png|gif|tif|bmp))\"/i", get_the_post_thumbnail( $post->ID, 'thumbnail' ), $matches);
return $matches[1];
}
In the wp-includes/feed-rss2.php ( I used the enclosure tag, but haven't yet done the filesize calculation, so I used a placeholder ):
<?php if (get_the_post_thumbnail( $post->ID, 'thumbnail' ) != '') { ?><enclosure <?php echo 'url="' . insertImageRSS() . '"'; ?> length="1000" type="image/jpeg" /><?php } ?>

Resources