Codeigniter: add a signature to my email - codeigniter

I need to add an image signature in my email body, i write the message into a textarea and the variable $message don't send the image, just send text, and when i use an editable div instead textarea, the message get empty, here my code:
//Controller
$destino = $this->load->view("destino");
$asunto = $this->input->post("asunto");
$mensaje = $this->input->post("mensaje");
$this->email->set_newline("\r\n");
$this->email->from('correopruebas#consultora.cl');
$this->email->to($destino);
$this->email->subject($asunto);
$this->email->message($mensaje);
//view message
<div class="col-md-9" style="float: right;">
<textarea id="editor" name="mensaje">
$this->load->view('firma');
</textarea>

I found the way, just need add other variable $message but in the "=" need to add a dot before ".=", and the path of your signature image on the server:
$message .= '<img src=http://path/to_my/signature.png alt="My Firma"> <br>';

Related

unisharp laravel-filemanager Thumbnail url

Hi I'm using unisharp laravel-filemanager for user to upload their products photos
when the image uploaded
this address will save in database
/photos/44/606074649c651.jpg
and I can use it by
{{asset('storage/'.$product->cover_img)}}
and Thumbnail saved in this address
/photos/44/thumbs/606074649c651.jpg
How can I get the address of thumbnail and how can I use it in blade?
This is the answer
#php($lastSlash = strrpos($product->cover_img,"/"))
src="{{asset('storage/'.substr_replace($product->cover_img, 'thumbs/', $lastSlash+1) .'' .substr($product->cover_img ,$lastSlash+1))}}"
One way to save it in the database is to add a hidden type input to the image's thumb, inside the stand-alon-button.js file.
// set or change the preview image src
items.forEach(function (item) {
target_preview.append(
$('<img>').css('height', '5rem').attr('src', item.thumb_url),
$('<input type="hidden" name="thumbnail">').attr('value', item.thumb_url)
);
});
Input:
<div class="input-group">
<span class="input-group-btn">
<a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary">
<i class="fa fa-picture-o"></i> Choose
</a>
</span>
<input id="thumbnail" class="form-control" type="text" name="image">
</div>
<div id="holder" style="margin-top:15px;max-height:100px;"></div>
you can use a function like this:
function getThumbs($url=""){
$base = basename($url);
if (strpos($url, 'https://') !== false or strpos($url, 'http://') !== false) {
return str_replace($base, "thumbs/".$base, $url);
}else{
$preUrl = "storage/";
$beforeBase = str_replace($base, "",$url);
return $preUrl.$beforeBase.'thumbs/'.$base;
}
}
and in your blade use:
<img src="{{ getThumbs($product->cover_img) }}" .../>

How to display contenteditable contents properly? (laravel) (vue)

I have done saved the contents inside the #descrition below.
<div id="description" contenteditable="true"></div>
My problem is when I try to display it does not display like an html format, it displays same like the saved data with <h1></h1> & <br>. It displays plain text only.
<div id="description" contenteditable="true">{{ $description }}</div>
The content I saved in my database & display:
<h1>Descriptoin</h1> Doner, where I built and maintained banner adverts and microsites. <br> And...
Someone know how to display this properly?
Answer: thanks to #Akram Wahid
In laravel - {!! $description !!}
In vue - <div v-html="description"> </div>
You have to do like this , because Blade {{ }} statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks.If you do not want your data to be escaped, you may use the following syntax:
<div id="description" contenteditable="true">{!! $description !!}</div>
By default Laravel escape special characters to prevent XSS attack.
Try using this format:
<div id="description" contenteditable="true">{!! $description !!}</div>

Display Textbox value in paragraph tag

I'm sending mail. I'm getting value from textbox, while i send mail i can't get it as paragraph.
For Example:
Textbox value = Hi
I'm Laravel
But in mail inbox = Hi I'm Laravel
Getting Value in Blade:
<textarea style="width: 100%;" name="message" cols="40" rows="10" required></textarea>
In Mail Blade (which display in email inbox):
<p>{{ $message }}</p>
You need to use any text editors like https://www.tiny.cloud/ insted of textarea.
or you need to send the data with html tags

