Email versturen (Drupal): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 80: Regel 80:
 
* nail()
 
* nail()
 
* Swiftmailer
 
* Swiftmailer
* PHPMailer eventueel icm. de Drupal SMTP-module
+
* Drupal SMTP-module ivm. PHPMailer.
  
Maar hoe integreer je dit met Drupal of Übercart?
+
Deze laatste mogelijkheid, blijkt een goede oplossing te zijn. Zie [[SMTP-module (Drupal)]] voor details.
  
== Externe SMTP-server gebruiken: SMTP-module + PHPMailer ==
+
== Zie ook ==
  
Dit lijkt de meest voor de handliggende oplossing te zijn. Zie verderop onder ''casussen'' voor restultaten.
+
* [[SMTP-module (Drupal)]]
 
 
== Casus mei 2012: Storing order-notificatie-e-mails (Drupal 6) ==
 
 
 
Dit betreft een storing waarbij de foutmelding gemeld werd.
 
 
 
{|
 
| [[File:E-mailfoutmeldingUbercart.png|thumb|In mei 2012 kreeg ik deze foutmelding, terwijl e-mails wel degelijk verstuurd werden]]
 
| [[File:E-mailfoutmelding2Ubercart.png|thumb|En dit is een bijbehorende logboekvermelding. Hier lijkt het e-mailadres van de ontvanger te ontbreken]]
 
| [[File:E-mailfoutmelding3Ubercart.png|thumb|De oplossing: Normaal staat op de regel ''E-mail admin checkout notification'' een link ''reset''. Door deze te klikken is het probleem verdwenen]]
 
|}
 
 
 
== Casus nov. 2012: Geen email na klonen webwinkel (Drupal 6 & Übercart) ==
 
 
 
Zie beschrijving in een eerder hoofdstuk.
 
 
 
== Casus april 2015: Geen email na migratie (Drupal 6 & Übercart) ==
 
 
 
Dit probleem trad op na migratie van een Übercart-site naar een eigen VPS icm. een Email-Only-abonnement van TransIP. In de praktijk blijk je niet naar jezelf te kunnen emailen. Ik heb hier contact over gehad met TransIP, maar dat heeft tot op heden weinig opgeleverd.
 
 
 
== Casus lente & zomer 2015: Vaak geen email vanuit Übercart ==
 
 
 
''' Probleem & aanvullende gegevens '''
 
 
 
Bij een bepaalde Drupal 6-webwinkel ontvangen klanten vaak geen orderbevestiging:
 
 
 
* Drupal-log vermeldt geen problemen
 
* PHP-log vermeldt geen problemen
 
* In het bijbehorende ''email-only-abonnement'' staat spamfiltering op z'n laagst, nog afgezien dat spamfiltering betrekking heeft op binnenkomende email, en niet op uitgaande email
 
* Bij een test op 5 augustus kreeg ik zelf wel gewoon een orderbevestiging
 
* Er komt geen email met fouten retour.
 
 
 
''' Overgebleven mogelijke oorzaken '''
 
 
 
* Kloppen de email-gerelateerde instellingen op deze Drupal-site?
 
* Is het SPF-record correct ingevuld?
 
 
 
== Casus herfst 2015: Geen orderbevestigingen ==
 
 
 
''' Probleem '''
 
 
 
De orders van een aantal webwinkels komen niet meer aan in een Gmail-account dat gebruikt wordt voor monitoring.
 
 
 
''' Aanvullende gegevens '''
 
 
 
* Dit betreft meerdere webwinkels, terwijl er niets aan die webwinkels is veranderd
 
* Het probleem treedt op op meerdere computers
 
* De enige gemeenschappelijke factor: Gebruik Gmail
 
* Geen orders in de spambox
 
 
 
''' Mogelijke oorzaken '''
 
 
 
* Gmail past voortdurend spaminstellingen aan. Dingen die voor Gmail overduidelijk spam zijn, belanden niet in de spambox, maar worden direct verwijderd
 
* Er wordt gebruik gemaakt van generieke mailserver-instellingen. Dat geeft een mismatch met de domeinnamen waarvoor gemailed wordt. Dat wordt al snel als spam aangemerkt.
 
 
 
