Author Topic: [MOD] - HTML Email  (Read 28668 times)

0 Members and 1 Guest are viewing this topic.

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
[MOD] - HTML Email
« on: September 15, 2007, 08:46:33 PM »
Detail: This send HTML email to users. This topic is use with other MOD I post (no work with MSN).

Use ZIP file attachment. Upload content to includes/html_email (create folder).

Here is test PHP script for 4images. Is send 3 last upload image of gallery and to all admin (allow email accept - if no -  no send).

// Step 1

In ROOT_PATH, create file: mail-client.php file.

Add:

Code: [Select]
<?php

define
('ROOT_PATH''./');
include(
ROOT_PATH 'global.php');
require(
ROOT_PATH 'includes/sessions.php');
@include_once(
ROOT_PATH 'includes/page_header.php');

if (
$user_info['user_level'] == ADMIN) {
    
    
$sql "
    
    SELECT image_id, image_name, cat_id, image_media_file
    FROM " 
IMAGES_TABLE "
    WHERE image_active = 1 AND (cat_id NOT IN ("
.get_auth_cat_sql("auth_viewimage""NOTIN").", ".get_auth_cat_sql("auth_viewcat""NOTIN")."))
    ORDER BY image_date DESC
    LIMIT 2
    
    "
;
    
    
$result $site_db->query($sql);
    
    @include_once(
ROOT_PATH 'includes/html_email/MAIL.php');
    
    
// get ID value (random) for the embed image
    
$id MIME::unique();
    
    
$site_email = new MAIL;
    
    
$image_url "";
    while (
$image_row $site_db->fetch_array($result)) {
        
$image_url .= preg_replace("/" $site_template->start "image_url" $site_template->end "/siU"format_url($script_url '/details.php?image_id=' . (int)$image_row['image_id']), $lang['latest_image_by_email_message_url']);
        
        
$f ROOT_PATH 'data/media/' $image_row['cat_id'] . '/' $image_row['image_media_file'];
        
$site_email->Attach(file_get_contents($f), FUNC::mime_type($f), nullnullnull'inline'$id);
    }
    
    
$sql1 "
    
    SELECT " 
get_user_table_field("""user_name") . get_user_table_field(", ""user_email") . "
    FROM " 
USERS_TABLE "
    WHERE " 
get_user_table_field("""user_level") . " >= '" ADMIN "' AND " get_user_table_field("""user_allowemails") . " = 1 AND " get_user_table_field("""user_id") . " != 1";
    
    
$result1 $site_db->query($sql1);   
    
    
$site_email->From($config['site_email'], format_text($config['site_name'], 2));
    
$site_email->AddTo($user_info['user_email'], format_text(trim($user_info['user_name']), 2));

    
$email_row = array();
    while (
$row $site_db->fetch_array($result1)) {
        
$email_row[] = $row;
    }
    
$site_db->free_result($result1);
    
$num_email sizeof($email_row);    
    
    
$user_email "";
    
$user_name "";
    for (
$i 0$i $num_email$i++) {
        if (
FUNC::is_mail($email_row[$i][$user_table_fields['user_email']], true) && !preg_match("/[\msn]/i"$email_row[$i][$user_table_fields['user_email']])) {            
            
$user_email .= $email_row[$i][$user_table_fields['user_email']] . ", ";
            
$user_name .= $email_row[$i][$user_table_fields['user_name']] . ", ";
        }
    }
    if (isset(
$user_name) && !empty($user_name) && isset($user_email) && !empty($user_email)) {
        
$user_name_sub substr($user_name0strlen($user_name) -2);
        
$user_email_sub substr($user_email0strlen($user_email) -2);    
    
    
$site_email->Cc[] = array(
            
'address'  => stripslashes($user_email_sub), // required
            
'name'     => format_text(trim($user_name_sub), 2), // optional
            
'charset'  => $lang['charset'], // optional
            
'encoding' => 'base64' // optional
    
);
    
$site_email->Subject('Latest image');
    }

@include_once(
ROOT_PATH 'lang/' $config['language_dir'] . '/html_email/my_template.php');
$site_email->Html($email_template);
echo 
$site_email->Send('client') ? $lang['latest_image_by_email_sent'] : $lang['latest_image_by_email_error'];
$site_email->Delto();
$site_email->Delcc();
$site_email->DelAttach();
$site_email->Disconnect();
unset (
$email_row);
unset (
$image_url);
unset (
$user_name);
unset (
$user_email);

}
@include_once(
ROOT_PATH 'includes/page_footer.php');
?>


// Step 2

In lang/english folder, create folder: html_email . Create file: my_template.php (yes, is true filename for test - no replace to real template name).

Add:

Code: [Select]
<?php

if (!defined('ROOT_PATH')) {
    die (
'Security violation.');
}

$email_template stripslashes('

<html>
<body bgcolor="#FFFFFF" text="#0F5475" link="#0F5475" vlink="#0F5475" alink="#0F5475">
<br />
      <table width="640" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td colspan="4"><img src="' 
$script_url '/' TEMPLATE_PATH '/images/header_top.gif" width="640" height="6" alt="" /></td>
        </tr>
        <tr> 
          <td width="6"><img src="' 
$script_url '/' TEMPLATE_PATH '/images/header_left.gif" width="6" height="60" alt="" /></td>
          <td width="405"><img src="' 
$script_url '/' TEMPLATE_PATH '/images/header_logo.gif" width="405" height="60" alt="" /></td>
          <td width="225" align="right">&nbsp;</td>
          <td align="right" width="6"><img src="' 
$script_url '/' TEMPLATE_PATH '/images/header_right.gif" width="6" height="60" alt="" /></td>
        </tr>
      </table>          
      <table width="640" border="1" cellspacing="1" cellpadding="0">
      <tr>           
      <td width="450" align="center"><font color="green"><br />Dear ' 
format_text(trim($user_info['user_name']), 2) . ',<br /><br />
      We now present you the latest upload image in gallery: <b>' 
format_text($image_info['image_name'], 2) . '</b><br /><br />
      ' 
$image_url '<br /><br /></font></td>
      </tr>
      </table>
      <table width="640" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="6"><img src="' 
$script_url '/' TEMPLATE_PATH '/images/footer_left.gif" width="6" height="19" alt="" /></td>
          <td width="405">&nbsp;</td>
          <td width="225">&nbsp;</td>
          <td width="6"><img src="' 
$script_url '/' TEMPLATE_PATH '/images/footer_right.gif" width="6" height="19" alt="" /></td>
        </tr>
      </table>
      
      <p id="copyright" align="center">
      Powered by <b>4images</b> v1.7.4
      <br />
      Copyright &copy; 2002-2007 <a href="http://www.4homepages.de" target="_blank">4homepages.de</a>
      </p>
</body>
</html>

'
);
?>


// Step 3

In lang/english/main.php file,

add top ?>:

Code: [Select]
$lang['latest_image_by_email_message_url'] = "Go see <a href=\"{image_url}\">here</a><br />";
$lang['latest_image_by_email_sent'] = "Email sent !";
$lang['latest_image_by_email_error'] = "Error while sending email. Please check mail / web logs (cPanel access) and post in 4homepages.de forum - official topic - if need help.";

Should work. ;)
« Last Edit: September 16, 2007, 06:05:05 PM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - HTML Email
« Reply #1 on: September 16, 2007, 04:00:57 PM »
/* Fix */

Step 1 fix (less server use for CC emails) - [09/16/2007].
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline ClickyMouse

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] - HTML Email
« Reply #2 on: January 28, 2008, 12:14:04 AM »
And how do I use this?

Do I have to configure anything? Like my username or password or SMTP Server?

Thanks!!! :wink:

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - HTML Email
« Reply #3 on: January 28, 2008, 12:15:32 AM »
Quote
Do I have to configure anything? Like my username or password or SMTP Server?

Yes. In ZIP package (1st post - attach file at footer). See : examples/relay.php file. You see Gmail example (e.g) with TLC protocol. ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline ClickyMouse

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] - HTML Email
« Reply #4 on: January 28, 2008, 12:22:21 AM »
Thanks! I've used that example with my own settings, and the email have been send excellently.

