Closed (fixed)
Project:
SMTP Authentication Support
Version:
6.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
11 Jul 2008 at 22:02 UTC
Updated:
25 Aug 2008 at 16:03 UTC
Hi All,
I just installed 6.x-1.x-dev on my Drupal 6.3 site and got the SMTP module working. It will send a test email to me fine. But how do I get other modules to use SMTP. Specifically, I need to get the Webforms module to use SMTP, which is why I downloaded this module. It appears that the webforms module still uses the mail() function.
I have SMTP enabled in admin/build/modules, and it is turned on in settings/smtp.
Thanks in advance for your help.
Comments
Comment #1
jcwatson11 commentedI just posted this issue in the Webform support area also for visibility and perhaps a faster answer depending on who might have the answer. Here's the link to the webform support issue: http://drupal.org/node/281604
Comment #2
oadaeh commentedIf the module is enabled, it should work for all messages.
Did you get an error message in your logs (admin/logs/watchdog)?
Comment #3
LukeLast commentedThis problem sounds familiar.
http://drupal.org/node/132892
Comment #4
jcwatson11 commentedThere are 2 messages, but I don't know what they mean, or what I should change. Here they are. Note that I have changed the domain and email address for security.
#1
Type: smtp
Message: Error sending e-mail from "www.domain.com" to user@domain.com: Language string failed to load: from_failed"www.domain.com"
Severity: error
#2
Type: mail
Message: Error sending e-mail (from "www.domain.com" to user@domain.com).
Severity: error
Comment #5
jcwatson11 commentedOkay, I found the answer to this particular error. But it still doesn't work. There's a new error now.
Solution to previous error: Language file not found in class.phpmailer.php. Once I forced PHPMailer to find the en language file, that error went away, but the form still wouldn't send. The new error is:
I think this has to do with an inconsistency between what webforms is providing as a FROM, and what SMTP exects to see as a FROM in the last parameter of drupal_mail() function... still working to resolve... but its getting late and I need sleep. If anyone else wants to take a look, it appears that in my case, the webforms module sends the email on line 1770 of webform.module (current release as of this writing). The FROM value submitted in my case is in the format
which is actually SMTP standard. But for some reason it's not working. When I look at smtp.module, starting on line 285 (yesterday's dev snapshot), I see that SMTP appears to be pulling information from the headers instead of using the FROM value submitted as one of the drupal_mail parameters.
Maybe it would be a good idea to have SMTP check to see if a from address is present in the list of arguments proper before pulling data from the headers array which may not have a FROM if the caller assumes it will use the FROM argument from drupal_mail() call.
Comment #6
oadaeh commented@jcwatson11: that's interesting that you got that language error. What did you do to force PHPMailer to find the language file? I'm guessing you got that error because the $mail object was not being set correctly, probably because not all the data was available and/or not in the correct locations. I believe the information below fixes that.
I uncommented two function calls that set the from name and e-mail address. I had meant to verify if they were needed or not, but hadn't had an opportunity to do so. I guess I can assume they are needed in certain situations, so I'll leave them in.
The change was submitted here: http://drupal.org/cvs?commit=127023. If you want to just try what you have w/o waiting for a new release, just uncomment the two lines at about 273 that read:
Let me know if this fixes your problem and allows Webform to work correctly.
Comment #7
jcwatson11 commented> What did you do to force PHPMailer to find the language file?
I don't think my PHP Path is set up properly for PHP to find the language file quite right. Just to prove it was the language file I added the SetLanguage PHPMailer command line to smtp.module right after the following line in drupal_mail_wrapper() (smtp.module file). So the code looks like this:
As the architect, if you would like to completely avoid that problem in the future, you could probably do something similar on that line, but get the drupal language setting also. I'm not sure how you would do that. I don't know if the global $language variable is in context at that point in the code's execution, but you probably know more about that than I do.
Regarding the FROM issue, I uncommented the lines you mentioned and the submission went through fine. So that worked. I'm glad you drew my attention to those commented lines. Thanks! And it makes sense to me, looking at your regular expression that that's what should happen, because 2 lines down you have:
If $from was a standard SMTP formatted email address with a name, like "Name" <email@address.com>, then with those lines commented, your rewriting it to be "Name" <"Name" <email@address.com>>.
I think you should do a preg_match to see what format the $from value is in before using those 2 lines. If the email address is in the format "/^"\w+" <.*>$/", then those two lines should be used, if its in the format "/^<.+>$/" or the format of a regular email address, then they shouldn't.
I think there are really only those possibilities... and I haven't tested those regexes. Their just off the top of my head, so they may need to be tweaked.
Thanks for your help!
Comment #8
jcwatson11 commentedOkay, here's my recommended fix:
inside drupal_mail_wrapper(), I replaced these lines:
with these lines:
2 suggestions are:
1. Allow the admin to set the valid email regex through the admin panel. (Don't know how to do that or I would post code for that too.)
2. Write the code to throw an error if the email recipient doesn't match... A better place to throw an error would be any place the email address is entered. But since the SMTP module probably can't control other modules where email addresses can be entered, that might not be practical without some global logic to validate email addresses inside drupal. So I'm not sure where we would go with that.
Comment #9
jcwatson11 commentedChanging status to patch (code needs review).
Comment #10
oadaeh commentedSorry for not getting back to you sooner. I had other things pop up that have kept me away for the last few days.
I hadn't planned on doing anything quite as elaborate as what you have proposed, and before I got busy elsewhere, I had already written the code I was going to use, but hadn't tested it. I'll try to get that done and submitted this morning, as there are lingering problems that need to be addressed. Also, there's a Drupal API function that does much of what you are proposing: http://api.drupal.org/api/function/valid_email_address, so I don't really need to go that far.
Comment #11
oadaeh commentedOkay, I've submitted the changes to the HEAD and DRUPAL-6--1 branches that should take care of this bug.
Comment #12
jcwatson11 commentedThat's great news! It pays to know the API, doesn't it!
Thanks for your help, and for letting me participate. :o)
Comment #13
oadaeh commentedI'm marking this as fixed, since there have been no follow ups to the contrary. :^)
Comment #14
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.