Question about sending mail from the forum (General)

by danielb987, Tuesday, May 30, 2017, 05:49 (83 days ago)

Hi,

Before upgrading my forum to the latest version, then a user sent a email to another user, he got a copy of the email. After the upgrade, the user that send the email does not get a copy of the email. (The upgrade was from a very old version).

It is the feature "E-mail to <user>" that I'm talking about:
http://mylittleforum.net/forum/index.php?mode=contact&id=10148

Is this a bug in MyLitteForum or a bug in my installation, or is the software changed in order to not send a copy to the user that send the email?

The problem is that if the user doesn't get a copy, he doesn't get a confirmation that the email has been sent at all. So it is a much desired feature to get a copy of the sent mail.

Best regards,
Daniel

Avatar

Question about sending mail from the forum

by Magma, Tuesday, May 30, 2017, 12:07 (83 days ago) @ danielb987

Just to let you know in 2.4.2 I also do not get a copy of email set to another user. Although I don't think I have for the past few versions now :lookaround:

Avatar

Sending mail from the forum, question to @Milo

by Auge ⌂ @, Tuesday, May 30, 2017, 13:33 (83 days ago) @ danielb987

Hello

Before upgrading my forum to the latest version, then a user sent a email to another user, he got a copy of the email.

@Milo: That's how it should work, or not?

After the upgrade, the user that send the email does not get a copy of the email.

I can confirm it. In my own installation I get the message as the recipient but not a confirmation copy as the sender.

(The upgrade was from a very old version).

Yes, you was the one with the ancient version. :-)

Is this a bug in MyLitteForum or a bug in my installation, or is the software changed in order to not send a copy to the user that send the email?

I've no clue. If I'm right, we made no changes in the code of the e-mail function in the last year (I entered the crew last june). Either the relevant change is older or we introduced an until now unnoticed bug.

The problem is that if the user doesn't get a copy, he doesn't get a confirmation that the email has been sent at all. So it is a much desired feature to get a copy of the sent mail.

This is comprehensible.

Tschö, Auge

--
further development of mlf1

Sending mail from the forum, question to @Milo

by danielb987, Tuesday, May 30, 2017, 14:10 (83 days ago) @ Auge

I compared the ancient version with the current version and the file "include/contact.inc.php" has been changed.

Ancient version, line 236 - 293:

   if(empty($errors))
    {
     $smarty->config_load($settings['language_file'],'emails');
     $lang = $smarty->get_config_vars();
 
     // send mail:
     $ip = $_SERVER["REMOTE_ADDR"];
 
     if(isset($_SESSION[$settings['session_prefix'].'user_name'])) $emailbody = str_replace("[user]", stripslashes($_SESSION[$settings['session_prefix'].'user_name']), $lang['contact_email_txt_user']);
     else $emailbody = $lang['contact_email_txt'];
     $emailbody = str_replace("[message]", stripslashes($text), $emailbody);
     $emailbody = str_replace("[forum_address]", $settings['forum_address'], $emailbody);
     $header  = "From: ".$sender_email."\n";
     $header .= "X-Mailer: PHP/" . phpversion(). "\n";
     $header .= "X-Sender-ip: ".$ip."\n";
     $header .= "Content-Type: text/plain; charset=".$lang['charset']."\n";
     $header .= "Content-transfer-encoding: 8bit\n";
     if($settings['mail_parameter']!='')
      {
       if(!@mail($recipient_email, stripslashes($subject), $emailbody, $header, $settings['mail_parameter'])) $errors[] = 'error_mailserver';
      }
     else
      {
       if(!@mail($recipient_email, stripslashes($subject), $emailbody, $header)) $errors[] = 'error_mailserver';
      }
    }
   if(isset($errors))
    {
     $smarty->assign('errors',$errors);
     if(isset($id)) $smarty->assign('id',$id);
     if(isset($user_id)) $smarty->assign('recipient_user_id',$user_id);
     if(isset($sender_email)) $smarty->assign('sender_email',htmlspecialchars(stripslashes($sender_email)));
     if(isset($text)) $smarty->assign('text',htmlspecialchars(stripslashes($text)));
     if(isset($subject)) $smarty->assign('subject',htmlspecialchars(stripslashes($subject)));
    } 
   else
    {
     $smarty->assign('sent',TRUE);
     // e-mail to sender:
     $emailsubject = str_replace("[subject]", stripslashes($subject), $lang['contact_notification_sj']);
     $emailbody = str_replace("[subject]", stripslashes($subject), $lang['contact_notification_txt']);
     $emailbody = str_replace("[message]", stripslashes($text), $emailbody);
     $emailbody = str_replace("[forum_address]", $settings['forum_address'], $emailbody);
     $emailbody = str_replace("[recipient]", $recipient_name, $emailbody);
     $header  = "From: ".$settings['forum_email']."\n";
     $header .= "X-Mailer: PHP/" . phpversion(). "\n";
     $header .= "X-Sender-ip: ".$ip."\n";
     $header .= "Content-Type: text/plain; charset=".$lang['charset']."\n";
     $header .= "Content-transfer-encoding: 8bit\n";
     if($settings['mail_parameter']!='')
      {
       @mail($sender_email, $emailsubject, $emailbody, $header, $settings['mail_parameter']);
      }
     else
      {
       @mail($sender_email, $emailsubject, $emailbody, $header);
      }
    }
 