But... How can I integrate it with 4images? So the Registration, E-Cards, and all that get send?

Thanks! (And sorry, but I don't know too much about programming, you rock!) :D

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - HTML Email
« Reply #5 on: January 28, 2008, 12:25:00 AM »
Quote
But... How can I integrate it with 4images? So the Registration, E-Cards, and all that get send?

Test email first with example. If is work (and you see test email in inbox of Gmail) - is possible for integrate.
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline ClickyMouse

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] - HTML Email
« Reply #6 on: January 28, 2008, 12:30:09 AM »
Yes, I've tested with the example file.

I've putted my own email address, and a recipient, and the mail has been sended succesfully:
Quote
Subject:test
Message:Text message.
Sender:webmaster@gruposcout508.com.ar (It's a GMail box)

Now? What I have to do, to integrate it with 4Images?

Thank you so so so so much!

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - HTML Email
« Reply #7 on: January 28, 2008, 12:32:02 AM »
Quote
and the mail has been sended succesfully

Yes, is send but you check in inbox of Gmail account for see if message get ?
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline ClickyMouse

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] - HTML Email
« Reply #8 on: January 28, 2008, 12:35:52 AM »
Here you got, I've attached the message that arrives to my other email (hd.clickymouse at gmail.com)

Directly sended from the code in examples/smtp-relay.php

