Closed (fixed)
Project:
Examples for Developers
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
27 Jan 2009 at 21:47 UTC
Updated:
1 Dec 2009 at 00:30 UTC
Jump to comment: Most recent file
Hello,
I am going to build a basic email module that will have a form and a submit button. This will only send one email at a time. I find the api example code and 'Learning Drupal 6 module development very confusing.
The people new to Module Development will be able to see how page is created, a form, and how one email is sent.
Hope this will help more people.
chris
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | email_example_365199_21.patch | 10.62 KB | rfay |
| #19 | email_example_365199_19.patch | 10.66 KB | rfay |
| #18 | email_example-d7.patch | 10.63 KB | ilo |
| #16 | email_example_d6_changes_01.diff | 5.07 KB | rfay |
| #16 | email_example_d6_rfay_01.patch | 10.55 KB | rfay |
Comments
Comment #1
dave reidMoving to our new examples module project.
Comment #2
webchickYes freaking please. Ugh.
I'll see if I can whip up something when I finally figure it out. :P
Comment #3
webchickYoink!
I talked this over with ilo and rfay in IRC, and I think this is what we're going to do:
1. Create a simple form that sends an e-mail when submitted. Probably basically take http://drupal.org/node/197122 but clean it way up.
2. Also add a hook_mail_alter() implementation that adjusts an existing mail (maybe the user registration mail or something) to demonstrate that.
I was going to get into defining settings pages to define mail templates, but that's over an beyond just the basic "I need to *&@#ing send a (*&@#ing email" so we'll keep it simple for now.
Some other references:
http://api.drupal.org/api/function/contact_mail/6 seems to be the most non-cracked-out hook_mail() implementation in core.
rfay also posted http://drupalbin.com/12224 as a working example.
Comment #4
webchickOk, here's a first stab at a "simple" example. I wavered on whether to split the form functions into a separate file, but in the end decided it's much easier to grok this when all the code is in one place, and it's hard enough to grok already. :P
I've no idea if the comments here are way overkill or not, but figured I'd err on the side of being overly verbose, since it's real easy to delete text, but not as easy to invent it. ;)
Note that I haven't implemented hook_mail_alter() yet. I'm stuck trying to think of a good use case for it. I was kinda thinking maybe forcing all e-mails to be sent as HTML, but I don't really have time to dig into how to do that.
Oh, btw, I need someone to help test this since I don't have SMTP set up locally. :\
Comment #5
rfayThanks! Long needed!
Comment #6
rfayAnd oh the delight of getting to review a webchick patch. :-)
Comment #7
ilo commentedThanks webchick! :)
rfay, remember, comments no longer than 80 cols, periods at the end! don't let anyone pass!
Comment #8
webchickHahaha. :) Be careful not to go mad with power now, you two! ;)
Comment #9
ilo commentedAs no movement has been here for 4 days I take this and build up a patch in the d6 version for now.
Comment #10
rfayI apologize I haven't reviewed this or others, Ilo - I've been out of town.
On this, it was submitted by webchick, so go ahead and review, revise, and commit when you think it's good.
Comment #11
ilo commentedhere we go.. Still needs review, I've included hook_mail_alter and simpletest code. Have to say.. was too hard to review webchick's submission.. ;)
Comment #12
webchickHaha! I, on the other hand, have no qualms about reviewing your patch! ;)
(This is all meant with the highest degree of respect, btw, and I *really* appreciate you finishing what I started! I just think it's important to be extra nit-picky on these, since they are examples that new developers will learn from. Consistency is key, so that they learn good practices.)
I'm not sure I'd add this here. If anything, stick a sentence or so to the effect of "hook_mail_alter() is yet another example of what can be done with mail API" in the @file section at the top.
I would suggest moving this up further, beneath email_example_mail_send(), so that all of the mail-related stuff is in one "hunk", and all of the non-email stuff comes below. I was thinking we might also want to put a divider of some kind like ///// Supporting functions //// between the two hunks, that so people know that the stuff before that is about mail, and the stuff after it is just set-up.
I would actually move this into the PHPDoc section, since it's about hook_mail_alter() itself, and not the code within.
"example" :)
I'd do "in which the message was built." The current sentence isn't quite proper English.
We should have a summary line of PHPDoc here.
We don't actually put PHPDoc on top of these functions since they are inherited from the base class.
These do not actually get put into t(), since they're not strings that ever need to be translated.
For concatenation, you should use " . " (space on either side) -- this is a new standard added in D7, but I think it makes sense to pre-emptively back-port it.
There's an extra space between email and =
I'm on crack. Are you, too?
Comment #13
ilo commentedHm.. Thank you very much for your comments, Id tried to keep as close to them as possible ;)
So..
- I've detailed that two examples are provided by the email example module in the @file header.
- moved the hook_mail_alter to the email functions hunk.
- included the //// Support functions //// separator.
- Fixed the English grammar (Sorry, this one I can't do better)
- Added the PHPdoc header to the testing class.
- Remove the headers for setUp() and getInfo()
- cross my fingers
:)
Comment #14
ilo commentedOf course, I forgot to mark as nr, can't do that with fingers crossed.
Comment #15
ilo commentedMissed the string issues in the patch, so I've reviewed all the suggestions again. Rerolled. If everybody agree with webchick's suggestions I guess this could be finished so we can start to work on d7 port.
Comment #16
rfayOK, I committed this one to D6 with minor changes (attached). The .diff file shows the items that were changed by me in the commit. The .patch is what was committed in http://drupal.org/cvs?commit=286346
The changes I made:
Now on to D7! Thanks to both of you for the excellent work on this.
Comment #17
webchickWow. Now that's what I call team work! Awesome! I'm so happy to finally have an example for this to give to folks. :D
This Examples project is such a great idea. Thanks so much for your hard work on this, guys! I'll see where else I can contribute here as I come across client needs and/or time.
Comment #18
ilo commentedOh.. tricky part to get this patch file.. my cvs tools conspired against this issue :)
Briefing:
- minor changes for t() (2nd argument should be array() and third argument is now an array with 'langcode' key..
- updated .info file
- signatures to "Implement "
Comment #19
rfayThe test on hook_email_alter fails on this one, although it works fine in a live test.
Email signature successfully verified. Other email_example.test 97 EmailExampleTestCase->testContactForm() FailThe added debug() in the test shows that the signature is not there. It is there on a live test.
I think this one is going to be a core bug. Could you pursue it?
BTW: Only tiny changes in this patch, but I had to recreate the .test file by hand, as the patch was invalid.
THANKS!
Comment #20
ilo commentedI'll not provide a new patch as we both are facing problem for each other files. Just would like to notice you what I've found..
This is a header of the email:
[Content-Type] => text/plain; charset=UTF-8; format=flowed; delsp=yesThis is the body of the email using $this->randomString(128) to generate the body:
s136221k:7cFs_]f.uX*i>*kjzr`S?-^\'f-p8q1x)rGP=O@G(.zFYRB2tQ/|8ot(gK....As long as the string contains random html tags, <, >, and so, a bad-formed html body is transformed by drupal_html_to_text(), and part of the email body (sometimes the signature) is removed as being part of a html tag. The signature is in fact inserted, but gets removed when formatting the message body.
This is a bug (probably a fix should be backported for the testcase of the D6 version) introduced by trying to send bogus html as body of text messages in the testcase. The fix, replace randomStr() with randomName() so no html tags are used in the body.
Can you fix that yourself in your own local copy and do some tests before committing, I did verify this with a change in the testcase to send 1000 emails using randomName() (0 errors) and randomStr() ~30% of messages fail.
Thanks for the review, rfay!
Comment #21
rfayCommitted the attached to head http://drupal.org/cvs?commit=289908
Thanks for the nice work on this.
Let's follow up on the issue you correctly described in #20.
Comment #22
ilo commentedThanks rfay!
The issue is #634618: email body gets truncated on character '<' followed by any special tag: example <b .