Yii2 Swiftmailer can't send image and font awesome icons - php

Mu Controller Code:
if ($model->load(Yii::$app->request->post())) {
$data = $this->renderPartial('receivers/contact_form_output_quick_query', [
'model' => $model,
'formData' => $_REQUEST], true);
$receiver_message = $this->renderPartial('receivers/receiver_message_quick_query',['data' => $data]);
$message = Yii::$app->mailer->compose();
$message->setFrom('info#company.com')
->setTo('info#company.com')
->setSubject('Subject Of email')
->setHtmlBody($data)
->send();
$message = Yii::$app->mailer->compose();
$message->setFrom('info#company.com')
->setTo($model->email)
->setSubject('Reply: Online Query')
->setHtmlBody($receiver_message)
->send();
Yii::$app->session->setFlash('success', 'Congratulations! Your message has been successfully Sent.');
}
Will some one tells me what is the main reason that image and Font Awesome icons are not sending properly?
My receiver message partial view goes here:
<div>
<table style="width: 600px;">
<tr>
<td>Thanks for your interest in our services. We have received your online query.</td>
</tr>
<tr>
<td>Thanks again for contacting us.</td>
</tr>
<tr>
<td style="height: 5px;"></td>
</tr>
<tr>
<td>(It may take some time depending upon the number of queries in the pipeline. We appreciate your cooperation in this regard.)</td>
</tr>
<tr>
<td>Regards!</td>
</tr>
</table>
<?= $this->render('signature'); ?>
<table>
<tr>
<td><strong style="font-size:16px;">Query Details that we received:</strong></td>
</tr>
<tr>
<td><?= $data; ?></td>
</tr>
</table>
</div>
The above is the render partial view for the receiver message:
My signature partial view is:
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<table>
<tr>
<td colspan="3">
<img src="<?= $this->theme->baseUrl?>/images/email_signature.png">
</td>
</tr>
<tr>
<td style="height: 30px;"></td>
</tr>
<tr>
<td>+123456778</td>
<td colspan="2"> | +123456778</td>
</tr>
<tr>
<td>http://www.example.com</td>
<td>| info#company.com </td>
<td>| <b>Skype:</b> skypeid</td>
</tr>
<tr>
<td><a target="_blank" href="https://www.linkedin.com"><i class="fa fa-linkedin"></i> Linked In | </a></td>
<td><a target="_blank" href="https://www.facebook.com"><i class="fa fa-facebook"></i> Facebook | </a></td>
<td><a target="_blank" href="https://twitter.com"><i class="fa fa-twitter"></i> https://www.twitter.com</a></td>
</tr>
The above is the render partial view for signature containing image and font awesome icons main problem is in this file.

Images
$this->theme->baseUrl will return path to theme, but without domain and scheme part (for example it will return /themes/my-theme). When you're generating URLs for mailing, you need to full URL with scheme and domain - you should generate URLs like this:
<img src="<?= Yii::$app->request->getHostInfo() . $this->theme->getBaseUrl() ?>/images/email_signature.png">
Font Awesome Icons
I have a bad news for you - many clients (especially webmails) does not support webfonts, so you will not be able to use Font Awesome icons in this way. Support for SVG is even worse, so this is not a solution either. You should probably stick to good old PNGs as icons.
Unfortunately working with mailing is like a time travel - you should build your emails in the same way you created your websites 10-20 years ago. Forget about fancy CSS3 features - the most bulletproof templates are still built using tables with inline CSS everywhere...

Not every mail client supports webfonts. So probably best for you is to download it as images, save it in your public assets folder and invoke it with img element tag.

if I am not wrong you need to use embed() or attach() for showing inline images in the email.
$Imageid = $message->attach(Swift_Attachment::fromPath('path/to/image')
->setDisposition('inline'));
and then use the $cid for showing the image inside the email text where ever you are assigning the text for the email
<img src="' . $Imageid . '" alt="Image" />'

Related

PHP template (.tpl) how to exclude directories

I'm using a PHP autoindex script which utilizes the template (.tpl) below. I would like to open files only in a new tab. I've tried adding target="_blank" to line 3 below, but this doesn't differentiate between files or directories and both open in a new tab. I want to exclude directories from opening.
<tr class="{file:tr_class}">
<td class="padded_row">
<a class="autoindex_a" href="{file:link}">
{if:icon_path}<img width="16" height="16" alt="[{file:file_ext}]" src="{file:icon}" />{end if:icon_path}
{file:filename} {file:thumbnail}
</a>{file:new_icon}{file:md5_link}{file:delete_link}{file:rename_link}{file:edit_description_link}{file:ftp_upload_link}
</td>
{if:download_count}
<td class="cell_right">
{file:downloads}
</td>
{end if:download_count}
<td class="cell_right">
{file:size}
</td>
<!--<td class="cell_right">
{file:date}
</td> -->
{if:description_file}
<td class="padded_row">
{file:description}
</td>
{end if:description_file}
</tr>
I'm wondering if there is a way to check before opening the link like an "if statement". If it is a directory or file and then "do something"...however I'm not skilled in this area.
thanks for your help