Current version, line 275 - 299:

   if(empty($errors))
    {
     // load e-mail strings from default language file:
     $smarty->configLoad($settings['language_file'], 'emails');
     $lang = $smarty->getConfigVars();
     if(isset($_SESSION[$settings['session_prefix'].'user_name'])) $emailbody = str_replace("[user]", $_SESSION[$settings['session_prefix'].'user_name'], $lang['contact_email_txt_user']);
     else $emailbody = $lang['contact_email_txt'];
     $emailbody = str_replace("[message]", $text, $emailbody);
     $emailbody = str_replace("[forum_address]", $settings['forum_address'], $emailbody);
     if(!my_mail($recipient_email, $subject, $emailbody, $sender_email)) $errors[] = 'mail_error';
    }
   if(isset($errors))
    {
     $_SESSION[$settings['session_prefix'].'formtime'] = TIMESTAMP - 7; // 7 seconds credit (form already sent)
     $smarty->assign('errors',$errors);
     if(isset($id)) $smarty->assign('id',intval($id));
     if(isset($user_id)) $smarty->assign('recipient_user_id',intval($user_id));
     if(isset($sender_email)) $smarty->assign('sender_email',htmlspecialchars($sender_email));
     if(isset($text)) $smarty->assign('text',htmlspecialchars($text));
     if(isset($subject)) $smarty->assign('subject',htmlspecialchars($subject));
    }
   else
    {
     $smarty->assign('sent',TRUE);
    }
 

In the ancient version, the PHP function mail() is called twice, both for $recipient_email and $sender_email. In the current version, my_mail() is only called once, for $recipient_email.

It would be great if MyLittleForum would send a copy of the email to the sender as well.

If this for some reason is not desirable, then a setting would allow the forum owner to choose whenether or not to use it. Or, it could be an option for the user that sends the email. A checkbox in the form. If the user check the checkbox, he will receive a copy. If he doesn't check the checkbox, he will not.

Best regards,
Daniel

Avatar

Sending mail from the forum, question to @Milo

by Auge ⌂ @, Tuesday, May 30, 2017, 14:29 (83 days ago) @ danielb987

Hello

I compared the ancient version with the current version and the file "include/contact.inc.php" has been changed.

Thank you for pointing me to the relevant section. I began to search for myself a few minutes ago. Now I can break this action immediately. :-)

It would be great if MyLittleForum would send a copy of the email to the sender as well.

If this for some reason is not desirable, then a setting would allow the forum owner to choose whenether or not to use it. Or, it could be an option for the user that sends the email. A checkbox in the form. If the user check the checkbox, he will receive a copy. If he doesn't check the checkbox, he will not.

Or with a second submit button. IMHO this would be more eye-catching.

Tschö, Auge

--
further development of mlf1

Avatar

Sending mail from the forum, question to @Milo

by Milo ⌂, Tuesday, May 30, 2017, 16:54 (83 days ago) @ Auge

Hello,

@Milo: That's how it should work, or not?

No, I don't think so. I remembered an old posting/thread about this issues and it took a lot of time to find this old thread: Copy of sent e-mail message. Thus, no copy of mail will be sent. This is the normal behaviour since 2008.

regards
Micha

