Solved: 5 Years, 1 Week ago Update on mail issue.
#1
Solved: 5 Years, 1 Week ago
So to trouble shoot, my web host's technical support logged in and changed the email address for the account I gave them for a "testuser002", to an email address of that technical support member's.

He was then able to send an email to himself through MyBB.

I then logged in, and was able to send an email from testuser002, to both "admin" and "nuraman00" (different email addresses).

However, when I send from "admin" to "nuraman00" I get message not accepted due to policy reasons.

When I send from "nuraman00" to "admin", I get "This message failed DMARC Evaluation and is being
refused due to the policy provided by the From domain."

I also can't send from nuraman00 to nuraman00 nor admin to admin.

Is it possible to set the "from" as my web host email address account, and a reply-to as the user's email address?
Reply
#2
Solved: 5 Years, 1 Week ago
Bump?
Reply
#3
Solved: 5 Years, 1 Week ago
Mail Settings has provision for admin mail & return mail.

if you have to modify from field value then this topic might help
Reply
#4
Solved: 5 Years, 1 Week ago
Is that used for PHP mail too?

I went to class_mailhandler.php, and the function set_common_headers, and I changed it to this:

		$this->headers .= "From: [email protected]";


Where [email protected] represents the hardcoded email address I entered.

However, nothing changed when I sent an email from nuraman00 to nuraman00. The from address was the same as before.

Also, is the reply-to going to properly be set?

So, after making that change above, I noticed that the FROM now has 2 headers when I send private messages.

It has a from, and it has a reply-to.

However, I don't think that function above is called when sending user to user emails, as nothing is changed then. As I said in the post above, the from address is the same as it was before, when sending user to user emails.
Reply
#5
Solved: 5 Years, 1 Week ago
Any more suggestions I can try?

Thank you.
Reply
#6
Solved: 5 Years, 1 Week ago
Bump?
Reply
#7
Solved: 5 Years, 1 Week ago
I tried using firePHP to see the call stack for when I send a user to user email. I was hoping to see what functions were being called, so I could see how it gets the from email address, and hopefully how to set the reply-to.

But I wasn't able to find what I was looking for. Is it happening too fast?

Am I not using the right tool?

Do I have to put a print statement to see something in the console?
Reply
#8
Solved: 5 Years, 1 Week ago
Ok, here's what I've been able to find:

Line 2706 in member.php  seems to indicate that this is for user to user emails.


if($mybb->input['action'] == "do_emailuser" && $mybb->request_method == "post")