== Casus sep. 2015 (1): Drupal SMTP-module in gebruik nemen ==
 
 
 
Ik volg [http://www.symphonythemes.com/drupal-blog/configure-drupal-smtp-gmail deze] handleiding:
 
 
 
# Installeer Drupal-module [https://www.drupal.org/project/smtp SMTP Authentication Support]: <code>drush -y en smtp</code>
 
# Maak de smtp-module-map de werkmap
 
# Download [https://github.com/Synchro/PHPMailer PHPMailer]: <code> wget https://github.com/Synchro/PHPMailer/archive/master.zip</code>
 
# Pak PHPMailer uit: <code>unzip master.zip</code>. Nu staat het in een submap <code>PHPMailer-master</code>. Da's precies goed
 
# Verander de naam van de PHPMailer-map: <code>mv PHPMailer-master phpmailer</code>
 
# Configureer de module onder <code>Site configuration > SMTP Authentication Support</code>
 
 
 
''' Foutmelding: Class 'SMTP' not found in ... smtp/phpmailer/class.phpmailer.php on line 1291 '''
 
 
 
* Deze klasse is gedefineerd in <code>modules/smtp/phpmailer/class.smtp.php</code> maar wordt blijkbaar niet geladen
 
* Het gaf nog WSOD's ook:
 
 
 
<pre>
 
[16-Sep-2015 17:44:10 Europe/Berlin] PHP Fatal error:  Class 'SMTP' not found in
 
/home/hiero/public/daaro.nl/public/sites/all/modules/smtp/phpmailer/class.phpmailer.php on line 1291
 
</pre>
 
 
 
== Casus sep. 2015 (2): Drupal SMTP-module in gebruik nemen ==
 
 
 
Installatie-procedure in pseudo-code:
 
 
 
<pre>
 
drush -y en smtp
 
cd ~/in2
 
wget https://github.com/Synchro/PHPMailer/archive/master.zip
 
unzip master.zip
 
cd .../sites/all/modules/smtp
 
mkdir phpmailer
 
cd phpmailer
 
cp -r ~/in2/PHPmailer/* .
 
</pre>
 
 
 
''' Configuratie '''
 
 
 
Site configuration > SMTP Authentication Support
 
 
 
''' Goede testmogelijkheden '''
 
 
 
Het is erg handig dat je vanaf de configuratiepagina test-emails kunt sturen.
 
 
 
''' WSOD: Library niet gevonden '''
 
 
 
Bij het ''enablen'' van de module, kreeg ik een WSOD, die onderstaande regel in het logboek achterliet.
 
 
 
== Casus Sep. 2015: Foutmelding: Class 'SMTP' not found ==
 
 
 
''' Foutmelding '''
 
 
 
[17-Sep-2015 16:27:44 Europe/Berlin] PHP Fatal error:  Class 'SMTP' not found in
 
/hier/daaro.nl/public/sites/all/modules/smtp/phpmailer/class.phpmailer.php on line 1302
 
 
 
''' Aanvullende gegevens '''
 
 
 
* De Drupal SMTP-module ondersteunt PHPMailer tot en met versie 2.2.1
 
* Versie PHPMailer: 5.2.13
 
* PHPMailer ondersteunt de ''Libraries API'' sinds versie 3.x
 
 
 
''' Mogelijke oorzaken '''
 
 
 
* Het mechanisme om de betreffende klasse-definitie te laden, ontbreekt
 
* Ik heb de library niet op de juiste plek gezet: De handleiding die ik volgde, was nogal out. [https://www.drupal.org/node/642138 Deze posting uit 2006 zegt:] '' sites/all/libraries/phpmailer''
 
 
 
''' Conclusie '''
 
 
 
''readme.txt'' en ''install.txt'' lezen.
 
 
 
== Casus sep. 2015: SMTP-module met succes geïnstalleerd (1) ==
 
 
 
* phpmailer downloaden: <code>wget https://github.com/PHPMailer/PHPMailer/archive/v2.2.1.tar.gz</code>
 
* Zie Readme- en Install-handleidingen in de appendix
 
* Ik kon geen patch vinden.
 
 
 
Met deze instellingen heb ik testmails kunnen sturen, zonder foutmelding:
 
 
 
* Email-Only-abonnement TransIP
 
* Poort 465
 
* SSL
 
 
 
Let op: Als er debugging-info wordt gestuurd, wil dat ''niet'' automatisch zeggen dat er iets mis is. In het bijzonder als je de module aanzet, komt er een enorme hoeveelheid debug-info voorbij. Bv.:
 
 
 
<pre>
 
 
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "220 submission2.mail.transip.nl ESMTP "
 
SMTP -> get_lines(): $data is "220 submission2.mail.transip.nl ESMTP "
 
SMTP -> FROM SERVER: 220 submission2.mail.transip.nl ESMTP
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "250-submission2.mail.transip.nl "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl "
 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl "
 
SMTP -> get_lines(): $str is "250-PIPELINING "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING "
 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING "
 
SMTP -> get_lines(): $str is "250-SIZE 40000000 "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 "
 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 "
 
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN "
 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN "
 
SMTP -> get_lines(): $str is "250-AUTH=PLAIN LOGIN "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN "
 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN "
 
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES "
 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES "
 
SMTP -> get_lines(): $str is "250-8BITMIME "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME "
 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME "
 
SMTP -> get_lines(): $str is "250 DSN "
 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN "
 
SMTP -> FROM SERVER: 250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6 "
 
SMTP -> get_lines(): $data is "334 VXNlcm5hbWU6 "
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 "
 
SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 "
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "235 2.7.0 Authentication successful "
 
SMTP -> get_lines(): $data is "235 2.7.0 Authentication successful "
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "250 2.1.0 Ok "
 
SMTP -> get_lines(): $data is "250 2.1.0 Ok "
 
SMTP -> FROM SERVER: 250 2.1.0 Ok
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "250 2.1.5 Ok "
 
SMTP -> get_lines(): $data is "250 2.1.5 Ok "
 
SMTP -> FROM SERVER: 250 2.1.5 Ok
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "354 End data with . "
 
SMTP -> get_lines(): $data is "354 End data with . "
 
SMTP -> FROM SERVER: 354 End data with . * phpmailer downloaden: <code>wget https://github.com/PHPMailer/PHPMailer/archive/v2.2.1.tar.gz</code>
 
 
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 3nH3Nx2Xn0z1b7X "
 
SMTP -> get_lines(): $data is "250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 3nH3Nx2Xn0z1b7X "
 
SMTP -> FROM SERVER: 250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 3nH3Nx2Xn0z1b7X
 
SMTP -> get_lines(): $data was ""
 
SMTP -> get_lines(): $str is "221 2.0.0 Bye "
 
SMTP -> get_lines(): $data is "221 2.0.0 Bye "
 
SMTP -> FROM SERVER: 221 2.0.0 Bye
 
</pre>
 
 
 
== Casus sep. 2015: SMTP-module met succes geïnstalleerd (2) ==
 
 
 
In pseudo-code:
 
 
 
<pre>
 
drush -y smtp
 
mkdir ..sites/all/libraries
 
cd ../sites/all/libraries
 
wget https://github.com/PHPMailer/PHPMailer/archive/v2.2.1.tar.gz
 
tar -xzf v2.2.1.tar.gz
 
mv PHPMailer-2.2.1/ phpmailer
 
</pre>
 
  
 
== Bronnen ==
 
== Bronnen ==
Regel 320: Regel 107:
 
* http://stackoverflow.com/questions/6573511/how-do-i-specify-to-php-that-mail-should-be-sent-using-an-external-mail-server
 
* http://stackoverflow.com/questions/6573511/how-do-i-specify-to-php-that-mail-should-be-sent-using-an-external-mail-server
 
* http://www.symphonythemes.com/drupal-blog/configure-drupal-smtp-gmail - Concrete implementatie
 
* http://www.symphonythemes.com/drupal-blog/configure-drupal-smtp-gmail - Concrete implementatie
 
''' Drupal SMTP-module '''
 
 
* https://www.drupal.org/project/smtp
 
 
''' PHPMailer '''
 
 
* https://github.com/PHPMailer/PHPMailer/releases/tag/v2.2.1 - Nieuwste ondersteunde versie
 
 
''' PHPMailer - SMTP-class-foutmelding '''
 
 
* https://www.google.nl/search?q=drupal+6+smtp+class+%27smtp%27+not+found+in+class.phpmailer.php
 
* https://github.com/PHPMailer/PHPMailer/issues/113
 
* https://www.drupal.org/node/1982536 - Fatal error: Class 'PHPMailer' not found in C
 
 
== Appendix: smtp-README.txt ==
 
 
<pre>
 
SMTP Authentication Support module for Drupal 6.x.
 
This module adds SMTP functionality to Drupal.
 
 
REQUIREMENTS
 
------------
 
* Access to an SMTP server
 
* PHP version 4.0.0 and up.
 
* The following PHP extensions need to be installed: ereg, hash, date & pcre.
 
* The PHPMailer package from Codeworx Tech., which can be found here:
 
  http://phpmailer.worxware.com/index.php?pg=phpmailer
 
  http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/
 
 
  The latest version supported is 2.2.1
 
 
* Optional: To connect to an SMTP server using SSL, you need to have the
 
  openssl package installed on your server, and your webserver and PHP
 
  installation need to have additional components installed and configured.
 
 
INSTALL INSTRUCTIONS
 
--------------------
 
See INSTALL.txt
 
 
NOTES
 
-----
 
This module sends email by connecting to an SMTP server.  Therefore, you need
 
to have access to an SMTP server for this module to work.
 
 
Drupal will often use the email address entered into Administrator -> Site
 
configuration -> E-mail address as the from address.  It is important for
 
this to be the correct address and some ISPs will block email that comes from
 
an invalid address.
 
 
Because this module uses the PHPMailer package, it is rather large and may
 
cause PHP to run out of memory if its memory limit is small.
 
 
Connecting to an SMTP server using SSL is possible only if PHP's openssl
 
extension is working.  If the SMTP module detects openssl is available it
 
will display the options in the modules settings page.
 
 
Sending mail to Gmail requires SSL or TLS.
 
</pre>
 
 
== Appendix: SMTP-INSTALL.txt ==
 
 
<pre>
 
NOTE: See the REQUIREMENTS in the README.txt file.
 
 
INSTALLATION INSTRUCTIONS
 
-------------------------
 
1.  Copy the files included in the tarball into a directory named "smtp" in
 
    your Drupal sites/all/modules/ directory.
 
 
2.  Download the PHPMailer package (the URL is listed in REQUIREMENTS section
 
    of the README.txt file). Unarchive the file and name the resulting directory
 
    phpmailer
 
 
3.  You can then put the library in any of 3 places:
 
    a)  sites/all/libraries (ie. sites/all/libraries/phpmailer) **recommended**
 
    b)  path/to/smtp  (ie. sites/all/modules/smtp/phpmailer)
 
    c)  Install the libraries module and place the library at a location where
 
        library module can find it.  (normally sites/all/libraries)
 
 
4.  Apply the adequate patch inside the phpmailer directory (check Drupal docs
 
    on how to apply patches).
 
 
5.  Login as site administrator.
 
 
6.  Enable the SMTP Authentication Support module on the Administer -> Site
 
    building -> Modules page.
 
 
7.  Fill in required settings on the Administer -> Site configuration -> SMTP
 
    Authentication Support page.
 
 
8.  Enjoy.
 
</pre>
 

Versie van 20 sep 2015 11:37

Foutmelding: Unable to send e-mail. Please contact the site administrator of the problem persist. In dit geval is er gelukkig nog een foutmelding, meestal is die er namelijk niet
Foutmelding: Probleem tijdens het versturen van e-mail. Neem contact op met de beheerder als het probleem aanhoudt

In diverse situaties verstuurt Drupal e-mail, bv. order-bevestigingen door Übercart of account-bevestigingen. Dat gaat niet altijd vlekkeloos. Het fundamentele probleem is het gebruik van de php-functie mail(), die alleen gebruik kan maken van een locale Sendmail-instantie. Er zijn gelukkig oplossingen.

Vanaf Drupal 7 speelt dit probleem niet meer, omdat er standaard gebruik wordt gemaakt van PHPMailer().

Het probleem: mail()

Een paar email-gerelateerde instellingen in phpinfo()

Drupal gebruikt een wrapper om de PHP-functie mail():

bool mail(string $to, 
          string $subject, 
          string $message [, 
          string $additional_headers [, 
          string $additional_parameters ]] )

mail functioneert als een mailclient voor de locale mailserver. Dus een mailserver die op die machine draait. Meer over de betreffende mailserver kun je achterhalen met phpinfo(). Mail kan alleen overweg met een locale mailserver, en schijnt vrij beroerd te werken. Problematischer: Zover ik weet, kan het alleen overweg met één domein per webserver. Als er meerdere domeinen op een webserver geconfigureerd zijn, moet je gaan spoofen. En veel spamfilters vinden het niet leuk als je dat doet.

Mail-headers

Dit is een deel van de header van zo'n email. Deze email is verstuurd uit naam van een webwinkel. Dit domein staat op een VPS welke gedeeld wordt met een aantal andere domeinen. Er wordt altijd gebruik gemaakt door dezelfde mail-server. In dit geval vallen de waarschuwingen nog mee:

Delivered-To: info@gmail.com
Received-SPF: neutral (google.com: 83.137.149.10 is neither permitted nor denied by best guess record for 
   domain of www-data@example.com) client-ip=83.137.149.10;
Authentication-Results: mx.google.com;
spf=neutral (google.com: 83.137.149.10 is neither permitted nor denied by best guess record for domain of 
   www-data@example.com) smtp.mailfrom=www-data@example.com
Received-SPF: none (no valid SPF record)
X-PHP-Originating-Script: 1000:mail.inc
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8Bit
X-Mailer: Drupal

Troubleshooting

Begin bij het logboek

Je weet wel:

Drupal: Reports > Recent log entries

Als deze entry er niet staat, moet je wellicht module Database logging en/of Syslog aanzetten.

Het logboek houdt alleen bij of email met success is afgeleverd bij de mailserver. Dat zegt dus niet of de mailserver de mail met succes heeft kunnen versturen.

Anders kan het PHP-logboek ook helpen:

less /var/log/php/error.log

Controleer de afzender (site information)

In de voortdurende strijd tegen spam, controleren veel ontvangende mailservers of de verzendende mailserver wel echt bestaat. Dat kan een probleem zijn, bv. als de betreffende website op een ontwikkelserver staat zonder domeinnaam, maar met alleen een IP-adres. Of als de site een echte naam heeft, maar op een ontwikkelserver draait, zonder die domeinnaam.

De afzender staat geconfigureerd onder Site information.

Übercart? Controleer de afzender!

In november 2012 had ik bij het klonen van een Übercart-site vergeten om het afzender-e-mailadres te veranderen. Bevestigingen van nieuwe accounts werden dus wel goed verzonden, maar orderbevestigingen niet.

In Drupal 6 moet je de afzender op twee of drie plekken aanpassen onder Conditionele acties.

Foutmelding: Probleem bij het versturen van e-mail. Neem contact op met de beheerder als het probleem aanhoudt
De oorzaak: Tikfout in het e-mailadres van de afzender. Deze fout bevestigd trouwens dat het e-mailadres van de afzender op meerdere plekken wordt bijgehouden. Anders was het al veel eerder gebleken
Deze fout heeft geen betrekking op Übercart, maar op Drupal in het algemeen. Dus pagina Site information.

Externe SMTP-server gebruiken: Mogelijkheden

Hierboven werd mail() genoemd, en de tekortkomingen die het heeft. Verzending via een externe mailserver, zou een universele oplossing zijn. Mogelijkheden:

  • nail()
  • Swiftmailer
  • Drupal SMTP-module ivm. PHPMailer.

Deze laatste mogelijkheid, blijkt een goede oplossing te zijn. Zie SMTP-module (Drupal) voor details.

Zie ook

Bronnen

php's mail()

Externe mailserver