--
Surveyor-Software: Geodetic Network Adjustment & Deformation-Analysis and Transformation

Sending mail from the forum, question to @Milo

by danielb987, Tuesday, May 30, 2017, 17:12 (83 days ago) @ Milo

Hello,

No, I don't think so. I remembered an old posting/thread about this issues and it took a lot of time to find this old thread: Copy of sent e-mail message. Thus, no copy of mail will be sent. This is the normal behaviour since 2008.

I see. And I understand why it is a bad idea that a user that is not logged in is able to choose the sender address.

But is it possible to send a copy to the sender if and only if the user is logged in? In that case the user should not choose the sender email address anyway.

I now see that it is possible to change the sender email address if the user is logged in, but I don't see any reason for that. It would be better if the form only showed the sender email address and not allowed it to be changed. If the email address is wrong, it is much better that the user changes it before, and since the user is logged in in this case, it is simple for the user to do that.

So my suggestion is as follows:

If the user is NOT logged in, no copy is sent to the user. And a text informs the user about that and tells the user to log in if he wants a copy.

If the user is logged in, send a copy to the senders email address. But don't allow the user to change the sender email address in the contact form.

Best regards,
Daniel

Avatar

Sending mail from the forum, question to @Milo

by Auge ⌂ @, Wednesday, May 31, 2017, 08:39 (82 days ago) @ danielb987

Hello

Interesting discussion.

So my suggestion is as follows:

If the user is NOT logged in, no copy is sent to the user. And a text informs the user about that and tells the user to log in if he wants a copy.

If the user is logged in, send a copy to the senders email address. But don't allow the user to change the sender email address in the contact form.

To recapitulate the by Milo linked (ancient) discussions and your proposals:

- Not logged in users should not be able to receive a copy of the e-mail.
- Logged in users should be able to receive a copy of the e-mail.
- The ability to change the senders e-mail-address is a no go.
- IMHO the copy of the e-mail should not be mandatory.

That would result in a (pseudo code) structure like this:

if (send-with-copy OR send-without-copy) {
  // mail form was sent by a visitor or registered user
  if (user-is-registered) {
    // form was sent by a registered user
    if (recipient-is-valid) {
      // send e-mail to the recipient
    }
    if (send-with-copy AND sender-is-valid) {
      // send additional e-mail to the sender
    }
  } else {
    // form was sent by an unregistered visitor or a not logged in user
    if (recipient-is-valid) {
      // send e-mail to the recipient
    }
  }
}

Testing for recipient-is-valid includes the check for a valid address or a valid user-ID and the activation of the contact-function by the desired recipient. Testing for sender-is-valid includes the check for a valid address and the validity of the ID of the current user.

Tschö, Auge

--
further development of mlf1

Sending mail from the forum, question to @Milo

by danielb987, Wednesday, May 31, 2017, 23:17 (81 days ago) @ Auge

Hello,

Yes. That would be great.

Testing for recipient-is-valid includes the check for a valid address or a valid user-ID ...

It should do both. First check for a valid user id. Then check that that user has a valid email address. And at last, as you said, check that that user accepts email.

Testing for sender-is-valid includes the check for a valid address and the validity of the ID of the current user.

I agree.

Best regards
Daniel

Avatar

Sending mail from the forum, question to @Milo

by Auge ⌂ @, Thursday, June 01, 2017, 08:14 (81 days ago) @ danielb987

Hello

Testing for recipient-is-valid includes the check for a valid address or a valid user-ID ...

It should do both. First check for a valid user id. Then check that that user has a valid email address.

That's coorect for registered recipients, but I intended another goal. The scripts allow to send emails also to unregistered users, who gave their o.k. to be contacted via e-mail when posting. In this case no user-ID exists. There's only an e-mail-address and the database field mlf2_entries.email_notification. Thatswhy the "or" instead an "and".

Tschö, Auge

--
further development of mlf1

Sending mail from the forum, question to @Milo

by danielb987, Thursday, June 01, 2017, 08:37 (81 days ago) @ Auge

I see.

But look at this post:
http://mylittleforum.net/forum/index.php?id=9093

Even if the user isn't registred, the contact form uses an ID, in this case the ID of the entry. So the ID should always be checked, either the user ID or the entry ID.

Best regards,
Daniel

RSS Feed of thread
powered by my little forum