In member.php, lines 2799 - 2852, seems to build the mail parameters.




	if($mybb->user['uid'])
	{
		$mybb->input['fromemail'] = $mybb->user['email'];
		$mybb->input['fromname'] = $mybb->user['username'];
	}

	if(!validate_email_format($mybb->input['fromemail']))
	{
		$errors[] = $lang->error_invalidfromemail;
	}

	if(empty($mybb->input['fromname']))
	{
		$errors[] = $lang->error_noname;
	}

	if(empty($mybb->input['subject']))
	{
		$errors[] = $lang->error_no_email_subject;
	}

	if(empty($mybb->input['message']))
	{
		$errors[] = $lang->error_no_email_message;
	}

	if($mybb->settings['captchaimage'] && $mybb->user['uid'] == 0)
	{
		require_once MYBB_ROOT.'inc/class_captcha.php';
		$captcha = new captcha;

		if($captcha->validate_captcha() == false)
		{
			// CAPTCHA validation failed
			foreach($captcha->get_errors() as $error)
			{
				$errors[] = $error;
			}
		}
	}

	if(count($errors) == 0)
	{
		if($mybb->settings['mail_handler'] == 'smtp')
		{
			$from = $mybb->input['fromemail'];
		}
		else
		{
			$from = "{$mybb->input['fromname']} <{$mybb->input['fromemail']}>";
		}

		$message = $lang->sprintf($lang->email_emailuser, $to_user['username'], $mybb->input['fromname'], $mybb->settings['bbname'], $mybb->settings['bburl'], $mybb->get_input('message'));
		my_mail($to_user['email'], $mybb->get_input('subject'), $message, $from, "", "", false, "text", "", $mybb->input['fromemail']);



This block calls the function my_mail, which is in functions.php:


function my_mail($to, $subject, $message, $from="", $charset="", $headers="", $keep_alive=false, $format="text", $message_text="", $return_email="")
{
    global $mybb;
    static $mail;

    // Does our object not exist? Create it
    if(!is_object($mail))
    {
        require_once MYBB_ROOT."inc/class_mailhandler.php";

        if($mybb->settings['mail_handler'] == 'smtp')
        {
            require_once MYBB_ROOT."inc/mailhandlers/smtp.php";
            $mail = new SmtpMail();
        }
        else
        {
            require_once MYBB_ROOT."inc/mailhandlers/php.php";
            $mail = new PhpMail();
        }
    }

    // Using SMTP based mail
    if($mybb->settings['mail_handler'] == 'smtp')
    {
        if($keep_alive == true)
        {
            $mail->keep_alive = true;
        }
    }

    // Using PHP based mail()
    else
    {
        if($mybb->settings['mail_parameters'] != '')
        {
            $mail->additional_parameters = $mybb->settings['mail_parameters'];
        }
    }

    // Build and send
    $mail->build_message($to, $subject, $message, $from, $charset, $headers, $format, $message_text, $return_email);
    return $mail->send();



If I look back at the my_mail function call from member.php:

 my_mail($to_user['email'], $mybb->get_input('subject'), $message, $from, "", "", false, "text", "", $mybb->input['fromemail']);

The return email is being sent as the from email address from the $mybb->input['fromemail'] variable. 


So what if I take this block right above it:

else
 {
 $from = "{$mybb->input['fromname']} <{$mybb->input['fromemail']}>";
 }


And hardcode the variable $from variable to my web host email address?

Would that be a good / safe way to make the user to user emails work for all emails?
Reply
#9
Solved: 5 Years, 1 Week ago
The problem I was having was sending yahoo to yahoo; yahoo to aol; aol to yahoo; and aol to aol.  I was getting those DMARC errors described in the OP.

I tried the change above, hard coding my server email address in that else block from member.php. 




I spent several more hours testing various things.

* I still could not send to AOL email addresses.

SMTP error from remote mail server after end of data:

   521 5.2.1

Host was not accepting delivery.

* I could, however, now send to Yahoo ones.

I was able to send PMs to aol email addresses.  That always worked.

And if I called the PHP mail function directly, instead of the my_mail() function in functions.php, I could also still send to aol email addresses.

The problem came as soon as I added a reply-to when sending to an AOL email address.


I then spent several hours testing branching logic I added in class_mailhandler.php, in the build_message() function, and set_common_headers() function.

I was only setting the return_email in build_message(), or the "Return-Path" and "Reply-To:" in set_common_headers, if the to email address wasn't an aol.com one.

I had several echo statements testing it.  For some reason, the logic would be fine through build_message(), but the return_email in set_common_headers in the "if($this->return_email)" branch was still referring to my web host email address.  Even though in build_message, it was being set to blank, and echo statements confirmed that.

Finally, I decided to go back to member.php, and call the native PHP mail function if it was an aol email address.

Also, for aol addresses, I put the "from" email address directly after "From:", and the MyBB username in "<>" brackets.

This is now my logic, from line 2846:


++++++++++++++++

        else
        {
            //$from = "{$mybb->input['fromname']} <{$mybb->input['fromemail']}>";   ** original code **
            
            // BEGIN CHANGE
            // if sending to aol email address, keep original from email address.  Don't pass a reply-to email address.
            if (stripos($to_user['email'], "@aol.com") !== FALSE)
            {
                $from = "From: {$mybb->input['fromemail']} <{$mybb->input['fromname']}>";
                $mybb->input['fromemail'] = "";    
                                
            }
            
            // keep sender in user to user email as reply-to during my_mail call below.  But change the from to the web host email address.            
            else
            {
                $from = 'WEB HOST EMAIL ADDRESS';
            }
            
        }
        
        $message = $lang->sprintf($lang->email_emailuser, $to_user['username'], $mybb->input['fromname'], $mybb->settings['bbname'], $mybb->settings['bburl'], $mybb->get_input('message'));
        
        
        // call native PHP mail instead of custom my_mail function for aol
        if (stripos($to_user['email'], "@aol.com") !== FALSE)
        {
            mail($to_user['email'], $mybb->get_input('subject'), $message, $from);
        }
            
        else
        {        
            my_mail($to_user['email'], $mybb->get_input('subject'), $message, $from, "", "", false, "text", "", $mybb->input['fromemail']);
        }
        
        // END CHANGE

+++++++++++++++++++++

This meant I didn't have to have branching logic in 3 places in class_mailhandler.php  (build_message(), set_common_headers().



Now, I can send from yahoo to aol; yahoo to yahoo (own self too); aol to aol; aol to yahoo.

I checked the reply-to to make sure they were coming up properly when I hit those buttons on the email client.

The only thing I can't do is send aol to aol if the user is emailing himself, that still gives this same error:

++++++++++++

   SMTP error from remote mail server after end of data:

   521 5.2.1 :



+++++++++++++++

But I think that's fine, it's not much of a limitation to a user if he can't email himself using MyBB from an aol email address.  He can always email himself using his own mail client.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)