PHP can send email but elgg site cannot.

Hello everyone, it's my first time to publish a topic and there's a issue with email. I love elgg! 

 

This example ElggDocs can send email but elgg site cannot. 

In setting.php:

$CONFIG->emailer_transport = 'sendmail';

More detail: elgg 3.3, MTA is mailx and smtps.

 

Thanks!

 

  • The server's error log only shows "Unable to send mail: Unknown error". This error seems to occur when Elgg tries to send the email (vendor/elgg/elgg/engine/lib/notification.php line 259).

    If you would find the mailserver (MTA) log it might contain a more detailed entry why the mail could not be sent, either never leaving the server as the server's MTA already denies the sending or the receiving server doesn't accept it for some reason.

    It's still a possibility - like I tried to explain in my last posting - that your mailsever does not sent the emails from Elgg if the site email address has not the same domain as the domain of your sever. Or the receiving server doesn't accept it if "from" address domain and server domain don't match. As the server log contains the log entry about some "Unknown error" I rather believe the mail is never sent it the first place.

    If you can't (or don't want) to use SMTP instead of the MTA on your server, you need to figure out what's wrong with the mailserver configuration as there's basically no configuration to be done on Elgg's side for sending via MTA. Only if you would want to make use of another mail provider and send the mails from the Elgg installation via SMTP you would have to provide the necessary config options in settings.php of your Elgg installation. Not using port 25 seems better anyway as you with port 465 you would send via SSL and the connection to the SMTP server would be encrypted.

  • I checked my MTA log (I am not sure with it) and found some are time out

    Aug 17 04:10:46 CVM*** sendmail[18985]: 07BJhRqC005605: to=<p*****@room369.work>, delay=5+00:27:19, xdelay=00:02:00, mailer=esmtp, pri=11010821, relay=box.room369.work. [178.128.100.127], dsn=4.0.0, stat=Deferred: Connection timed out with box.room369.work.

    -PS, this is a spam mail address.-

    and others do not exist in log. I don't know why it happens.

  • It necessary to know what happens with emails sent by Elgg. Any spam mails not getting sent for whatever reason might be nice to know but probably doesn't help. What happens when you register an account (as you tried before)? What's in the mail log at that time?

    You still haven't told if the site email you use in your Elgg installation is from the same domain as your site url. I still think this might be the problem if it's not the same.

    You could also take a look at examples 2 and 3 from https://www.php.net/manual/en/function.mail.php to see how adding a header to the mail you sent with the php mail() command. With this examples you can test if the mail is still sent when using the site email address as from and reply addresses in the header.

  • https://serverfault.com/questions/897695/sendmail-not-sending-stat-deferred-connection-timed-out-with

    No use, php can send mail to everywhere but elgg can't send mail to anywhere.

     You still haven't told if the site email you use in your Elgg installation is from the same domain as your site url. 

    It's the same. But I haven't add DNS MX record (I think it does not matter)

  • I guess I'm at a loss then.

    If you have either set

    $CONFIG->emailer_transport = 'sendmail';

    in your settings.php or commented out this line (default) there's absolutely nothing to be set up in Elgg to get the mail sending working. BUT you need to have your MTA correctly set up. The command line mail() test might be just an indication that the MTA doesn't work at all but not necessarily a proof that it fully works because the test does not include a mail header on its own whereas Elgg adds such a header to allow for identification of sender.

    The other option with

    $CONFIG->emailer_transport = 'smtp';

    (and $CONFIG->emailer_smtp_settings array filled with the SMTP server credentials) would require some configuration in the settings.php file (but only these two config variables).

    If neither of these two options work for you, you could try re-installing your Elgg site in case something might have gone wrong and something in the Zend Sendmail Transport package is broken. I would think it's unlikely but you could try nonetheless. If this also doesn't work, you need to accept that you're mailserver (MTA) is not fully operational and you need to sort this out. Without any proper log entries (server log and/or php log and/or maillog) telling us more about possible errors it's simply impossible for us to help you. I would suggest you ask the support of your webhoster what might be the problem then if you can't sort it out yourself.

  • I can recieve email with header

  • It's no use if you tell us that you can send the mails by using the test script but can't provide any error log entries giving any info about why the mails sent from Elgg fail to be transferred. If you can't find the logs yourself or can't fix your mailserver yourself, you would have to contact the support of your webhoster.

  • This is the MTA log, and Elgg log says 'Unknown error '
     
    [26-Aug-2020 21:36:12 Asia/Shanghai] mail() on [/www/wwwroot/sn.mydomain.com/vendor/zendframework/zend-mail/src/Transport/Sendmail.php:296]: To: =?UTF-8?Q?test?= <ya******23@163.com> -- Headers: Date: Wed, 26 Aug 2020 21:36:12 +0800 Sender: =?UTF-8?Q?CCSN?= <noreply@sn.mydomain.com> From: =?UTF-8?Q?CCSN?= <noreply@sn.mydomain.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: </.default.1598448972.9563@sn.mydomain.com> Content-Transfer-Encoding: 8bit Content-ID: =?UTF-8?Q?<plaintext>?= Content-Type: multipart/alternative;  boundary="=_3477d21c9f1d9f2e578570dfdb396ced";  format="flowed" -- Subject: test please confirm your email address for CCSN!
     
    I think the mail was delivered to MTA but not sent
  • I'm very sorry. But I don't think I can help you.

    The MTA log file snippet (which looks very different to any maillog entries I've seen so far) shown no status or error info at all. I do not see if this mail got sent or rejected or whatever happened to it. If there's no other information avalable, I don't think there's much sense (for me) trying to find a solution.

    Can't you ask the support of your webhoster to get it fixed? This whole issus starts to remind me to a discussion topic from some time ago where someone tried to set up an Elgg site on Godaddy. In this case the mail() test also worked but Elgg could not sent mails either because the server just did not offer a sendmail compatible MTA but you were required to use a mail relay and send the mail via SMTP. Back then Elgg did not offer SMTP support out of the box. By now this is possible if configured with the SMTP server settings in Elgg's settings.php. So, you could try if you get email sending via SMTP to work. Or get the support of your webhoster to configure the mailserver correctly. Or try it on another hoster that might provide a working server config.