PHP mpdf handling block level elements inside table

I am using mpdf library to generate PDF from HTML.I came across the limitation of mpdf that we cannot use block level elements inside table.Is there any possible way to make mpdf work with following code?. I tried span instead of p but its not act like block level elements.
<table style="width:100%; table-layout:fixed">
<tr>
<td>
<p style="text-align:left;font-size:14px;font-family:Arial;padding-left:105px;">Some text</p>
<p style="text-align:left;font-weight:normal;font-size:14px;font-family:Arial;padding-left:125px;">Some text Some text Some text </p>
</td>
</tr>
</table>
The styles of Block level elements inside table,td won't reflect in PDF.I have fixed above issue with using another table by following.Hope it will help someone.
<table style="width:100%; table-layout:fixed">
<tr>
<td>
<table>
<tr>
<td style="text-align:left;font-size:14px;font-family:Arial;padding-left:105px;">
Some text
</td>
</tr>
<tr>
<td style="text-align:left;font-weight:normal;font-size:14px;font-family:Arial;padding-left:125px;">
Some text Some text Some text
</td>
</tr>
</table>
</td>
</tr>
</table>

PHP Web Page Scraping

I am able to get the coding of a website with file_get_contents but I want to be able to get certain values out of the html. This piece of code is always the same but the value between the html tag changes from time to time. This is the HTML Code:
<div class="cheapest-bins">
<h3>Cheapest Live Buy Now</h3>
<table>
<tbody><tr>
<th>Console</th>
<th>Buy Now Price</th>
</tr>
<tr class=" active">
<td class="xb1">XB1</td>
<td>1,480,000</td>
</tr>
<tr class="">
<td class="ps4">PS4</td>
<td>1,590,000</td>
</tr>
<tr class="">
<td class="x360">360</td>
<td>---</td>
</tr>
<tr class="">
<td class="ps3">PS3</td>
<td>2,800,000</td>
</tr>
</tbody></table>
</div>
How would I go about getting the: 1,480,000 .. 1,590,000 .. --- and 2,800,000?
short answer:
find a css selector library such as https://github.com/tj/php-selector
then you could grab all td:last-child elements/innerhtml
for your specific example you could just just
preg_match_all('#<td>(.*?)</td>#', $html, $matches);

Placing a path to an image in mySQL and displaying on a php page in dreamweaver

For my uni project i have created a website for my local rugby team...
I have a database of players and in that database i have a column for profile picture. I was told to just put the path to the image in the player record which i did. The photo doesnt load just the line i put it there. The path i inserted below....
H:\WebDesign2\Xampp\htdocs\BedlinogRFC\images\Benji.jpg
Below is my dreamweaver code:
<div class="playerProfilePhotoContainer">
<table height="250" width="299" border="0" cellpadding="3">
<caption>
Player Photo
</caption>
<tr>
<td><img src="<?php echo $row_Recordset1['ProfilePhoto']; ?>" alt="Profile Photo of Player"/></td>
</tr>
</table>
</div>
Can anybody show me where i am going wrong or where i need to change?
Thanks
This:
<td height="235"><?php echo $row_Recordset1['ProfilePhoto']; ?></td>
Should be:
<td height="235"><img src="<?php echo $row_Recordset1['ProfilePhoto']; ?>" alt=""/></td>

Layout problems (php,html)

I made some images which i need, currently i have :
$output .= "
<tr>
<td align='center'><b>{$name}</b></td> </tr>
<tr>
<td align='center'><img src='$avatar'/></td> </tr>
<td align='center'><b>Points</b>: {$points}</td> </tr>
<tr>
<td align='center'><b>Status</b>:<b><font color='green'> {$misc['text_status']}</font></b></td> </tr>
<tr>
<td align='center'><a href='".$link."'><font color='red'><b>See more statistics</b></font></a><hr></td></tr>
";
with script i get this(ie image) http://img717.imageshack.us/img717/7885/thisdn.png .
Now i need to output something like this http://img703.imageshack.us/img703/171/thatq.png (ie image) without mysql. May i have some examples of yours?
move <tr> before your for loop and </tr> after you for loop
or better one, place individual tables with float:left for each member
You could try to wrap every profile information (photo, points etc) in a div and not use tables at all. Then float these div-s to the right or left. Note that every div must have the same class.

Categories