Laravel email template URLs not working in Gmail - php

I am using Laravel 4 smtp mail to send mail to users. When I send mails to Gmail, the logo and URLs didn't show up as intended. When I checked the urls, it showed localhost instead of my domain name. I don't know why it's happening.
My email template:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Dosis:400,500,600,700' rel='stylesheet' type='text/css'>
<style>
body {
font-family: 'Dosis', sans-serif;
font-size:14px;
color: #333;
}
#table-wrap {
background:#fafafa;
border-bottom: 5px solid #eee;
border-top: 5px solid #EC4F48;
}
#site_logo{
background: #EC4F48;
border-bottom: 2px solid #EC4F48;
-webkit-border-bottom-right-radius: 2px;
-webkit-border-bottom-left-radius: 2px;
-moz-border-radius-bottomright: 2px;
-moz-border-radius-bottomleft: 2px;
border-bottom-right-radius: 2px;
border-bottom-left-radius: 2px;
}
</style>
</head>
<body>
<table id="table-wrap" width="100%" cellpadding="0" cellspacing="0" style="border-radius:3px; -webkit-border-radius:3px; -moz-border-radius:3px;">
<tbody>
<tr>
<td align="left" style="padding:3px; border-bottom: 2px solid #fadc65;" width="60%">
<h3 style="margin-left: 15px;">Hi, {{{ $username }}}!</h3>
</td>
<td align="center" id="site_logo">
<img src="{{ asset('dist/img/logo.png') }}" width="200" style="margin-left: 10px;" />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<br />
<h2>Welcome to mydomain.com !</h2>
<h2>Thanks for registering to Mysite.</h2>
<h4>Click here to confirm your email...</h4>
<br />
</td>
</tr>
<tr>
<td align="left">
<p style="margin-left: 20px; color: #666;">
www.mydomain.com | Email : feedback#mydomain.com
</p>
</td>
</tr>
</tbody>
</table>
</body>
</html>

When you use CLI to generate any view Laravel uses url parameter to set domain. By default its value is set to http://localhost so you need to change this parameter to your domain.
The parameter is located in app.php in config folder.
Laravel comment for Application URL:
This URL is used by the console to properly generate URLs when using the Artisan command line tool. You should set this to the root of your application so that it is used when running Artisan tasks.

Related

On pdf generate getting Image not found or type unknown barryvdh\dompdf error