Lumen How to validate image upload and display an alert on the frontend?

I am building a web app using angular2 for my frontend and lumen for my backend. I have a form where a user can upload a picture but I want to add validation so the user can only upload valid image formats (JPEG, PNG, GIF, etc) and the file cannot be larger than 32mb. I want to return a response to my frontend as an alert if any of these conditions are not met
The upload form (angular2)
<form ngNoForm action=""
target="_blank"
method="POST"
enctype="multipart/form-data">
<input type="file" name="image" id="image">
<input type="submit" value="Upload" name="submit">
</form>
How I'm saving it to the database
public function imageUpload(Request $request) {
// Check to make sure file is valid and doesnt exceed 32mb or display alert
$file = $request->file('image');
$imagedata = file_get_contents($file);
$base64 = base64_encode($imagedata);
if (DB::table('paint')->where('id', 1)
->update(['pic' => $base64]))
{
//Display alert on frontend after pic sucessfully uploaded
}
public function imageUpload(Request $request) {
$this->validate($request, [
'image' => 'required|image|max:32.896'
]);
//rest of your code
}
You can call the validate method at the top of your functions. If one condition will fail it will return an error you can display. its checking:
if the request contains the variable image
if it's an image type (jpeg, png, bmp, gif, or svg)
it's size is smaller or equal to 32.896 kb
for more rules you can check out: https://laravel.com/docs/5.4/validation
in your html file you can do something like this:
<div *ngFor="let elements of errors">
<div class="alert alert-warning" *ngFor="let element of elements">{{ element }}</div>
</div>
it depends how you want to display your messages.

Adding auto hyperlink to images

I have created a wordpress blog for images. While publishing all the posts, I didn't use wordpress editor to upload images. Instead, I used FillaZilla to upload the images. Then, in the wordpress editor, I manually wrote only the image tag (below) in all the posts and published it. All posts contain no text, but only images. Like this,
<img alt="" title="" src=""></img>
Now what I want to ask you is that I want the images in all the posts to get auto hyperlink address same as the image src. I have more than 200 blog posts in my wordpress blog. I don't want to edit all of them one by one. Here's the coding of the wordpress content area,
<div class="post-entry">
<p><img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="sun" alt="sun" /></p>
</div>
Could anyone please help me on this? how can I add hyperlink to the images? Is there any code which I can put in the post-entry div in my wordpress theme page?
#chandu-vkm explained (in the comments) exactly what I was looking for. Now I have one more question. When I add a a span tag before img , the code #chandu-vkm mentioned doesn't let me add span tag right before img tag. Instead it places the place tag outside the p tag, like in the code below.
<div class="post_div">
<span class="entry"></span>
<p>
<img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="Cute Teddy Bear" alt="Cute Teddy Bear" />
</p>
</div>
But I want span to be placed right after p, like this.
<div class="post_div">
<p>
<span class="entry"></span>
<img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="Cute Teddy Bear" alt="Cute Teddy Bear" />
</p>
</div>
Somebody please help me out.
you can do it with some jquery
<div class="post_div">
<img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="sun" alt="sun" />
</div>
like this
$('.post_div img').each(function(){
$(this).wrap(function() {
return '<a href="' + $(this).attr('src') + '" />';
})
});
here the sample http://jsfiddle.net/a4PYd/
If you are certain that all your post content contains only the <img> tag, you can add this snippet of code to your functions.php file:
function hyperlink_all_my_content( $content ) {
$link = "http://www.somelink.com";
return "<a href='$link'>$content</a>";
}
add_filter( 'the_content', 'hyperlink_all_my_content' );
Note that this will link all your content, even on your wordpress pages.
EDIT:
function hyperlink_all_my_content( $content ) {
$matches = array();
$nummatches = preg_match("/src=['|\"](.*)['|\"]/", $content, $matches);
return "<a href='" . $matches[1] . "'>$content</a>";
}
add_filter( 'the_content', 'hyperlink_all_my_content' );

Resources