PHP Classes

example page or implementation

Recommend this page to a friend!

      Extended PHP Mailer  >  All threads  >  example page or implementation  >  (Un) Subscribe thread alerts  
Subject:example page or implementation
Summary:looking for some help or an example of how the php mailer works
Messages:10
Author:Dubliner
Date:2005-05-19 15:08:53
Update:2005-05-21 17:51:44
 

  1. example page or implementation   Reply   Report abuse  
Picture of Dubliner Dubliner - 2005-05-19 15:08:53
Hi ..

This sounds like a very interesting php class. I'm new to php and was wondering of there is an example of it working somewhere...it's not clear to to use the class.

do I simply setup a html web form to gather the to, name, from, subkect, body etc. fields and pass it to the php?

Any help or pointers appreciated..

DUb


  2. Re: example page or implementation   Reply   Report abuse  
Picture of Vagharshak Tozalakyan Vagharshak Tozalakyan - 2005-05-20 09:03:53 - In reply to message 1 from Dubliner
Hi DUb,

Extended PHP Mailer only expands the features of standard mail() function allowing to add attachments, change encoding, handle message templates, etc. It can be used in the same situations where the mail() function can be used.

From where to take values of properties depends on a concrete task you are going to solve. Sure you can use variables received from HTML form.
As you likely have noticed the file "help.txt" contains some samples of a code using the class and description of its properties and methods.

If you tell me for the decision of which task you wish to use the class, maybe I can help you with more concrete answer.

Best wishes,
Vagharsh

  3. Re: example page or implementation   Reply   Report abuse  
Picture of Dubliner Dubliner - 2005-05-20 10:21:27 - In reply to message 2 from Vagharshak Tozalakyan
Hi Vagharsh,

thanks for responding so quickly.

I'm trying to update a drupal module called mail.module that already exists at the www.drupal.org site (it's a free open source PHP based community & content management system).

At the moment the mail.module (php) only sends a text mail with no attachments. So I'm doing my best to try and add an "attachment" feature to it.

the modules for drupal are developed voluntarily and the guy who created the mail.module is too busy doing other stuff and I was simply having a bash at doing it myself - my php skills are very limited.

I thought I could call your extended php mailer class from his php module and pass the variables from his mail.module across.

i.e.

Step 1: if the mail has an attachment run the extended_mail function

Step 2: the extended_mail function includes the extendedphpmailer.class and the correct variables are passed across from the mail.module to send the mail with an attachment.

Step 3: if the mail does NOT have an attachment run the normal send_mail function.

Apologies in advance if that is a stupid suggestion..but I'm very new to php and am teaching myself.

Dub


  4. Re: example page or implementation   Reply   Report abuse  
Picture of Vagharshak Tozalakyan Vagharshak Tozalakyan - 2005-05-20 18:04:50 - In reply to message 3 from Dubliner
Hmm... it seems drupal code a little bit confusing:) isn't it? ... Unfortunately I have not enough free time to investigate it now. You can get a sample of a form that sends attached e-mails from here: http://vagh.armdex.com/formsample.zip, maybe it will appear useful to you..?

p.s. is it better to hack user_mail() function in "user.module" to avoid some kind of ambiguity?

  5. Re: example page or implementation   Reply   Report abuse  
Picture of Dubliner Dubliner - 2005-05-20 18:26:20 - In reply to message 4 from Vagharshak Tozalakyan
Thanks Vagharshak,

You're right the (drupal) code is hard to understand.
Will have a look at the user.module and see if hacking that is an option.
thanks for the tip. I will post a mesage back up here if I have any success and it's of interest to others.

That link for the sampleform.zip gave me a 404 by the way.

Can you repost the link again?

Cheers

Dub


  6. Re: example page or implementation   Reply   Report abuse  
Picture of Vagharshak Tozalakyan Vagharshak Tozalakyan - 2005-05-20 21:15:12 - In reply to message 5 from Dubliner
please try agian the same link after 1-2 hours

  7. Re: example page or implementation   Reply   Report abuse  
