<?php
// Global variables for function use.
$GLOBALS['title'] = false;
$GLOBALS['link'] = false;
$GLOBALS['description'] = false;
$GLOBALS['titletext'] = null;
$GLOBALS['linktext'] = null;
$GLOBALS['desctext'] = null;
$GLOBALS['email_body'] = '';
$GLOBALS['email_body'] .= '<html>
<body><table width="100%" cellpadding="3" cellspacing="1" border="0" align="center">';
$GLOBALS['email_body'] .= ' <tr>';
// Add a title for the newsletters here
$GLOBALS['email_body'] .= ' <th align="left"></th>';
$GLOBALS['email_body'] .= ' </tr>';
$GLOBALS['email_body'] .= ' <tr>';
$GLOBALS['email_body'] .= ' <td class="row1" width="100%">';
$GLOBALS['email_body'] .= ' <font face="arial">';
// Add some HTML for store specials here
$GLOBALS['email_body'] .= ' ';
// function: startElement
// Deals with the starting element
function startElement( $parser, $tagName, $attrs ) {
// By setting global variable of tag name
// I can determine which tag I am currently
// parsing.
switch( $tagName ) {
case 'TITLE':
$GLOBALS['title'] = true;
break;
case 'LINK':
$GLOBALS['link'] = true;
break;
case 'DESCRIPTION':
$GLOBALS['description'] = true;
break;
}
}
// function: endElement
// Deals with the ending element
function endElement( $parser, $tagName ) {
// By noticing the closing tag,
// I can print out the data that I want.
switch( $tagName ) {
case 'TITLE':
//echo "<p><b>" . $GLOBALS['titletext'] . "</b><br/>";
$GLOBALS['email_body'] .= "<p><b><a href=\"". $GLOBALS['linktext'] . "\">" . $GLOBALS['titletext'] . "</a></b><br/>";
$GLOBALS['title'] = false;
$GLOBALS['titletext'] = "";
break;
case 'LINK':
//echo "Link: <a href=\"". $GLOBALS['linktext'] . "\">" . $GLOBALS['linktext'] . "</a><br/>";
$GLOBALS['email_body'] .= " ";
$GLOBALS['link'] = false;
$GLOBALS['linktext'] = "";
break;
case 'DESCRIPTION':
//echo "Desc: " . $GLOBALS['desctext'] . "</p>";
$GLOBALS['email_body'] .= "Opis: " . $GLOBALS['desctext'] . "</p>";
$GLOBALS['description'] = false;
$GLOBALS['desctext'] = "";
break;
}
}
// function: charElement
// Deals with the character elements (text)
function charElement( $parser, $text ) {
// Verify the tag that text belongs to.
// I set the global tag name to true
// when I am in that tag.
if( $GLOBALS['title'] == true ) {
$GLOBALS['titletext'] .= $text;
} else if( $GLOBALS['link'] == true ) {
$GLOBALS['linktext'] .= $text;
} else if( $GLOBALS['description'] == true ) {
$GLOBALS['desctext'] .= $text;
}
}
// Create an xml parser
$xmlParser = xml_parser_create();
// Create an xml parser
$xmlParser2 = xml_parser_create();
// Set up element handler
xml_set_element_handler( $xmlParser, "startElement", "endElement" );
// Set up element handler
xml_set_element_handler( $xmlParser2, "startElement", "endElement" );
// Set up character handler
xml_set_character_data_handler( $xmlParser, "charElement" );
// Set up character handler
xml_set_character_data_handler( $xmlParser2, "charElement" );
// ********************************************************************************
**********
// Input the URL for XML RSS feed below - any RSS feed should work
// Open connection to RSS XML file for parsing.
$fp = fopen( "adres RSS", "r" ) or
die( "Cannot read RSS data file." );// ********************************************************************************
**********
// Parse XML data from RSS file.
while( $data = fread( $fp, 4096
) ) { xml_parse
( $xmlParser, $data, feof( $fp ) ); }
// ********************************************************************************
**********
// Use this for a second feed
// Open connection to RSS XML file for parsing.
/* $fp2 = fopen( "http://some.second.rss.feed", "r" )
or die( "Cannot read RSS data file." );
// Parse XML data from RSS file.
while( $data2 = fread( $fp2, 4096 ) ) {
xml_parse( $xmlParser2, $data2, feof( $fp2 ) );
}
*/
// ********************************************************************************
**********
// Close file open handler
// ********************************************************************************
**********
// Use this for a second feed
// Close file open handler
/* fclose( $fp2 );*/
// ********************************************************************************
**********
// Free xml parser from memory
xml_parser_free( $xmlParser );
// ********************************************************************************
**********
// Use this for a second feed
// Free xml parser from memory
/* xml_parser_free( $xmlParser2 );*/
// ********************************************************************************
**********
// ********************************************************************************
**********
// Put unsubscribe information here
$GLOBALS['email_body'] .= ('
<br>
</font>
</td>
</tr>
</table></body></html>
');
// ********************************************************************************
**********
echo $GLOBALS['email_body']; // ********************************************************************************
**********
// Add email subjest here, remove date if you want (delete . date("m.d.y") to remove date)
$subject = ' - ' . date("d.m.y"); // ********************************************************************************
**********
// ********************************************************************************
**********
// Add who the email is from
$from = 'OD';
// ********************************************************************************
**********
// ********************************************************************************
**********
// Add store email address here
$from_email = 'OD';
// ********************************************************************************
**********
// IMPORTANT***********************************************************************
**********
// Uncomment this section after testing
$sql = 'SELECT `customers_firstname` , `customers_lastname` , `customers_email_address` '
. ' FROM `customers` '
. ' WHERE `customers_newsletter` = 1';
$name = $row['customers_firstname'] .' '. $row['customers_lastname'];
$email = $row['customers_email_address'];
// IMPORTANT***********************************************************************
**********
// To test change $email to 'store@email.com'
newsletter_mail($name, 'do kogo wyslac', $subject, $GLOBALS['email_body'], $from, $from_email);
// ********************************************************************************
**********
// IMPORTANT***********************************************************************
**********
// Uncomment this section after testing
}
// Function to send out the newsletters
function newsletter_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
if (SEND_EMAILS != 'true') return false;
// Instantiate a new mail object
$message = new email
(array('X-Mailer: SeekShopping Mailer'));
// Build the text version
$text =(email_text);$message->add_html($email_text, $text);
// Send message
$message->build_message();
$message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject, 'od- email ');
}
?>