Jump to content

Emailing PHP dynamic text and image content


rickbond79

Recommended Posts

Hi there,

 

I have a simple question - is it possible to send out an html email containing PHP/MySQL code so that when the user receives the email it checks the date and serves up content from a database? I have created a page that works fine online, but when I try to email the page, it doesn't work from within the user's email client (such as outlook, or gmail).

 

When I look at the raw email source, it looks like the PHP code isn't getting executed by the email program. If anyone knows a reason or workaround, I would appreciate it!

 

Thanks in advance,

Rick

 

<?php
$day = date("Y-m-d");

// Connects to your Database
mysql_connect("empowermentoftheday.com", "username", "password") or die(mysql_error()) ;
mysql_select_db("etd_emails") or die(mysql_error()) ;

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$query = sprintf("SELECT * FROM daily WHERE date = '%s'",
    mysql_real_escape_string($day));

// Perform Query
$Recordset1 = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$Recordset1) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="description" content="Free inspirational Picture of the Day as well as a Free daily Wellness Break. Start your day off right and Empower Yourself Today. Empowerment of the Day is meant to inpire you each and every day and is brought to you by the Remakable Success Group Team.Empower Yourself Today." />

<meta name="keywords" content="inspirational quote, picture of the day, wellness quote, inspirational saying, inspirational story, today's wellness break, empowerment, empower yourself, empowerment of the day, health tip, wellness tip" />

<title>Empowerment Of The Day</title>

</head>

<body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" align="center">

<div style="background:#DBAE13">
<img src="http://www.empowermentoftheday.com/email/images/header.jpg" alt="Empowerment of the Day" width="650" height="77" /></div>

<div>
<table width="650" border="0" cellpadding="0" cellspacing="0">
<tr>
   <td align="center" valign="middle"><img src="http://www.empowermentoftheday.com/email/images/message2.jpg" alt="Picture of the Day" width="306" height="34" vspace="15" /></td>
   </tr>

<tr>
   <td align="center" valign="middle">
   
   <table border="0" cellspacing="0" cellpadding="5" bgcolor="#000000">
  <tr height="10px">
    <td height="10px"></td>
    <td height="10px"></td>
    <td height="10px"></td>
  </tr>
  <tr>
    <td> </td>
    <td><img src="http://www.empowermentoftheday.com/email/images/photos/<?php echo $row_Recordset1['photo']; ?>" alt="Picture of the Day" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td align="center">    
    <div><font color="#FFFFFF" face="Helvetica, Arial, sans-serif"><?php echo $row_Recordset1['quote']; ?></font></div>
</td>

<td> </td>
</tr>

</table>

</td>
</tr>
<tr>
  <td align="center" valign="middle">
      <img src="http://www.empowermentoftheday.com/email/images/message3.jpg" alt="Today's Wellness Break" width="360" height="44" vspace="15" /></td>
</tr>
<tr>
  <td align="center" valign="middle"><p><font color="#000000" face="Helvetica, Arial, sans-serif"><?php echo $row_Recordset1['wellness']; ?><br>
<br>
</font></p></td>
</tr>
</table>

<script language="JavaScript1.2" type="application/javascript">

/*
Disable right click script II (on images)- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

var clickmessage="Right click disabled on images!"

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
alert(clickmessage)
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()
</script>
</div>
<div style="background:#D0A615">
<img src="http://www.empowermentoftheday.com/email/images/footer.jpg" alt="Copyright 2010 Remarkable Success Group Inc. Design by Ortega.ca" width="650" height="74" border="0" usemap="#Map" />
<map name="Map"><area shape="rect" coords="456,28,617,55" href="http://www.ortega.ca" alt="Design by Ortega.ca" target="_blank"></map>
</map></div>

<!-- GOOGLE ANALYTICS -->

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2910054-6']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</td>
</tr>
</table>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
Share on other sites

Email clients can't execute scripts server or client side - this is a big security issue.

I would use your php/mysql script in conjunction with the phpmailer class.

 

So for example your have a php script named "send.php"  - The first part of the script gets the date and hence the DB info and outputs the correct HTML to a file on your server.

 

The second part of the script uses the phpMailer class to send out the HTML file created earlier. So when you go to http://somehost.com/send.php in your browser the correct html is sent to your list. 

Link to comment
Share on other sites

It can be done, but it not a good idea.

 

It involves a lot of javascript, but it so insecure.

 

Send a link as advised.

 

you could do better,

 

idea....

send a link to user email account , they press the link and it,

cheeks there id info on your database, then redirect to a page they can see the info only on your server not there email account.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.