Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Email Queue 2.0


aodfan

Recommended Posts

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

Grrrr i see now that i didn't make it clear.

The original that's the one i'm using :D

 

yes, the funny thing with osc is that the mail function in admin was apparently written by a different person than the one on the catalog side, they also did not talk to eachother it seems. Hence the many posts about mail working in admin and not in catalog and visa versa.

 

anyway, use this:

 

while ($mail = tep_db_fetch_array($mail_query)) {

if (USE_EMAIL_QUEUE == 'true') {

tep_store_mail($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], $subject, $message , $from, STORE_OWNER_EMAIL_ADDRESS);

} else {

tep_mail($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], $subject, $message , STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

}

//$mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', $from, $subject);

}

 

 

you can keep that other mimemessage stuff in there, comment it out or delete it.

Treasurer MFC

Link to comment
Share on other sites

Very many thanks Amanda will do that tomorrow and let you know of course

 

BTW are you never sleeping ? :D

 

Welterusten to you and your +

 

<grin>

 

John

"If you're working on something new, then you are necessarily an amateur."

Link to comment
Share on other sites

Hi Amanda,

 

works like a dream, but of course you will not be surprised :D

 

Thanks again very very much, your addition is a big improvement.

 

Regards

John

"If you're working on something new, then you are necessarily an amateur."

Link to comment
Share on other sites

  • 2 months later...

this is an absolutely fantastic contribution! (as usual with any of boxtel's work)

saved me from migrating my stock osc newsletter function to the overly bloated phplist

 

to avoid using a cron, is there a 'send all' button that i may have missed?

Link to comment
Share on other sites

nevermind. i read a few pages back and noticed the file :)

 

however, my batch send is blank. i followed the instructions given to devine952 and it's still blank.

 

before i edited the configuration cache line, it got a Sending mails success message; but nothing was updated on the email queue window, nor did i receive the test message.

 

when i hit send manually from the email queue window, i receive the mails & everything's updated

 

i do not receive any errors whatsoever.

i also do not have the configuration cache contribution installed.

 

 

file:

<?php
require('includes/configure.php');
require(DIR_WS_INCLUDES . 'filenames.php');
require(DIR_WS_INCLUDES . 'database_tables.php');
require(DIR_WS_FUNCTIONS . 'database.php');
tep_db_connect() or die('We are currently unavailable due to Maintenance..');
require(DIR_WS_FUNCTIONS . 'general.php');
require(DIR_WS_CLASSES . 'mime.php');
require(DIR_WS_CLASSES . 'email.php');
// set application wide parameters
$configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
while ($configuration = tep_db_fetch_array($configuration_query)) {
define($configuration['cfgKey'], $configuration['cfgValue']);
}
if (HOLD_EMAIL_QUEUE != 'true') {
echo 'Sending Emails from the Queue.....' . "\n";
$mail_qry = "select id,
charset,
to_name,
to_address,
subject,
text,
from_name,
from_address,
created
from email_batch
where (send is null or send = '') and
(hold is null or hold = '')
order by created asc
limit 5";
$email_query = tep_db_query($mail_qry);
while ($email = mysql_fetch_array($email_query)) {
echo 'Sending...' . $email['id'].' '.$email['to_name'].' '.$email['to_address']."\n";
define('CHARSET', $email['charset']);
$send_result = tep_mail(
$email['to_name'],
$email['to_address'],
$email['subject'],
$email['text'],
$email['from_name'],
$email['from_address']);
echo 'result=[';
if ($send_result) {
tep_db_query("update email_batch set send = 'on', last_updated = now() where id = '" . $email['id']. "'");
echo 'OK]'."\n";
} else {
echo 'ERROR]'."\n";
}
}
echo 'Done'."\n";
mysql_free_result($email_query);
}
?>

Edited by eww
Link to comment
Share on other sites

