4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: thunderstrike 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:
<?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), null, null, null, '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_name, 0, strlen($user_name) -2);
$user_email_sub = substr($user_email, 0, strlen($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:
<?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"> </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"> </td>
<td width="225"> </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 © 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 ?>:
$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. ;)
-
/* Fix */
Step 1 fix (less server use for CC emails) - [09/16/2007].
-
And how do I use this?
Do I have to configure anything? Like my username or password or SMTP Server?
Thanks!!! :wink:
-
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. ;)
-
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
-
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.
-
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:
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!
-
and the mail has been sended succesfully
Yes, is send but you check in inbox of Gmail account for see if message get ?
-
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!
-
Yes, I know is send but I ask if you see message inside Gmail inbox account for receive ? :|
-
Do you mean this?
-
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.
-
:wink:
I'll wait for that, hope you can make it!
Thanks!
-
// Step 1
Create a file call mail-client.php file (in ROOT_PATH).
Add:
<?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:
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:
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:
show_setting_row("smtp_password");
add after:
show_setting_row("use_smtp_relay_password");
// Step 3
In lang/english/admin.php file,
find:
$setting['smtp_password'] = "SMTP password";
add after:
$setting['use_smtp_relay_password'] = "SMTP Relay Password (if have)";
// Step 4
In SQL Patches,
use (1 time):
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. ;)
-
I't doesn't work yet :S
Here you can check it: http://gruposcout508.com.ar/fotos/mail-client.php (http://gruposcout508.com.ar/fotos/mail-client.php)
Thanks!
-
You login in ADMIN level for test ? If you post URL, is why is no work - I no can test this axcept if admin. ;)
-
So... I should login as Admin first, for example on the Admin Control Panel, and then, paste the mail-client link on the address bar?
Thanks!
-
So... I should login as Admin first
This is right. You need login in ADMIN level. After, you test this. No need for post URL (rename file for safety). ;)
-
Nice, now it says "Sent!", and it's on my InBox on GMail.
But when I try to Send an EMail from 4Images, for example on ACP>Users>Send Mail, it gives me an error message.
Do I have to make some more configuration?
Thanks!
-
Do I have to make some more configuration?
Yes, this is right. You need know for this to work ... is no possible for use tags in email with HTML ... (e.g: register_vars) . I no get how for integrate TLS in Jan class (includes/email.php) . I no this good. :|
If ok for replace admin/email.php file for TLC block I post day before, I say how but you no can use tags with this MOD ...
-
Sorry, but my english is not very good...
I didn't understand what you were trying to explain...
Could you explain it again?
Thanks!! :D
-
My english is no good too. Sorry.
-
I should rename mail-client.php to email.php, and replace it on admin/email.php?
Thanks!
-
No. 8O
I just check code (both) and I think is possible for use the two (includes/email.php and SMTP OpenSSL). I need time for check this.