Picture of Vagharshak Tozalakyan Vagharshak Tozalakyan - 2005-05-21 07:49:29 - In reply to message 5 from Dubliner
Hi again,

As you see I've make some changes to my mail sending class. Now it is possible
to construct the body and headers of message without sending message. There is
no more need to make changes in "user.module", all you need is to upload
attachments to the server and change following lines in _mail_send() function
of "mail.module".

...
while ( $account = db_fetch_object ( $result ) )
{
if ( $account->mail )
{
$variables = array (
'%username' => $account->name,
'%site' => variable_get ( 'site_name', 'drupal' ),
'%uri' => $base_url,
'%uri_brief' => substr ( $base_url, strlen('http://' ) ),
'%mailto' => $account->mail,
'%date' => format_date ( time ( ) ),
'%login_uri' => url ( 'user/login', NULL, NULL, TRUE ),
'%edit_uri' => url ( 'user/edit', NULL, NULL, TRUE )
);
$message = strtr ( $node->body, $variables );

if ( is_array ( $attaches ) && count ( $attaches ) > 0 )
{
require_once ( 'xmailer.call.php' );
$xmailer = new XPhpMailer ( );
$xmailer->addr = $account->mail;
$xmailer->subject = $node->title;
$xmailer->attachments = $attaches;
$xmailer->msg = $account->mail;
$xmailer->is_html = FALSE;
$xmailer->extra_headers = $headers;
$boundary = '';
$headers = $xmailer->ConstructHeaders($boundary, $xmailer->cb_base);
$message = $xmailer->ConstructMsgBody($boundary, $xmailer->cb_base);
unset ( $boundary );
unset ( $xmailer );
}

user_mail($account->mail, $node->title, $message, $headers);
}
}

  8. Re: example page or implementation   Reply   Report abuse  
Picture of Dubliner Dubliner - 2005-05-21 12:14:18 - In reply to message 7 from Vagharshak Tozalakyan
Hiya....

many thanks for the tips. I'm learning a lot.

Quick questions if you have the time,

Question 1:

I'm getting the following error message:
"warning: convert_cyr_string(): Unknown destination charset: in xmailer.class.php on line 194."

Assume it has something to do with the cyrillic character set thing...I've tried removing that function, but that breaks the class. Is there a way I can get the php to ignore it?


Question 2

haven't got to the stage where I insert the attachment. Do i just paste the text you mentioned exactly or do I need to edit anything?


Thanks agaion for your help. I'm learning a lot by trying to get this working.


Dub




  9. Re: example page or implementation   Reply   Report abuse  
Picture of Vagharshak Tozalakyan Vagharshak Tozalakyan - 2005-05-21 17:18:59 - In reply to message 8 from Dubliner
1) Try to write $xmailer->cp_base instead of $xmailer->cb_base :)) I think it will solve a problem... :) if not - simply disable warnings with '@': "@convert_cyr_string(...)" I don't test previous code, it was written "on the fly" just to show the scheme of possible solution, that's why there could be errors.

2) As I already spoke, I did not study the program source, therefore I can not tell particularly what steps you need to perform to handle file uploads... You can get ideas on how to change the old HTML form from the sample I've posted above.

p.s. sorry for my not so clear English, I speak Russian and native Armenian more good :)

  10. Re: example page or implementation   Reply   Report abuse  
Picture of Dubliner Dubliner - 2005-05-21 17:51:44 - In reply to message 9 from Vagharshak Tozalakyan
thanks for responding so quickly..

I didn't realise the php wasn't tested. Am having too many problems with it so I have asked the guy who originally did the mail.module I mentioned to see if he can help.

Thanks anyway for your help. I will post back up here if I find a solution that works.

By the way, I maybe wrong, I'm not an expert, but I think that the headers are being inserted twice in the email in the ConstructHeaders function which is creating problems when the email is sent.

I was testing the HTML side of the script without the attachment option and it wouldn't work properly. It would send the email, but the email didn't show up properly in different email programmes. Worked fine for just plain/txt emails. But not with the is_html=TRUE option switched on.

Just thought I'd mention it in case others are trying to using it.

Talk later

Dub