this is an absolutely fantastic contribution! (as usual with any of boxtel's work)

saved me from migrating my stock osc newsletter function to the overly bloated phplist

 

to avoid using a cron, is there a 'send all' button that i may have missed?

 

I did not deem that really necessary as you can simply call email_batch_send.php in your browser to do that but you can add a button like :

 

echo '<td style="background: #f1f9fe; border: 1px solid #A2ABB6;" width="16%" align="center"><a href="' . tep_href_link(FILENAME_EMAIL_QUEUE, 'page=' . $HTTP_GET_VARS['page'] . '&eID=' . $eInfo->id . '&table=' . $_GET['table'] . '&action=send_pending') . '">' . 'Send All Pending' . '</a></td>';

 

that triggers the "send_pending" action and add this to the case:

 

case 'send_pending':

$mail_qry = "select id,

to_name,

to_address,

charset,

subject,

text,

from_name,

from_address,

type,

created

from email_batch

where (send is null or send = '') and

(hold is null or hold = '')

order by created asc

limit 5";

$email_query = tep_db_query($mail_qry);

$emails = tep_db_num_rows($email_query);

while ($email = mysql_fetch_array($email_query)) {

define('CHARSET', $email['charset']);

if ($email['type'] == 'M') $email['text'] = str_replace("\n", "<br>", $email['text']);

$send_result = tep_mail(

$email['to_name'],

$email['to_address'],

$email['subject'],

$email['text'],

$email['from_name'],

$email['from_address']);

if ($send_result) {

tep_db_query("update email_batch set send = 'on', last_updated = now() where id = '" . $email['id']. "'");

}

}

mysql_free_result($email_query);

tep_redirect(tep_href_link(FILENAME_EMAIL_QUEUE, 'page=' . $HTTP_GET_VARS['page'] . '&table=' . $_GET['table']));

break;

 

that will basically do the same as the scheduled job.

Adjust the limit to your needs (php timeout limits).

Treasurer MFC

Link to comment
Share on other sites

that didn't send either. i put your code beneath:

	  case 'reply':
	$this_email_query = tep_db_query("select * from " . $table_in_use . " where id = '" . $_GET['eID'] . "'");
	$this_email = mysql_fetch_array($this_email_query);
	tep_store_mail($this_email['from_name'], $this_email['from_address'], $this_email['subject'], $this_email['text'], $this_email['to_name'], $this_email['to_address'], 'on');
	break;

 

and the html at the very end of the table menu.

 

no errors or anything, no mails were marked as sent and no mails received. the page just refreshed when i clicked "Send All Pending"

Edited by eww
Link to comment
Share on other sites

that didn't send either. i put your code beneath:
	  case 'reply':
	$this_email_query = tep_db_query("select * from " . $table_in_use . " where id = '" . $_GET['eID'] . "'");
	$this_email = mysql_fetch_array($this_email_query);
	tep_store_mail($this_email['from_name'], $this_email['from_address'], $this_email['subject'], $this_email['text'], $this_email['to_name'], $this_email['to_address'], 'on');
	break;

 

and the html at the very end of the table menu.

 

no errors or anything, no mails were marked as sent and no mails received. the page just refreshed when i clicked "Send All Pending"

 

well,

 

go into admin/includes/functions/general.php

 

find in function tep_mail() the statement:

 

$message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);

 

and change that to:

 

return $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);

 

 

then at least the tep_mail function will return its result.

 

then change the case code I gave you to : (only added some messages to check what is happening)

 

case 'send_pending':

$mail_qry = "select id,

to_name,

to_address,

charset,

subject,

text,

from_name,

from_address,

type,

created

from email_batch

where (send is null or send = '') and

(hold is null or hold = '')

order by created asc

limit 5";

$email_query = tep_db_query($mail_qry);

$emails = tep_db_num_rows($email_query);

if ($emails) {

while ($email = mysql_fetch_array($email_query)) {

define('CHARSET', $email['charset']);

if ($email['type'] == 'M') $email['text'] = str_replace("\n", "<br>", $email['text']);

$send_result = tep_mail(

$email['to_name'],

$email['to_address'],

$email['subject'],

$email['text'],

$email['from_name'],

$email['from_address']);

if ($send_result) {

tep_db_query("update email_batch set send = 'on', last_updated = now() where id = '" . $email['id']. "'");

$messageStack->add_session('Email '. $email['id']. ' Send', 'success');

} else {

$messageStack->add_session('Error while trying to send email '. $email['id'], 'error');

}

}

} else {

$messageStack->add_session('Nothing to send', 'error');

}

mysql_free_result($email_query);

tep_redirect(tep_href_link(FILENAME_EMAIL_QUEUE, 'page=' . $HTTP_GET_VARS['page'] . '&table=' . $_GET['table']));

break;

Treasurer MFC

Link to comment
Share on other sites

1054 - Unknown column 'type' in 'field list'

select id, to_name, to_address, charset, subject, text, from_name, from_address, type, created from email_batch where (send is null or send = '') and (hold is null or hold = '') order by created asc limit 5

[TEP STOP]

so i commented out 'type' and tried again... then it was marked sent and i received the mail :D

 

 

thank you for that!

Link to comment
Share on other sites

new question:

 

- when i view the emails in the queue, they are formatted correctly.

 

for example:

hi.

 

how are

you!

^ this is what i want

 

but when i send a test mail to myself, i get:

hi. how are you!

^ this is what i don't want

 

what could i do to keep the linbreaks formatted properly once sent, without having to use html (or is that a last resort?)

Edited by eww
Link to comment
Share on other sites

new question:

 

- when i view the emails in the queue, they are formatted correctly.

 

for example:

 

^ this is what i want

 

but when i send a test mail to myself, i get:

 

^ this is what i don't want

 

