How to place website logo and identity image design on the very top of email sent via phpmailer to gmail - phpmailer

[enter image description here][1]I am sending a password recovery mail and i used table html tag for cross-platform support. I put the image in the right position in the mail, which is at the top. But the image was placed below the message as attachment without the css style and not within the table row on top of the page. How do ensure the image is placed at the top not bottoom inside gmail?
I used phpmailer AddEmbeddedImage('../../img/kokwo_full.png', '{$site}', '{$site}.png').
$subject="Password Reset Request - {$site}";
$message="
<table width='100%' style=' background:#f2f2f2; margin:0px; margin:0px 0px; color:#fff; font-family: Arial, sans-serif; font-size:12px; font-weight:bold; padding:0% 2%'>
<tr style='background:#fff;'>
<td colspan='2'><img src='{$http}://{$website}/img/kokwo.png' style='background:#4885ed; height:60px'/></td>
</tr>
<tr style='height:140px;'>
<td colspan='2' style='color:#000;text-align:center; font-size:32px'> </td>
</tr>
<tr>
<td colspan='2' style='color:#000;text-align:center; font-size:32px; border-bottom:1px solid #000'> Hi {$user_name},</td>
</tr>
<tr style=' height:90px;'>
<td colspan='2' style='color:#000; font-size:18px'>Instant password change
<p style='color:#000; font-size:10px'>{$email}</p></td>
</tr>
<tr style=' color:#808080; '>
<td colspan='2' style='color:#808080; font-size:18px'>Click on this button</td>
</tr>
<tr style=' height:30px;'>
<td colspan='2' style='text-align:center;'>
<form action='{$http}://{$website}reset' method='post' class='regi' enctype='multipart/form-data'>
<input type='text' name='user_id' value='{$user_id}' style='display:none;'/>
<button type='submit' style='background:#00A9E0; color:#fff; padding: 10px;
font-size: 18px;
border: none;
border-radius: 5px;
width: 89%;
margin:25px 3%' name='reg_user' >Change your password on ".ucwords($site)." </button>
</form>
</td>
</tr>
<tr style='height:80px;'>
<td colspan='2'> </td>
</tr>
<tr style='height:30px; background:#4885ed;'>
<td colspan='2'></td>
</tr>
</table>
";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['reset-password'])) {
require '../../PHPMailer/src/Exception.php';
require '../../PHPMailer/src/PHPMailer.php';
require '../../PHPMailer/src/SMTP.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.{$site}.com"; // "ssl://smtp.gmail.com" didn't worked
$mail->SMTPAuth = true;
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->Username = $my_mail;
$mail->Password = $my_password;
$mail->From = $my_mail;
$mail->FromName = $fromname;
$mail->addAddress($email, $user_name);
$mail->addReplyTo($my_mail, $fromname);
$mail->Sender=$my_mail;
//Provide file path and name of the attachments
$mail->Subject = $subject;
$mail->AddEmbeddedImage('../../img/kokwo_full.png', '{$site}', '{$site}.png');
$mail->Body = $message;
$mail->AltBody=$subject;
$mail->Send();
if (!$mail) {
array_push($errors, "<div class='error'><p>
Could not be delivered to {$email},please try again
.</p></div>");
} else {
array_push($errors, "<div class='success'><p>
Check inbox or spam folder at {$email}.</p></div>");
}
}
```what i want to achieve[What I got][2]
[1]: https://kokwo.com/img/stack/real.jpg
[2]: https://kokwo.com/img/stack/fake.jpg

You have attached it as an embedded image, but you're not actually using it in your template.
The second parameter to addEmbeddedImage is cid, a content identifier. A separate problem is that you have single-quoted your strings, so no variable interpolation will be done - that's probably not what you intended.
So if your call looks like this:
$mail->addEmbeddedImage('../../img/kokwo_full.png', 'kokwo', 'kokwo.png').
you would use that image in your HTML like this:
<img src="cid:kokwo" style="background:#4885ed; height:60px">
Note that the string after the cid: part of the URL exactly matches the cid value you passed to addEmbeddedImage.

Related

TinyMCE paste from excel

I have a problem with TinyMCE editor which I cannot resolve.
If I copy a table from Excel and paste it into the editor it loses the formatting. I have set up extended_valid_elements as follows...
extended_valid_elements:"a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],table[style|class|border=2|width|cellspacing|cellpadding|bgcolor],colgroup,col[style|width],tbody,tr[style|class],td[style|class|colspan|rowspan|width|height|background|span|padding],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style|font-family|color]"
The HTML that is saved into the MySQL field is as follows
From Excel ...
<table style="border-collapse: collapse; width: 242pt;" border="2" width="322">
<tbody>
<tr style="height: 14.25pt;">
<td style="height: 14.25pt; width: 105pt;" width="140">Test</td>
<td style="width: 104pt;" width="138"></td>
<td style="width: 33pt;" width="44"> </td>
</tr>
</tbody>
</table>
From Word ...
<table style="width: 242.0pt; border-collapse: collapse;" border="2" width="0">
<tbody>
<tr style="height: 14.25pt;">
<td style="width: 105.0pt; padding: 0cm 5.4pt 0cm 5.4pt; height: 14.25pt;" width="140">
<p style="margin-bottom: .0001pt; line-height: normal;"><span style="font-size: 10.0pt; font-family: 'Arial',sans-serif; color: black;">Test</span></p>
</td>
<td style="width: 104.0pt; padding: 0cm 5.4pt 0cm 5.4pt; height: 14.25pt;" width="139"></td>
<td style="width: 33.0pt; background: #92D050; padding: 0cm 5.4pt 0cm 5.4pt; height: 14.25pt;" width="44">
<p style="margin-bottom: .0001pt; line-height: normal;"><span style="font-size: 10.0pt; font-family: 'Arial',sans-serif; color: black;"> </span></p>
</td>
</tr>
</tbody>
</table>
How can I make this work from excel without having to go through word first?
It would appear I have to use power paste which is a paid-for option ... I have a call setup with their sales team to see how much it will cost! Fingers crossed.

HTML table scraping - table object returned as 1 big cell instead of separate elements

I've been working on a webpage scraping program from within excel VBA (with lots of help from this forum).
I've gotten stuck at a table which shows a single row, which I need to automate clicking. I used the same method for a similar table earlier in the process and that worked fine:
setting the HTML table to IEtable object
using ietable.rows(1).click
This table however, returns as 1 cell containing the values of all the separate elements I see on the webpage and the .click function doesn't work.
This is the HTML code for the table I am trying to access:
<table id="tblPatientList" class="tblTabBody" style="height: 143px; width: 653px;" cellspacing="2" cellpadding="0">
<tbody>
<tr style="height: 100%; width: 100%;">
<td style="width: 649px; height: 100%;">
<div id="divPatientList" style="overflow: auto; width: 100%; height: 100%; background-color: white;">
<table id="dgrPatients" class="tblpat" style="border-width: 0px; width: 100%; border-collapse: collapse;" border="0" rules="all" cellspacing="0" cellpadding="1">
<tbody>
<tr class="headerBlue">
<td style="width: 5%;"> </td>
<td style="width: 15%;">Hosp No.</td>
<td style="width: 15%;">Surname</td>
<td style="width: 15%;">Forename</td>
<td style="width: 10%;">DOB</td>
<td style="width: 2%;">Sex</td>
<td style="width: 10%;">NHS Number</td>
<td style="width: 25%;">Address</td>
<td class="screenOnlyOutput" style="width: 5%;" align="center">List</td>
</tr>
<tr class="even" style="color: red;">
<td align="center"> </td>
<td><strong>12345678</strong></td>
<td>ANONYMOUS FIRST NAME</td>
<td>ANONYMOUS LAST NAME</td>
<td>dd/mm/yyyy</td>
<td align="center">M</td>
<td>123 456 7890 <img style="cursor: hand; vertical-align: middle; border: 0px;" title="Number present and verified" src="/icedesktop/dotnet/icedesktop/images/tick.gif" /></td>
<td>ANONYMOUS ADDRESS</td>
<td class="screenOnlyOutput" align="center"><input id="dgrPatients_ctl02_chkAddOrRemove" style="border: 0px; height: 12px;" name="dgrPatients$ctl02$chkAddOrRemove" type="checkbox" /></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
This table always only returns 2 rows - a header and 1 data row. I try to click it with:
Set ieTbl = ieDoc.Document.frames(0).Document.all.tblPatientList
If Not ieTbl Is Nothing Then
ieTbl.Rows(1).Click
Set ieTbl = Nothing
End If
When I examine the ietable object in the immediate window, it only has 1 row and 1 column, containing all the separate cells on the html page in 1 cell in the ietbl object.
Why is it doing this?

Primeng header misalign from body table

Having a scrollable table with a scrollHeight set and after that changing the scrollHeight, the scrollbar should be aligned with the table header automatically. The table data is not changed.
(I have a scrollable table with header in a resizable dialog, and when dialog resizes, the scrollHeight of the table changes accordingly, but the scrollbar of the table is not aligned to the new scrollHeight)
updating primeng to 7.1.4 version.
<p-table [columns]="cols" [value]="cars" scrollable="true" [scrollHeight]="scrollHeight">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
Correct display of the scrollbar on a scrollable table when changing the scrollHeight dynamically without chaning the data.
It seems to be an ongoing problem, there is a workaround here: https://github.com/primefaces/primeng/issues/5354. But still seems unsolved.
The workaround is to add these styles:
.ui-table-scrollable-header-box {
margin-right: 17px !important;
}
.ui-table-scrollable-body {
margin-right: 17px !important;
}
My workaround :
p-table {
cdk-virtual-scroll-viewport {
overflow-y: scroll !important;
}
}
Best solution which worked like charm for me:
.ui-table .ui-table-scrollable-body-table {
min-height: 1px !important;
}
In my case, if we add a width in header column than must add same width for body on that column
<p-table scrollHeight="calc(100vh - 280px)" [scrollable]="true" [paginator]="true" [rows]="100" [responsive]="true">
<ng-template pTemplate="header">
<tr>
<th style="width: 50px;"> Header One </th>
<th> Header Two </th>
<th> Header Three </th>
<th style="width: 150px;"> Header Four </th>
<th> Header Five </th>
</tr>
</ng-template>
<ng-template pTemplate="body">
<tr>
<td style="width: 50px;"> Body One </td>
<td> Body Two </td>
<td> Body Three </td>
<td style="width: 150px;"> Body Four </td>
<td> Body Five </td>
</tr>
</ng-template>
</p-table>
I've managed to solve this issue by doing the following:
1- add display: grid !important; to .p-datatable css class
2- add display: block; to .p-datatable>.p-datatable-thead>tr>th and .p-datatable>.p-datatable-tbody>tr>th
at the end you will have some structure like this:
.p-datatable {
.p-datatable-thead{
>tr{
>th{
display: block;
}
}
}
.p-datatable-tbody{
>tr{
>th{
display: block;
}
}
}}

how to separate every object populated in table from bd to a separate table paragraph using ASP.Net mvc5

learning asp.net and came to a problem i can not solve yet, any help would be appreciated.
Here is the screen shot of how it is now:
enter image description here
and that how i want it to be on the web:
enter image description here
This is my table on Index page
#{
ViewBag.Title = "Главная страница";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<table>
#foreach (var b in ViewBag.Events)
{
<tr>
<td style=" padding: 8px;"><p><h2>#b.Date</h2></p></td>
<td style=" padding: 8px;"><p><h2>#b.Time</h2></p></td>
</tr>
}
<tr>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Title</h3></p></>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Place</h3></p></td>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Lecturer</h3></p></td>
</tr>
#foreach (var b in ViewBag.Events)
{
<tr style="padding: 80px;">
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee;"><p><h4>#b.Title</h4></p></td>
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee; "><p><h4>#b.Location</h4></p></td>
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee; "><p><h4>#b.Responsible</h4></p></td>
</tr>
}
</table>
Add Event
Home controller
using PhClub.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PhClub.Controllers
{
public class HomeController : Controller
{
EventsContext db = new EventsContext();
public ActionResult Index()
{
IEnumerable<Event> events = db.Events;
ViewBag.Events = events;
return View();
}
[HttpGet]
public ActionResult CreateEvent()
{
return View();
}
[HttpPost]
public ActionResult CreateEvent(AddEvent addEvent)
{
db.AddEvents.Add(addEvent);
db.SaveChanges();
return View();
}
}
}
And second question - at the moment, when i add new event to Db with hardcoded ID it is not being populated with method above - any advise of where im going wrong?
Here is the table for event input i use,
<body>
<div>
<h3>Form of event creation</h3>
<form method="post" action="">
#*<input type="hidden" value="#ViewBag.AddEventId" name="AddEventId" />*#
<table>
<tr>
<td><p>Enter Id of event :</p></td>
<td><input type="text" name="AddEventId" /> </td>
</tr>
<tr>
<td><p>Enter title :</p></td>
<td><input type="text" name="Title" /> </td>
</tr>
<tr>
<td><p>Date:</p></td>
<td><input type="text" name="Date" /> </td>
</tr>
<tr>
<td><p>Time :</p></td>
<td><input type="text" name="Time" /> </td>
</tr>
<tr>
<td><p>Address :</p></td>
<td>
<input type="text" name="Location" />
</td>
<tr>
<td><p>Lecturer:</p></td>
<td><input type="text" name="Responsible" /> </td>
</tr>
<tr><td><input type="submit" value="Send" /> </td><td></td></tr>
</table>
</form>
</div>
</body>
Your current structure has two adjacent loops:
#foreach (var b in ViewBag.Events)
{
[some output]
}
[more output]
#foreach (var b in ViewBag.Events)
{
[even more output]
}
So you're looping over the events twice, effectively building two different sections of table divided by that output in the middle. It looks like you want just one loop, where each iteration of the loop has a couple rows of table output. Something structured more like this:
#foreach (var b in ViewBag.Events)
{
[some output]
[more output]
[even more output]
}
This is untested of course, but perhaps in your code it would look like this:
#foreach (var b in ViewBag.Events)
{
<tr>
<td style=" padding: 8px;"><p><h2>#b.Date</h2></p></td>
<td style=" padding: 8px;"><p><h2>#b.Time</h2></p></td>
</tr>
<tr>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Title</h3></p></>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Place</h3></p></td>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Lecturer</h3></p></td>
</tr>
<tr style="padding: 80px;">
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee;"><p><h4>#b.Title</h4></p></td>
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee; "><p><h4>#b.Location</h4></p></td>
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee; "><p><h4>#b.Responsible</h4></p></td>
</tr>
}
Basically, just loop over the records once and build the output you want for each record.
(For your second question, you may want to open a new Stack Overflow question. To avoid confusion and keep things concise it's generally best to ask one question at a time.)

finding the direct child of a tag in watir

I have a table containing multiple columns in which the data is populated from a database. The columns can have drop-downs, text-fields, check-boxes along with simple text. I need to write down a function which will essentially return the data present in a table column.
Here's an example as to how the tags are named in the web page. [Credits to w3schools for the CSS for the tables].
<html>
<head>
<style type="text/css">
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:100%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
</style>
</head>
<body>
<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr class="data-row">
<td id="customers:0:company">Alfreds Futterkiste</td>
<td id="customers:0:contact">Maria Anders</td>
<td id="customers:0:chooseCountry">
<select id="customers:0:country">
<option>Germany</option>
<option>Sweden</option>
<option>Mexico</option>
</select>
</td>
</tr>
<tr class="data-row alt">
<td id="customers:1:company">Berglunds snabbköp</td>
<td id="customers:1:contact">Christina Berglund</td>
<td id="customers:1:chooseCountry">
<select id="customers:1:country">
<option>Germany</option>
<option selected="selected">Sweden</option>
<option>Mexico</option>
</select>
</td>
</tr>
<tr class="data-row">
<td id="customers:2:company">Centro comercial Moctezuma</td>
<td id="customers:2:contact">Francisco Chang</td>
<td id="customers:2:chooseCountry">
<select id="customers:2:country">
<option>Germany</option>
<option>Sweden</option>
<option selected="selected">Mexico</option>
</select>
</td>
</tr>
</table>
</body>
</html>
Now, the algorithm which I use for determining all the values in the column say "Company" is
Determine the no of rows having class = or substring as "data-row".
Construct the string for getting the cell and iterating it from 0 to n-1
Use the text method to retrieve the text
Now, if I use this on a select_list, it returns all the options in the list. Thus, I was going to check whether the child of the tag is either a text-field or a drop-down
list and call their respective functions to get their values.
Is there a way where in Watir we can determine the child of a particular tag is a particular tag or not or is there some method similar to getAllChildNodes in JavaScript?
Sorry for being over-descriptive and thanks in advance for any possible solutions.
This is very simple, you just need to see whether a text_field or select_list exists:
require 'watir-webdriver'
b = Watir::Browser.start 'yourwebpage'
b.table.rows.each do |row|
row.cells.each do |cell|
if cell.text_field.exist?
puts cell.text_field.value
elsif cell.select_list.exist?
puts cell.select_list.selected_options
else
puts cell.text
end
end
end
b.close

Resources