I am getting below error when generating a PDF in Laravel using barryvdh/laravel-dompdf package of laravel.
Image not found or type unknown
HTML
<html>
<head>
<style>
table
{
border-color: #000;
color: #000;
border-collapse: collapse;
font-family: sans-serif;
}
</style>
</head>
<body>
<table style="width: 100%; margin-top: 10px;" cellpadding="3" border="1">
<tr>
<td style="text-align: right; font-weight: bold; font-size: 14px; padding-left: 5px;">User Image</td>
<td colspan="4" style="height: 50px;">
<img src="/val/test/storage/images/profile_1611820816863.jpg" height="70">
</td>
</tr>
</table>
</body>
</html>
Level
$complete_html = '<above HTML>';
$dompdf = new Dompdf();
$dompdf->loadHtml($complete_html);
$page_size = 'A4';
$dompdf->setPaper($page_size, 'portrait');
$dompdf->render();
$file_name = 'test_dom';
$dompdf->stream($file_name.'.pdf', array("Attachment" => 1));
I have reviewed other post on this topic and set "RemoteEnable" as true in dompdf config file and restarted the server but still getting this issue.
Edit
I have changed image path it is a shared folder path, not project or local path.
Also, file and folder path both have full permission to read and write(777) is already given
This could be because of a file permission issue, Please check your BL server has all required access to read/write an image file from the shared location.
This could happen only if the server configuration could have been changed.
Your class is wrong, to use laravel-dompdf you should call PDF or \Barryvdh\DomPDF\PDF. and change /test/example-app/storage/images/profile_1611820816863.jpg to real absolute path. if your image folder inside app folder you should change to app_path('storage/images/profile_1611820816863.jpg'). Below is working code using dompdf wrapper:
$pdf = \Barryvdh\DomPDF\PDF::loadHtml('<html><head>
<style>
table
{
border-color: #000;
color: #000;
border-collapse: collapse;
font-family: sans-serif;
}
</style>
</head>
<body>
<table style="width: 100%; margin-top: 10px;" cellpadding="3" border="1">
<tr>
<td style="text-align: right; font-weight: bold; font-size: 14px; padding-left: 5px;">User Image</td>
<td colspan="4" style="height: 50px;">
<img src="'.app_path('storage/images/profile_1611820816863.jpg').'" height="70>
</td>
</tr>
</table>
</body></html>');
$pdf->stream('test_pdf.pdf', array("Attachment" => 1));
if you want still use original dompdf without wrapper, you need to change image url to app_path('/storage/images/profile_1611820816863.jpg') and also set chroot to app_path()
below is my tested working code withoud wrapper:
$complete_html = '<html><head>
<style>
table
{
border-color: #000;
color: #000;
border-collapse: collapse;
font-family: sans-serif;
}
</style>
</head>
<body>
<table style="width: 100%; margin-top: 10px;" cellpadding="3" border="1">
<tr>
<td style="text-align: right; font-weight: bold; font-size: 14px; padding-left: 5px;">User Image</td>
<td colspan="4" style="height: 50px;">
<img src="'.app_path('/test/example-app/storage/images/profile_1611820816863.jpg').'" height="70>
</td>
</tr>
</table>
</body></html>';
$dompdf = new \Dompdf\Dompdf();
$options = $dompdf->getOptions();
$options->setChroot(app_path());
$options->setIsRemoteEnabled(true);
$dompdf->setOptions($options);
$dompdf->loadHtml($complete_html);
$page_size = 'A4';
$dompdf->setPaper($page_size, 'portrait');
$dompdf->render();
$file_name = 'test_dom';
$dompdf->stream($file_name.'.pdf', array("Attachment" => 1));

I wish to insert reply buttons in php-mailer AMENDED

I have created a code which works in the email client as follows:
<html>
<head>
<title>PLEASE REPLY USING THE BUTTONS</title>
</head>
<body>
<table cellspacing="5" cellpadding="5" border:5px;>
<tr>
<td align="center" width="200" height="40" bgcolor="#000091" style="-webkit- border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;" >
<span style="color: #FFFFFF">ATTENDING</span>
</td>
<td height="10"></td>
<td align="center" width="200" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">
<span style="color: #FFFFFF">ATTENDING AND DINING</span>
</td>
<td height="10"></td>
<td align="center" width="200" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">
<span style="color: #FFFFFF">APOLOGIES</span>
</td>
</tr>
</table>
</body>
</html>
Now amended to include html, header, body. It works in a web page and works in an email client.
But placing this into the body text in php-mailer ignores it completely.
How can I ensure that these buttons appear in the mailed text.
I do not understand the response with Yii:: as the page simply jams up.
Is there any easier way to get the html into the page?
Thanks for your assistance
CRG
use setHtmlBody in your code
public function sendEmail($email)
{
return Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject('text')
->setHtmlBody($this->body)
->send();
}
Email html differs greatly from normal html, for various reasons, security being one of them. Many email clients ignore the mailto link completely, implement it poorly, or show a warning to the user.
It is better to avoid it. You could use a form inside you email, or on your website, to allow users to send you a message.
Ref: https://www.campaignmonitor.com/blog/email-marketing/2013/06/tip-avoid-using-mailto-links-in-html-email/

Email not working which contains sub domain url

I am getting a strange issue in a website.
I have a domain (e.g. http://exaple.com.PQR.co.uk) on which I have built a website using PHP.
Website working fine but issue is in sending email.
I trying to send HTML email as below example ::
<html lang="en"><head><meta charset="utf-8"></head>
<body>
<table style="width: 100%; border: none; border-collapse: collapse;">
<tbody>
<tr>
<td style="border: none; background-color: #000; padding: 15px; color:#fff; width: 70px;">
<a href="#" style="border:none;">
<img src="**http://www.example.com.PQR.co.uk/**webservices/icon-70.png" width="70" height="70">
</a>
</td>
<td style="border: none; background-color: #000; padding: 15px; color:#fff; font-size: 40px;">
ABC
</td>
</tr>
<tr>
<td colspan="2" style="background-color: #EEEEEE; color: #000; padding: 10px;">
Hello User, <br><br>
Your account details are as below:<br/><br/>
Email ID : test.example#gmail.com<br/>
Password : Click here to change password.<br/>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: #EEEEEE; color: #000; padding: 10px;">
Thanks,<br/>
ABC Team
</td>
</tr>
<tr>
<td colspan="2" style="background-color: #EC008C; padding:5px;">
</td>
</tr>
</tbody>
</table>
</body>
</html>
This email does not send successfully but mail() returns TRUE.
When I tries to send same email by changing domain to "example.com" instead of "www.example.com.PQR.co.uk" then it works but with "www.example.com.PQR.co.uk" its not working.
Please guide me for this issue. I am not getting where issue is.
Thanks in advance

php ul li class and id

I have looked but the answers that people have given didn't help my problem. Rather confusion.
I am creating a small project for my website and i am trying to convert it to php for the pages and easier maint.
The way i want it set up is like how i have it now. Soloentertainment.org But this is all html and each page is it own Html page and if i need to edit or add to the nav bar or anywhere else i have to go to each html and change it. That is a big no no. So trying to convert it to php but the problem i have encountered, which is weird is that i have it highlight what page you are on now. But for the php, Soloentertainment.org/index.php, (i don't have all links working so the projects page and bout leads to the html links) but the home should be highlighted like in the original home page.
Code for the index.php:
<body bgcolor="#000000" id="home">
<div align="center">
<table class="contentTable" >
<tbody>
<tr>
<td colspan="0" border="0" height="50px" align="center">
<?php include("message.php"); ?>
</td>
</tr>
<tr>
<td colspan="0" border="0" height="125px" align="center">
<?php include("header.php"); ?>
</td>
</tr>
<tr>
<?php include("navbar.php"); ?>
</tr>
<?php include("home.php");?>
</tbody>
</table>
</div>
</body>
Code for the Navbar.php:
<td id="navbar">
<ul>
<li onclick="location.href='http://www.soloentertainment.org/index.php';" class="home" title="Home">Home</li>
<li class="projects" title="Projects">Projects</li>
<li class="about" title="About">About</li>
<li>Contact</li>
</ul>
</td>
The original index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico">
<title>Solo Entertainment</title>
</head>
<style>
.contentTable {
width: 795px;
border-left: 10px;
border-left-color: #b7ad6f;
border-right: 10px;
border-right-color: #b7ad6f;
margin: 0px;
padding: 0px;
}
.header {
background-color; #000
background-repeat: no-repeat;
background-position: right;
}
#navbar {
width:100%;
height:30px;
background-color:#000;
}
#navbar ul {
width:50%;
margin:0 auto 0 auto;
}
#navbar ul li {
float:left;
color: #FFF;
padding:0 20px 0 20px;
border:1px solid #FFF;
height:30px;
list-style:none;
display:block;
line-height:30px;
text-align:center;
cursor:pointer;
}
#navbar ul li:hover {
background-color:#CCC;
color: #000;
}
#home #menu .home, #projects #menu .projects {
background-color:#FFF;
color: #111
}
</style>
<body bgcolor="#000000" id="home">
<div align="center" id="menu">
<table class="contentTable">
<tbody>
<tr>
<td colspan="2" border="0" height="55px" align="center">
<font color="#FF0000" size="+2">This site is still being built. Please be Patient</font>
</td>
</tr>
<tr>
<td colspan="2" class="header" align="left" border="0" height="125px">
<img src="images/solo.png" width="785" height="112" alt="Title" title="Solo Enertainment" border="0">
</td>
</tr>
<tr>
<td id="navbar">
<ul>
<li onclick="location.href='http://www.soloentertainment.org';" class="home" title="Home">Home</li>
<li onclick="location.href='http://www.soloentertainment.org/projects';" class="projects" title="Projects">Projects</li>
<li onclick="location.href='http://www.soloentertainment.org/about';" class="about" title="About">About</li>
<li>Contact</li>
</ul>
</td>
</tr>
<tr>
<td colspan="2" class="header" align="center" border="0" height="100px">
<font color="#FFFFFF" size=""> Welcome to Solo Entertainment, One Man One Show.</font>
</td>
</tr>
<tr>
<td colspan="2" class="header" align="Center" border="0">
<img src="./images/kyleandsteve1280.jpg" width="307" height="245" />
<br />
<font color="#FFFFFF">Kyle and Steve Save the world.
<br />
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Now the i don't get why Home is highlighted in the html and not for the php?
Your css that make the highlight looks like this:
#home #menu .home, #projects #menu .projects {
background-color: #FFFFFF;
color: #111111;
}
On your PHP file, the button with .home class is under an element with a #home id but there's no element with #menu id.
This is the part on your HTML:
<body bgcolor="#000000" id="home">
<div align="center" id="menu">
This is the part on your PHP:
<body bgcolor="#000000" id="home">
<div align="center">

