For issues related to the current stable release please use it's own Help forum.
IMPORTANT:Please read this before using an git or nightly build version: wiki.webtrees.net/en/GIT

Before asking for help please read "How to request help" by clicking on that tab above here.

TOPIC: Cannot send mail by SMTP

Cannot send mail by SMTP 2 months 3 days ago #1

  • hlein
  • hlein's Avatar
  • Offline
  • Junior
  • Posts: 138
Trying to send a mail fails (webtrees says "The message was not sent."

In wt_log an error is logged:
Mail: stream_set_blocking() expects parameter 1 to be resource, null given
Regards
Helmut
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 3 days ago #2

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Posts: 11160
1) Is that the entire message?

2) In your PHP.INI (Control panel -> Server information), what value do you have for "disable_functions"
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 2 days ago #3

  • hlein
  • hlein's Avatar
  • Offline
  • Junior
  • Posts: 138
1) yes
2)
pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,symlink,leak,dl,stream_socket_server,stream_socket_sendto,stream_socket_client,opcache_invalidate,opcache_reset

Note:
if I set Error Log and Display Errors to on in the PHP configurration (provider) and run the following testscript
<?php

namespace Fisharebest\Webtrees;

use Middleland\Dispatcher;

require __DIR__ . '/vendor/autoload.php';

// require './vendor/swiftmailer/swiftmailer/lib/swift_required.php';

use Swift_Mailer;
use Swift_MailTransport;
use Swift_Message;
use Swift_NullTransport;
use Swift_Preferences;
use Swift_SendmailTransport;
use Swift_SmtpTransport;
use Swift_Transport;



$pEmailGmail = 'hlein77@gmail.com';
$pPasswordGmail = 'cmd1307#';
$pFromName = 'MundialSYS.com'; //display name

$pTo = 'hlein@gmx.at'; //destination email
$pSubjetc = "Hello MundialSYS"; //the subjetc 
$pBody = '<html><body><p>Hello MundialSYS</p></html></body>'; //body html

$transport = new Swift_SmtpTransport/*::newInstance*/('smtp.gmail.com', 465, 'ssl');
            $transport->setUsername($pEmailGmail);
            $transport->setPassword($pPasswordGmail);

$mMailer = new Swift_Mailer/*::newInstance*/($transport);

$mEmail = new Swift_Message/*::newInstance()*/;
$mEmail->setSubject($pSubjetc);
$mEmail->setTo($pTo);
$mEmail->setFrom(array($pEmailGmail => $pFromName));
$mEmail->setBody($pBody, 'text/html'); //body html

if($mMailer->send($mEmail) == 1){
    echo 'send ok';
}
else {
    echo 'send error';
}
?>

I get these errrors:
[15-May-2019 19:22:46 UTC] PHP Warning:  stream_set_blocking() expects parameter 1 to be resource, null given in /data/web/e74015/html/wt-test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 275
[15-May-2019 19:22:46 UTC] PHP Warning:  stream_set_timeout() expects parameter 1 to be resource, null given in /data/web/e74015/html/wt-test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 279
[15-May-2019 19:22:46 UTC] PHP Fatal error:  Uncaught Swift_TransportException: Expected response code 220 but got an empty response in /data/web/e74015/html/wt-test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:445
Stack trace:
#0 /data/web/e74015/html/wt-test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(358): Swift_Transport_AbstractSmtpTransport->assertResponseCode('', Array)
#1 /data/web/e74015/html/wt-test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(147): Swift_Transport_AbstractSmtpTransport->readGreeting()
#2 /data/web/e74015/html/wt-test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#3 /data/web/e74015/html/wt-test/testsmtpmail.php(42): Swift_Mailer->send(Object(Swift_Message))
#4 {main}
  thrown in /data/web/e74015/html/wt-test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php on line 445
Regards
Helmut
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 2 days ago #4

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Posts: 11160
The problem is that the SwiftMailer library is using the function stream_socket_client().

Your webhost blocks this function.

The result is an unexpected NULL value - which you see in the logs.

I am not sure why it is blocked. To my knowledge, it is not a security risk.
stream_socket_client() provides the same functions as fsockopen() - which your host allows.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 2 days ago #5

  • hlein
  • hlein's Avatar
  • Offline
  • Junior
  • Posts: 138
So there is no solution - except asking the provider to open the function (what most probably he won't do) ?
Regards
Helmut
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 2 days ago #6

  • hlein
  • hlein's Avatar
  • Offline
  • Junior
  • Posts: 138
I have found the same problem described in the internet stackoverflow.com/questions/54480190/swi...m-set-blocking-error

The answer the user got from easyname:
easyname's support informed me today that they disabled stream_socket_client() in PHP7.x to prevent abuse by hackers. This is their last word.
Regards
Helmut
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 2 days ago #7

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Posts: 11160
> This is their last word.

/sigh


Searching on google, I can only find one webhost that blocks this function...



I have been looking at the source-code of other PHP mail libraries.

I have found one that checks if stream_socket_client() is available - if not, it will use fsockopen() instead.

However, this library is less sophisticated, and I guess it might not be able to communicate with as many different SMTP servers.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 1 day ago #8

  • hlein
  • hlein's Avatar
  • Offline
  • Junior
  • Posts: 138
Could PHPmail be re-enabled, maybe with a warning about reliability ? For me, it did work.
Regards
Helmut
The administrator has disabled public write access.
Do you need a web hosting solution for your webtrees site?
If you prefer a host that specialises in webtrees, the following page lists some suppliers able to provide one for you: 

Cannot send mail by SMTP 2 months 1 day ago #9

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Posts: 11160
Security flaws have been found in the PHP mail() function.

These flaws can allow someone to run any code on your server.

A hacker simply needs to use a "carefully created" (but valid) email address in the register page.

Popular mail libraries (e.g. SwiftMailer, ZendMail, PhpMailer, etc.) have all removed support for mail().

For security matters, one should follow the advice of the experts.

As I said in my previous post, I have found another mail library that does not use the blocked function.

So, it is possible to write code like this:
if (host == easynames) {
  use PhpMailer library;
} else {
  use SwiftMailer library;
}

webtrees 2.0 is still only beta. This is the time to find and fix these types of issue.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Cannot send mail by SMTP 2 months 1 day ago #10

  • hlein
  • hlein's Avatar
  • Offline
  • Junior
  • Posts: 138
This would be phantastic. Maybe it would be more flexible to test for stream_socket_client enabled than for specific server names.

Thanks
Regards
Helmut
The administrator has disabled public write access.

[solved] Cannot send mail by SMTP - WFME 1 month 2 weeks ago #11

  • hlein
  • hlein's Avatar
  • Offline
  • Junior
  • Posts: 138
Hi,

easyname.at has enabled stream_socket_client(). Sending emails by SMTP works now, but you have to use easyname's servers (not gmail.com ....)

Not necessary to seaarch another mailing package.

Thanks.
Regards
Helmut
Last Edit: 1 month 2 weeks ago by hlein.
The administrator has disabled public write access.
Powered by Kunena Forum