diff --git a/config-templates/config.php b/config-templates/config.php
index f25f30b1e955ba0c01dd60ddf21254cb4f444aa0..b9e9e004393557ef45a495315ef162fa3988ae7e 100644
--- a/config-templates/config.php
+++ b/config-templates/config.php
@@ -54,6 +54,11 @@ $config = array(
     'technicalcontact_name' => 'Administrator',
     'technicalcontact_email' => 'na@example.org',
 
+    /*
+     * Sender email should use the same domain as your application domain to prevent SPF record filtering
+     */
+    //'sendmail_from' => 'no-reply@example.org',
+
     /*
      * The timezone of the server. This option should be set to the timezone you want
      * SimpleSAMLphp to report the time in. The default is to guess the timezone based
diff --git a/www/errorreport.php b/www/errorreport.php
index d99f313b99cb712be944ed536136f213c97988d2..569db419929568a20568bb20df012a1a67a6ede6 100644
--- a/www/errorreport.php
+++ b/www/errorreport.php
@@ -101,10 +101,21 @@ $email = trim($email);
 // check that it looks like a valid email address
 if (!preg_match('/\s/', $email) && strpos($email, '@') !== false) {
     $replyto = $email;
-    $from = $email;
 } else {
     $replyto = null;
-    $from = 'no-reply@simplesamlphp.org';
+}
+
+$from = $config->getString('sendmail_from', null);
+if ($from === null || $from === '') {
+    $from = ini_get('sendmail_from');
+    if ($from === '' || $from === false) {
+        $from = 'no-reply@example.org';
+    }
+}
+
+// If no sender email was configured at least set some relevant from address
+if ($from === 'no-reply@example.org' && $replyto !== null) {
+    $from = $replyto;
 }
 
 // send the email