See ya!

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - HTML Email
« Reply #9 on: January 28, 2008, 12:37:56 AM »
Yes, I know is send but I ask if you see message inside Gmail inbox account for receive:|
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline ClickyMouse

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] - HTML Email
« Reply #10 on: January 28, 2008, 12:57:37 AM »
Do you mean this?

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - HTML Email
« Reply #11 on: January 28, 2008, 01:00:38 AM »
Yes, this is right. :)

Now, I check for add smtp-relay in 4images. First post is say mail.php for include but no smtp-relay.
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline ClickyMouse

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] - HTML Email
« Reply #12 on: January 28, 2008, 01:12:57 AM »
 :wink:
I'll wait for that, hope you can make it!

Thanks!

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - HTML Email
« Reply #13 on: January 28, 2008, 01:30:23 AM »
// Step 1

Create a file call mail-client.php file (in ROOT_PATH).

Add:

Code: [Select]
<?php

define
('ROOT_PATH''./');
include(
ROOT_PATH 'global.php');
require(
ROOT_PATH 'includes/sessions.php');
@include_once(
ROOT_PATH 'includes/page_header.php');

if (
$user_info['user_level'] == ADMIN) {
    
// path to 'SMTP.php' file from XPM4 package
require_once (ROOT_PATH 'includes/html_email/SMTP.php');

$f = (stripslashes(trim($config['site_email']))); // from (Gmail mail address)
$t = (stripslashes(trim($config['site_email']))); // to mail address
$p = (stripslashes(trim($config['use_smtp_relay_password']))); // Gmail password

// standard mail message RFC2822
$m 'From: '.$f."\r\n".
         
'To: '.$t."\r\n".
         
'Subject: test'."\r\n".
         
'Content-Type: text/plain'."\r\n\r\n".
         
'Text message.';

// connect to MTA server (relay) 'smtp.gmail.com' via SSL (TLS encryption) with authentication using port '465' and timeout '10' secounds
// make sure you have OpenSSL module (extension) enable on your php configuration
$c SMTP::connect('smtp.gmail.com'465$f$p'tls'10) or die(print_r($_RESULT));

// send mail relay
$s SMTP::send($c, array($t), $m$f);

// print result
if ($s) echo 'Sent !';
else 
print_r($_RESULT);

// disconnect
SMTP::disconnect($c);

}
@include_once(
ROOT_PATH 'includes/page_footer.php');
?>


// Step 2

In admin/settings.php file,

find:

Code: [Select]
function show_account_activation_options($setting_name, $setting_value) {
  global $account_activation_optionlist;
  foreach ($account_activation_optionlist as $key => $val) {
    echo "<input type=\"radio\" name=\"setting_item[".$setting_name."]\" value=\"$key\"";
    if ($setting_value == $key) {
      echo " checked=\"checked\"";
    }
    echo "> ".$val."<br />";
  }
}

add after:

Code: [Select]
function show_smtp_relay_password($setting_name, $setting_value) {
  global $smtp_relay_password_optionlist;
  foreach ($smtp_relay_password_optionlist as $key => $val) {
    echo "<input type=\"radio\" name=\"setting_item[".$setting_name."]\" value=\"$key\"";
    if ($setting_value == $key) {
      echo " checked=\"checked\"";
    }
    echo "> ".$val."<br />";
  }
}

find:

Code: [Select]
show_setting_row("smtp_password");

add after:

Code: [Select]
show_setting_row("use_smtp_relay_password");

// Step 3

In lang/english/admin.php file,

find:

Code: [Select]
$setting['smtp_password'] = "SMTP password";

add after:

Code: [Select]
$setting['use_smtp_relay_password'] = "SMTP Relay Password (if have)";

// Step 4

In SQL Patches,

use (1 time):

Code: [Select]
INSERT INTO `4images_settings` (setting_name, setting_value) VALUES('use_smtp_relay_password', '');

// Is work:

ACP - > Setting - > SMTP Relay Password (if have) . Type password. After, try email with mail-client.php file and see if work. ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline ClickyMouse

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] - HTML Email
« Reply #14 on: January 28, 2008, 11:17:19 PM »
I't doesn't work yet :S

Here you can check it: http://gruposcout508.com.ar/fotos/mail-client.php

Thanks!