Solved

Send email everyday automatically

Posted on 2016-09-15
8
43 Views
Last Modified: 2016-09-16
I created a table with this output

ID          Rows                      Insurance
----          --------                     --------------
123           2                             AA,EE
345            1                            YU
55              3                             AA,EE,UY

Open in new window


And more, I want it to be able to send an email daily with these reports but for it to be sent with the same CSS style it is displayed on the webpage. Any ideas on how I could send this email and without altering the physical display of it?
Im using PostgreSQL and the emails will be entered manual (since there more than one)
0
Comment
Question by:Jasmine Ikhreishi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 41799772
First get a mail php script to send it out according to your wishes (get the html source code and css correct).
After that, you have to add a cronjob to mail it out every day. If you don't have access to a cronjob, you WILL have to do it manually.
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41799775
There are PHP extensions for sending HTML emails, but browsers and email reader apps handle CSS very differently. You will have to re-create the styled table to suit the email reader application. It is very unlikely that an email reader will import an external stylesheet. Some email reader apps will strip out anything in the head element where most internal stylesheets are in web pages. There are a few that will retain and apply stylesheets within the body element. But the safest way to style an email is to use inline styles. This means that every element will need a style attribute with style parameters.

Your table does not appear to require sophisticated CSS styling. I would begin by sending a bare HTML table and see if it displays adequately in your email application. You obviously have a routine already set up to generate an HTML table for the web page. Use that routine to generate the message for the HTML email.

One popular PHP extension for sending HTML email is PEAR Mail_Mime. I've seen other experts recommend PHPMailer. The first step would be to determine if your server is already configured with one of these. If not, you'll need to load one.
0
 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41799792
Unfortunately I need to do the mailing procedure manually.

//if "email" variable is filled out, send email
  if (isset($_REQUEST['email']))  {
  
  //Email information
  $admin_email = "jasmine@hotmail.com";
  $email = "jasmine@hotmail.com";
  $subject = 'Date';
  
  //send email
  mail($admin_email, "$subject", $comment, "From:" . $email);

Open in new window

 I have added this before the content but it didnt work
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 41799823
what was $comment? If possible, post in full.
0
 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41799828
Its nothing that code wouldnt even work. I tried using this also but it wouldnt work:

require "connection.php";

$to = "jasmine@hotmail.com";
$subject = "HTML email";
?>
<?php

$query= "SELECT client_id, count(client_id) AS rows, array_agg(insurance) AS insurance from vouchers WHERE parsing_date=CURRENT_DATE GROUP BY client_id";
$result = pg_query($conn,$query);

?>
$message= "
<!DOCTYPE html>
<html>
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<link href = "http://fonts.googleapis.com/css?family=Roboto:400">

<style>
.responstable {
  margin: 1em 0;
  width: 100%;
  overflow: hidden;
  background: #FFF;
  color: #024457;
  border-radius: 10px;
  border: 1px solid #167F92;
  word-wrap: break-word;
}
</style>

</head>

<body>
<div class="container-fluid">
        <div>
        
          <h1>Clients</h1>
   
          
        </div>
        
<table class="responstable" rules='all' style='border-collapse: collapse;'>
<thead>
	<tr>
		<th>Client id</th>
		<th>Number of rows</th>
		<th>Insurance</th>
	 
	</tr>
</thead>
  <?php 
  	while($row = pg_fetch_array($result))
	{ 




$find ='{';
$replace = '' ;
$arr = $row['insurance'];
$insurance3= str_replace($find,$replace,$arr);
$insurance = str_replace('"','  ',$insurance3);

  ?>
 
  <tbody>


     <td><?php echo $row['client_id']; ?></td>
     <td><?php echo $row['rows'];?></td>   
     <td><?php echo $insurance; ?></td> 
      
    </tr>
  <?php  }

  
  ?>  </tbody>
</table>
 
</div>

</body>
</html>
  ";

<?php 
$headers = "HI";
mail($to,$subject,$message,$headers);

?>

Open in new window


$message being the whole content starting from the query
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 41799866
You keep opening and closing the PHP tag, therefore confusing yourself.

Since $message= " is declared outside the PHP tag, it's not known to PHP what it is.
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41800264
What happens if you enter this at the top of your PHP code?
mail("jasmine@hotmail.com","Test Message","This is a test","FROM: jasmine@hotmail.com");

Open in new window

Be sure to check your hotmail spam/junk folder.
0
 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41801307
I dont recieve anything when I do that i checked everything
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Session time out quickly. 6 50
CSRF session and form tokens never match when using php/AJAX 4 56
PHP substring 3 46
Can't find an open element in HTML 5 49
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question