what could i do to keep the linbreaks formatted properly once sent, without having to use html (or is that a last resort?)

 

better change this :

 

if ($email['type'] == 'M') $email['text'] = str_replace("\n", "<br>", $email['text']);

 

 

to this:

 

if (EMAIL_USE_HTML) $email['text'] = str_replace("\n", "<br>", $email['text']);

 

 

same here:

 

if (EMAIL_USE_HTML == 'true') {

if ($this_email['type'] == 'M') {

$this_email['text'] = str_replace("\n", '<br>', $this_email['text']);

} else {

$this_email['text'] = str_replace("\n", '', $this_email['text']);

}

}

 

 

I use the type so I can replace \n with <br> for html emails but replace it with nothing for other types of mail like newsletters.

Treasurer MFC

Link to comment
Share on other sites

if i replace:

			   if (EMAIL_USE_HTML == 'true') {
			 $contents[] = array('text' => '' . TEXT_INFO_EMAIL_TEXT . '<br>' . tep_draw_textarea_field('text','soft',150,25, tep_convert_linefeeds(array("\r\n", "\n", "\r"), '<br>', $eInfo->text)));
		   } else {
			 $contents[] = array('text' => '' . TEXT_INFO_EMAIL_TEXT . '<br>' . tep_draw_textarea_field('text','soft',150,25, $eInfo->text));
		   }

 

with

if (EMAIL_USE_HTML == 'true') {
if ($this_email['type'] == 'M') {
$this_email['text'] = str_replace("\n", '<br>', $this_email['text']);
} else {
$this_email['text'] = str_replace("\n", '', $this_email['text']);
}
}

when i go to preview, the body message isn't there... or did i mix something up?

Link to comment
Share on other sites

if i replace:

			   if (EMAIL_USE_HTML == 'true') {
			 $contents[] = array('text' => '' . TEXT_INFO_EMAIL_TEXT . '<br>' . tep_draw_textarea_field('text','soft',150,25, tep_convert_linefeeds(array("\r\n", "\n", "\r"), '<br>', $eInfo->text)));
		   } else {
			 $contents[] = array('text' => '' . TEXT_INFO_EMAIL_TEXT . '<br>' . tep_draw_textarea_field('text','soft',150,25, $eInfo->text));
		   }

 

with

if (EMAIL_USE_HTML == 'true') {
if ($this_email['type'] == 'M') {
$this_email['text'] = str_replace("\n", '<br>', $this_email['text']);
} else {
$this_email['text'] = str_replace("\n", '', $this_email['text']);
}
}

when i go to preview, the body message isn't there... or did i mix something up?

 

that is the wrong position, I meant where the email is send not where it is displayed for editing.

Treasurer MFC

Link to comment
Share on other sites

  • 11 months later...

i noticed if i send too many mails a day, services like hotmail begin filtering my messages.

 

i'm guessing it's because many of the mails contain similar wording and are all from the same email address.. so they trigger some filters.

 

my question:

i want to use something like pull random messages (i guess that would be the rand() command in php?) so that the TO, SUBJECT and message content is entirely different.

 

currently i've only been able to figure out how to sort by email name, id, subject, etc. (i'm not a php wizard :) )

 

how difficult would it be to achieve this?

Link to comment
Share on other sites

  • 1 month later...

Amanda,

 

I am using email queue and all works well and I wanted to include it into my newsletter_products contribution as well but I am also using newsletter visitor as well. This is my code below...

	function send($newsletter_id) {
  $mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");

  $mimemessage = new email(array('X-Mailer: osCommerce bulk mailer'));
  $mimemessage->add_html($this->html_content());
  $mimemessage->build_message();
  while ($mail = tep_db_fetch_array($mail_query)) {
	$mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', EMAIL_FROM, $this->title);
  }

/////Simple Visitor Newsletter
  while ($visitor = tep_db_fetch_array($visitor_query)) {
  $mimemessage->send('Visitor' . ' ' . 'Visitor', $visitor['email'], '', EMAIL_FROM, $this->title);
}
/////Simple Visitor Newsletter

 

How can I change this?

Link to comment
Share on other sites

  • 2 months later...

Hi Amanda,

 

Hoping you can assist in this. I want to hold all newsletters but send all other mail through the system immediately. But I do want it to keep a copy of all mail sent. Will this contribution work for this specifically??

 

I did install it and put Use Email Queue on True and Hold Email on false and it still holds all of it.

Edited by swtnhpy
Link to comment
Share on other sites

doesn't look like boxtel's posted in nearly a year :(

 

maybe someone else knows the answer:

when you have a lot of messages to send (say, many to the same customer) is there a way to randomize the order sent? currently i have it ordered to send by subject alphabetically but this is still sending multiple messages to 1 person in a short period of time.

 

places like hotmail don't seem too fond of this.

Link to comment
Share on other sites

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...