Module: PHPMailer

rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2009-07-22 23:43

If anyone's interested, I've created a new module called PHPMailer which replaces Gallery's built in Sendmail code with a slightly modified version. Instead of using PHP's built in mail function, this will allow Gallery to send email messages using something called PHPMailer ( http://phpmailer.sourceforge.net/ ). For some reason my web host doesn't have PHP's mail function set up properly, so this fixes that issue for me. I've tested it against my "ContactOwner" module and done some quick testing against the notification module as well, and it appears to work fine. Should anyone run into a problem with it though, let me know.

Also note that this module does not include PHPMailer. You will need to download it from the above web site and install it on your own before setting up this module.

The module may be downloaded from this post, or from my github account at:
http://github.com/rWatcher/gallery3-contrib/tree/master

I've also set up a wiki entry at:
http://codex.gallery2.org/Gallery3:Modules:phpmailer

---
Report Problems/Suggestions Here | Get latest version | Documentation | Coffee Fund | My Library | My GitHub

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Thu, 2009-07-23 18:08

I've pulled this into the contrib repo. Thanks!
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!

 
kenziebug

Joined: 2010-06-01
Posts: 5
Posted: Tue, 2010-06-01 20:40

This is a great module, although having an issue with using it with a gmail/googleapps account. I know in gallery 2, to make it work I had to use tls://smtp.gmail.com|465 as the smtp server. I believe from what I can see in your code, it looks like you are passing the variables in. I have seen posts on google about using phpmailer with gmail, but can't seem to get it to work with this module. If you could provide any guidance that would be great. (by the way i'm running libphp-phpmailer on ubuntu)

Thanks

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Tue, 2011-04-26 00:03

I've just updated this module for use with the new Gallery 3.0 release. It can be found on my github and attached to this post.

 
dmolavi
dmolavi's picture

Joined: 2002-12-05
Posts: 573
Posted: Thu, 2010-10-07 18:47

send a pull request to bharat so he can sync up the main gallery3-contrib repo with it..

--
For Gallery 3 modules and themes, visit GalleryModules.com.
For PHPNuke, phpBB2, and phpBB3 integration help, visit NukedGallery.net.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Fri, 2010-10-08 05:08

Pulled!
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git

 
gpo

Joined: 2008-05-05
Posts: 68
Posted: Fri, 2010-10-08 08:26

I'm abit confussed what this module does & how to set it up!
Is it to upload via email to your gallery or send out email of your uploaded photo!

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2010-10-09 01:25

Neither, from the docs:
"PHPMailer is a module for Gallery 3 which will allow Gallery to use PHPMailer instead of php's built in mail function."

 
blastpit

Joined: 2010-12-06
Posts: 7
Posted: Mon, 2010-12-06 14:43

How I can Setup PHPMailer with GMail?
and
What Is "Location of PHPMailer Class"

 
jjmartinez

Joined: 2010-12-10
Posts: 1
Posted: Fri, 2010-12-10 14:17

Hi,

I've installed phpmailer 5 in htdocs/phpmailer, but, I don't know what is "Location of PHPMailer Class", Do I have to insert "/phpmailer/class.phpmailer.php"? it doesn't work. Do you help me please?

Thanks for all.

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Sun, 2011-01-23 17:34

I am using PHPMailer and I am also using ContactOwner modules. When I try to send an email to the owner I get the follwoing error message:

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. When I reload I get this:

-(
Dang... Something went wrong!

We tried really hard, but it's broken.

Hey wait, you're an admin! We can tell you stuff.

There's an error message below and you can find more details in gallery3/var/logs (look for the file with the most recent date on it). Stuck? Stop by the Gallery 3 Forums and ask for help. You can also look at our list of open tickets to see if the problem you're seeing has been reported. If you post a request, here's some useful information to include:

Platform information

Host name: my.site
Operating system: Linux 2.6.34.7-0.7-desktop
Apache: Apache/2.2.15 (Linux/SUSE)
PHP: 5.3.3
MySQL: 5.1.46-log
Server load: 0.00 0.00 0.00
Graphics toolkit: imagemagick
Gallery stats

Version: 3.0 (Santa Fe)
Albums: 194
Photos: 12735
Kohana_Exception [ kohana/core.errors.403 ]:
@todo FORBIDDEN
MODPATH/gallery/helpers/access.php[ 194 ]

189
190 /**
191 * Terminate immediately with an HTTP 403 Forbidden response.
192 */
193 static function forbidden() {
194 throw new Kohana_Exception("@todo FORBIDDEN", null, 403);
195 }
196
197 /**
198 * Internal method to set a permission
199 *
MODPATH/gallery/helpers/access.php[ 417 ] » access_Core::forbidden()
MODPATH/gallery/libraries/MY_Forge.php[ 42 ] » access_Core::verify_csrf()
MODPATH/forge/libraries/Forge.php[ 164 ] » Forge->validate()
MODPATH/gallery/libraries/MY_Forge.php[ 41 ] » Forge_Core->validate()
MODPATH/contactowner/controllers/contactowner.php[ 112 ] » Forge->validate()
{PHP internal call} » ContactOwner_Controller->sendemail( arguments )
SYSPATH/core/Kohana.php[ 331 ] » ReflectionMethod->invokeArgs( arguments )
{PHP internal call} » Kohana_Core::instance( arguments )
SYSPATH/core/Event.php[ 208 ] » call_user_func_array( arguments )
APPPATH/Bootstrap.php[ 67 ] » Event_Core::run( arguments )
DOCROOT/index.php[ 97 ] » require( arguments )

Any help would be appreciated!

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Mon, 2011-01-24 03:38

I played some more with this, but I still get this error. There is something to do with permissions obviously, but I can't figure out what exactly. Any help would be appreciated.

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Mon, 2011-01-24 15:07

Any help?

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Tue, 2011-01-25 02:22

Did anybody made this work at all?

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2011-06-01 18:51

Here is the lastest version of the PHPMailer module. I have included the fix from ticket 1572 and added support for ssl as requested in ticket 1573.

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Wed, 2011-05-25 18:46

OK. I put it in, provided all the necessary SMTP information, provided the phpmailer path and nothing. Who is using this module and how is it used? Is it working in conjuction with the "contact owner" module or is the contact owner module using it?

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Thu, 2011-05-26 01:41
peshko wrote:
OK. I put it in, provided all the necessary SMTP information, provided the phpmailer path and nothing.

What happens? Do you get an error message, or does the email just not get sent, or something else? Does anything show up in /var/logs?

peshko wrote:
Who is using this module and how is it used? Is it working in conjuction with the "contact owner" module or is the contact owner module using it?

This module allows you to replace Gallery's built in method for sending email messages with PHPMailer. It should work in conjunction with anything that needs to send out an email and has been tested with the Contact Owner, eCard, and Notification modules in conjunction with Gallery 3.0.1.

Explanation of settings --
Location of PHPMailer Class: The server path to the class.phpmailer.php file (which must be installed separately). If you're on a linux server, this should look something like "/path/to/class.phpmailer.php" and if you're on a windows server this should look something like "c:\path\to\class.phpmailer.php".

From Email Address: The email address that messages will be sent from. Some SMTP server's restrict you to only sending mail from a specific address, others will let you send email from any address. Make sure the address that you specify here is valid for use with your server.

From Name: This can be anything. It'll show up on the from line in all email messages that Gallery sends.

SMTP Server Address: A valid smtp server address, ex: smtp.example.com

SMTP Login Name / SMTP Password: The login name and password for the SMTP server, if required.

SMTP Port: The port number, default is 25 for unencrypted servers, and usually either 587 or 465 for encrypted servers, although some smtp servers may use a completely different port number.

Use SSL?: Check this box if you're SMTP server requires encryption (ex: gmail).

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Thu, 2011-05-26 18:40

rWatcher, thanks a lot!

Based on your descritpion I got it configured correct.

The effect is basically nothing gets sent. I checked the /var/log and the only thing I see is in the apache2/access.log:

mylaptop - - [26/May/2011:14:33:30 -0400] "POST /gallery3/index.php/contactowner/sendemail/2 HTTP/1.1" 500 - "http://mygallery/gallery3/index.php/contactowner/emailid/2" "Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"

Firefox gives me an empty screen and in the chrome I get:

Server error
The website encountered an error while retrieving http://mygallery/gallery3/index.php/contactowner/sendemail/2. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this web page later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

Any help would be appreciated!

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Fri, 2011-05-27 04:22

That doesn't really tell me much :( Is there anything in the gallery3/var/logs folder?

Also, do you know what version of PHPMailer you have installed? I did all my testing against 5.1:
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/

There are two files you should have on you're server that come with phpmailer -- class.phpmailer.php and class.smtp.php (there's also a third file that it comes with called class.pop.php, but I think it should work fine if that's missing).

PHP Mailer comes with some test scripts, are you able to use any of them to send test messages (specifically test_smtp_basic.php -- you'll have to manually edit it to specify a mail server and login/password/etc)? That would tell us if php mailer it'self is working properly or not.

 
Od3n

Joined: 2011-05-30
Posts: 2
Posted: Mon, 2011-05-30 09:56

Having a similar issue, no emails being sent for password reset or new user registrations. The web page stops processing (no error is given) and does not progress. The PHP mailer test page generates an email with out error.

official Gallery 3.0.2
PHP Version 5.2.15 php info page http://troy.neven.info/test1.php
PHPMAILER version Version 5.1 (October 20, 2009)
Apache version 2.2.17
cPanel Pro 1.0 (RC1)

Log file message:

2011-05-30 04:27:36 -05:00 --- error: Exception [ 0 ]: @todo SEND_MAIL_FAILED
/home/nevenin1/public_html/troy/modules/phpmailer/libraries/Sendmail.php [ 90 ]
#0 /home/nevenin1/public_html/troy/modules/register/helpers/register.php(103): Sendmail_Core->send()
#1 /home/nevenin1/public_html/troy/modules/register/helpers/register.php(50): register_Core::_sendemail('deleted@neven.info', Object(SafeString), Object(View))
#2 /home/nevenin1/public_html/troy/modules/register/helpers/register.php(91): register_Core::send_user_created_confirmation(Object(Pending_user_Model), '700c4c05c676803...')
#3 /home/nevenin1/public_html/troy/modules/register/controllers/register.php(42): register_Core::create_new_user(5)
#4 [internal function]: register_Controller->handler()
#5 /home/nevenin1/public_html/troy/system/core/Kohana.php(331): ReflectionMethod->invokeArgs(Object(register_Controller), Array)
#6 [internal function]: Kohana_Core::instance(NULL)
#7 /home/nevenin1/public_html/troy/system/core/Event.php(208): call_user_func_array(Array, Array)
#8 /home/nevenin1/public_html/troy/application/Bootstrap.php(67): Event_Core::run('system.execute')
#9 /home/nevenin1/public_html/troy/index.php(102): require('/home/nevenin1/...')
#10 {main}

line 85 of /modules/phpmailer/libraries/Sendmail.php suggests that has some thing to do with the new line separators of the email headers, referring to the this comment in the code:

// The docs say headers should be separated by \r\n, but occasionaly that doesn't work and you
// need to use a single \n. This can be set in config/sendmail.php

Not able to locate config/sendmail.php so I am not sure what to do next.

Any ideas?

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Tue, 2011-05-31 17:19

This is from the smtp_basic. Works great. I receive an email. Settings in the gallery settings and the test file are the same.

SMTP -> FROM SERVER:220 mx.google.com ESMTP m16sm148529qck.40
SMTP -> FROM SERVER: 250-mx.google.com at your service, [71.178.50.63] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK m16sm148529qck.40
SMTP -> FROM SERVER:250 2.1.5 OK m16sm148529qck.40
SMTP -> FROM SERVER:354 Go ahead m16sm148529qck.40
SMTP -> FROM SERVER:250 2.0.0 OK 1306862040 m16sm148529qck.40
Message sent!

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Tue, 2011-05-31 17:37

Forgot to add. I use the PHPMailer version that you specified above.

I still get the error:

The website encountered an error while retrieving http://mygallery/gallery3/index.php/contactowner/sendemail/-1. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this web page later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

I am trying Contact the Owner link.

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2011-06-01 18:56

Here is the latest version of the PHPMailer module. It has been tested against Gallery 3.0.2 and PHPMailer 5.1 and works fine for me.

I've added lots of additional error handling and error logging code to this version. Hopefully if it's still not working there will at least be something useful in the gallery3/var/logs folder to explain what's going wrong instead of just the generic "@todo SEND_MAIL_FAILED".

 
kenziebugtim

Joined: 2006-06-23
Posts: 1
Posted: Wed, 2011-06-01 20:43

Thanks rwatcher. This works great now. The one thing I did encounter that may be tripping some people up is the path to the "class.phpmailer.php. I was getting the blank white screen until I added the "class.phpmailer.php to the end of the path which in my case on ubuntu 10.04 LTS server was the following /usr/share/php/libphp-phpmailer/class.phpmailer.php . Using this it worked perfectly. I did use the libphp-phpmailer version 5.1-5 install from ubuntu repository instead of just downloading it from sourceforge.

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Wed, 2011-06-01 21:26

I think adding class.phpmailer.php at the end was the key. I replaced the module with the new one rWatcher provided, but still got the white empty screen. Once I added "class.phpmailer.php" at the end of the path, everything works as a charm now!

rWatcher I think you should make a note on that.

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Thu, 2011-06-02 03:30

I'm glad it's working now :)

I've updated the codex to mention that class.phpmailer.php must be specified as part of the path.

 
Od3n

Joined: 2011-05-30
Posts: 2
Posted: Sun, 2011-06-05 05:33

My issues were around incorrect SMTP options, the additional logging exposed my stupidity.

Thanks :)

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Sun, 2011-06-05 17:55

Glad it's working for everyone now :)

 
mossienz

Joined: 2011-06-08
Posts: 3
Posted: Wed, 2011-06-08 22:50

I have installed this on my site, and have it working with the test functions, and now contact owner.

However it does not seem to work for the basket module? I cannot determine if this is the basket module or phpmailer causing the issue, as I have never been able to get the mail working from basket.

No errors showing in the log files, and site operates as normal, except without mail being sent.

Any ideas?

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2011-06-08 23:50

Checking...

basket doesn't use gallery's sendmail library, it accesses the php mail function directly. See /modules/basket/helpers, lines 372 and 387:
https://github.com/rWatcher/gallery3-contrib/blob/master/3.0/modules/basket/helpers/basket.php

The author would have to update this module to use Gallery's sendmail function instead of accessing mail directly, similar to what the contact owner modules does around lines 149-155 in modules/contactowner/controllers/contactowner.php:
https://github.com/rWatcher/gallery3-contrib/blob/master/3.0/modules/contactowner/controllers/contactowner.php

 
mossienz

Joined: 2011-06-08
Posts: 3
Posted: Thu, 2011-06-09 00:08

What is the chance of you modifying the module for me so I can get my site up and running - while I request the module be changed?

This is the only thing stopping my site from getting up and running :(

 
HeineDigital

Joined: 2011-06-22
Posts: 2
Posted: Wed, 2011-06-22 02:36

Für alle Benutzer in Deutschland die "HostEurope" als Provider verwenden,
habe ich das Modul von rWatcher angepasst, damit es auch dort funktioniert.

For all Users of HostEurope,
we have edited the file sendmail.php of the modul from rWatcher at line 89-91

Original (sendmail.php)

Quote:
if (!$this->mail($to, $this->subject, $message, $headers)) {
throw new Exception("@todo SEND_MAIL_FAILED");
}

Änderungen/ Changes

Quote:
if (mail($to,$this->subject,$message,$headers, "-f " .$to )){
}else{
throw new Exception("@todo SEND_MAIL_FAILED");
}

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2011-06-22 04:09
HeineDigital wrote:
Änderungen/ Changes

Quote:
if (mail($to,$this->subject,$message,$headers, "-f " .$to )){
}else{
throw new Exception("@todo SEND_MAIL_FAILED");
}

Unless I'm missing something, this change will prevent my PHPMailer module from using PHPMailer. If you want to use PHP's mail function, why not just stick with the default Sendmail.php file at /modules/gallery/libraries/Sendmail.php?

 
HeineDigital

Joined: 2011-06-22
Posts: 2
Posted: Wed, 2011-06-22 04:21
Quote:
Unless I'm missing something, this change will prevent my PHPMailer module from using PHPMailer. If you want to use PHP's mail function, why not just stick with the default Sendmail.php file at /modules/gallery/libraries/Sendmail.php?

The original sendmail.php file don't support SSL

 
psychoph

Joined: 2009-11-15
Posts: 36
Posted: Sat, 2011-09-17 02:32

Anyone getting phpmailer causing them to not be able to create albums? WHen i disable it I go to add an ablum and click create and the page loads. When i enabled PHPmailer and i perform the same actions the page never reloads. The album is created but the page never reloads.

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Sat, 2011-09-17 03:59

Works fine for me with Gallery 3.0.2. What modules do you have installed that use PHPMailer? Maybe it's some kind of issue between PHPMailer and a module I don't have installed.

 
melph

Joined: 2009-02-14
Posts: 12
Posted: Fri, 2012-06-29 15:31

Hi

This might be an obvious question, so apologies in advance.

I am using this plugin as my webhost changed settings prevent php mail from working. However, I have found several modules that need email, don't seem to work. The ones I have found so far are Favorites and Shopping basket.

I know this module is set up and running OK as I can use contact form which uses this module all ok.

Should this module override all other settings and modules that require email just switch to using this module, or is it that these modules are coded just to use php mail functions?

Like I said, probably obvious question but some guidance would be appreciated.

Many thanks

Mark

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Mon, 2012-07-02 18:32
melph wrote:
Hi

This might be an obvious question, so apologies in advance.

I am using this plugin as my webhost changed settings prevent php mail from working. However, I have found several modules that need email, don't seem to work. The ones I have found so far are Favorites and Shopping basket.

I know this module is set up and running OK as I can use contact form which uses this module all ok.

Should this module override all other settings and modules that require email just switch to using this module, or is it that these modules are coded just to use php mail functions?

Like I said, probably obvious question but some guidance would be appreciated.

Many thanks

Mark

This module replaces Gallery's sendmail library with one that's been modified to use phpmailer instead of mail. Any module that relies on Gallery's sendmail library will automatically switch over to phpmailer while this module is enabled.

 
peshko

Joined: 2010-11-22
Posts: 81
Posted: Sun, 2012-07-15 16:23

Recently upgraded to 3.0.4 and started getting an error msg when I try to use sendmail:

Platform information

Host name: gal.site
Operating system: Linux 3.1.9-1.4
Apache: Apache/2.2.21 (Linux/SUSE)
PHP: 5.3.10
MySQL: 5.5.16-log
Server load: 0.03 0.04 0.05
Graphics toolkit: imagemagick

Gallery stats

Version: 3.0.4 (Ricochet)

Exception [ 0 ]: @todo SEND_MAIL_FAILED

MODPATH/phpmailer/libraries/Sendmail.php[ 90 ]
85 // The docs say headers should be separated by \r\n, but occasionaly that doesn't work and you
86 // need to use a single \n. This can be set in config/sendmail.php
87 $headers = implode($this->header_separator, $headers);
88 $message = wordwrap($this->message, $this->line_length, "\n");
89 if (!$this->mail($to, $this->subject, $message, $headers)) {
90 throw new Exception("@todo SEND_MAIL_FAILED");
91 }
92 return $this;
93 }
94
95 public function mail($to, $subject, $message, $headers) {

MODPATH/contactowner/controllers/contactowner.php[ 155 ] » Sendmail_Core->send()
{PHP internal call} » ContactOwner_Controller->sendemail( arguments )
SYSPATH/core/Kohana.php[ 331 ] » ReflectionMethod->invokeArgs( arguments )
{PHP internal call} » Kohana_Core::instance( arguments )
SYSPATH/core/Event.php[ 208 ] » call_user_func_array( arguments )
APPPATH/Bootstrap.php[ 67 ] » Event_Core::run( arguments )
DOCROOT/index.php[ 113 ] » require( arguments )

I have my PHPMailer:

gal:/usr/lib/php5/classes/PHPMailer_v5.1 # ls
LICENSE aboutus.html class.phpmailer.php class.smtp.php examples test
README changelog.txt class.pop3.php docs language

WHat seems to be wrong?

Thanks!

 
xhushito

Joined: 2012-07-18
Posts: 1
Posted: Wed, 2012-07-18 08:10

personally I've had headaches with this issue of the mails ... finally thank you for your answers, do not consider myself a geek hehe ;)

Greetings guys