send html as attachment via phpmailer

I have html variable,i want to send it as attachment via email.
here is my code
$html='
<table cellpadding="0" cellspacing="0" style=" margin:0 auto;" width="100%">
<tr>
<th style="background:#FC3; padding:4px 0;border:1px solid #000; border-bottom:2px solid #000; border-right:2px solid #000;" align="center" valign="middle"><h3 style="font:300 14px verdana; margin:0; text-align:left;text-align:center;">DECLARATION BY THE AGENT</h3></th>
<th style="background:#FC3; padding:4px 0;border:1px solid #000; border-bottom:2px solid #000; border-right:2px solid #000;" align="center" valign="middle"><h3 style="font:300 14px verdana; margin:0; text-align:left;text-align:center;">DECLARATION BY THE OWNER (The Seller)</h3></th>
</tr>
<tr>
<td width="49%" style="padding:5px 10px;border-right:2px solid #000;">
<ul style="margin:0; padding:0;">
<li style="list-style:none; margin:0 0 10px 0;">
<p style="font:300 12px verdana;float: left; margin:0 5px 0 0;text-align:center;">
I hereby declare, I have read and understood the Real Estate Brokers Code of Ethics,
</p>
</li>
</ul></td>
<td width="49%" style="padding:5px 10px;border-left:1px solid #000;">
<ul style="margin:0; padding:0;">
<li style="list-style:none; margin:0 0 10px 0;">
<p style="font:300 12px verdana;float: left; margin:0 5px 0 0; text-align:center;">
I/We hereby declare, we are the Owners of the property as stated below.
</p>
</li>
</ul></td>
</tr>
</table>';
$mail->AddAttachment($html); // attachment
$mail->Send();
AddAttachment() requires a file (on the filesystem)
there is the AddStringAttachment() function for what you are doing. see docs: http://docs.redaxo.com/de/4.3.1/class_p_h_p_mailer.html#a92ef5134fdce5bd5fd24a723c508bf2b
try this:
$mail->AddStringAttachment($html,"filename.htm","base64","text/html");
I think you are trying to send html instead so try like this
$mail->Body = $html;
$mail->Send();
ok, so you are trying to send it for example and it deosn't work ?
$mail->AddAttachment("/var/tmp/file.html");

Categories