Current time: 04-20-2014, 11:28 PM Hello There, Guest! (LoginRegister)


Post Reply 
direct use of my_mail() function vs mailqueue
02-17-2012, 07:06 PM
Post: #1
direct use of my_mail() function vs mailqueue
In one of my plugins I am using the mailqueue to send emails on new posts, however I need to send them with a reply-to header set to the poster email.

One issue is that the send_mail_queue() routine overwrites the Reply-To: header I set in the headers attribute of the mail queue I insert. This occurs in the set_common_headers() function of the mail handler.

So that leaves me with using the my_mail function directly as it supports a $return_email parameter. However, I use this function, the message body looses all the new lines and just shows \r\n\ in the message body.

I find this odd since I am sending the same $db->escape_string($post['message']); variable to both the my_mail() function as well as inserting it into the mail queue

This gives me the correct reply-to, but leaves \r\n as text in the message without any line breaks:
PHP Code:
            my_mail($db->escape_string($notifyuser['email']), 
                    
$db->escape_string($emailsubject), 
                    
$db->escape_string($emailmessage), 
                    
$db->escape_string($post['username'])."<".$db->escape_string($post['email']).">",
                    
""
                    
"",
                    
false,
                    
"text"
                    
""
                    
$db->escape_string($post['email'])
                    ); 

this gives me the correct message body with line breaks, but overwrites the reply-to:
PHP Code:
            $new_email = array(
                
"mailto" => $db->escape_string($notifyuser['email']),
                
"mailfrom" => $db->escape_string($post['username'])."<".$db->escape_string($post['email']).">",
                
"subject" => $db->escape_string($emailsubject),
                
"message" => $db->escape_string($emailmessage),
                
"headers" => 'Reply-To: '.$db->escape_string($post['email'])
            );
            
$db->insert_query("mailqueue"$new_email); 

I can not see where in the my_mail() process that the message is getting double escaped.

Maybe I am just missing the obvious. Can anyone help?

Personal site: CommunityPlugins.com

Please do not PM me for MyBB support here. Use the forums, they are here for a reason. Thanks.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-17-2012, 08:20 PM (This post was last modified: 02-17-2012 08:43 PM by Beardy.)
Post: #2
RE: direct use of my_mail() function vs mailqueue
Would nl2br() not work, to convert the \r\n characters to <br />? Not sure if they'll display as raw-text or HTML inside the email though. E-mail formatting isn't really one of my strong points.

I also looked through the my_mail and send_mail_queue functions and I can't see why the reply-to header isn't getting passed along, but I've never really used MyBB's mail functions so maybe I'm missing something.
Find all posts by this user
Quote this message in a reply
02-17-2012, 08:52 PM
Post: #3
RE: direct use of my_mail() function vs mailqueue
(02-17-2012 08:20 PM)Beardy Wrote:  Would nl2br() not work, to convert the \r\n characters to <br />? Not sure if they'll display as raw-text or HTML inside the email though. E-mail formatting isn't really one of my strong points.

Since I want to send as plain text, it will just display as <br />

(02-17-2012 08:20 PM)Beardy Wrote:  I also looked through the my_mail and send_mail_queue functions and I can't see why the reply-to header isn't getting passed along, but I've never really used MyBB's mail functions so maybe I'm missing something.

In the mail handler is a function called set_common_headers() that tests for a $return_email and uses that as the reply to, if that is not provided it uses the mybb setting for email, but it does this AFTER inserting the headers I specify basically overriding the Reply-To I specify.

But I can not specify the $return_email value when using the built-in mail queue.

Personal site: CommunityPlugins.com

Please do not PM me for MyBB support here. Use the forums, they are here for a reason. Thanks.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-17-2012, 10:02 PM (This post was last modified: 02-17-2012 10:40 PM by Beardy.)
Post: #4
RE: direct use of my_mail() function vs mailqueue
Try using htmlspecialchars() on the message variable instead of $db->escape_string.

Actually, that'll display some characters weird in the e-mail since it won't be displaying HTML. strip_tags() might be better.

I did something like this with strip_tags() and received the e-mail fine:

PHP Code:
$message strip_tags("asd
message on a new line

blank line above<br />"
);

my_mail(
    
"[email protected]"
    
"This is a subject"
    
$message
    
"John Doe"."<[email protected]>",
    
""""false"text"""
    
"[email protected]"
); 

[Image: a7YE8.png]
Find all posts by this user
Quote this message in a reply
02-17-2012, 10:08 PM
Post: #5
RE: direct use of my_mail() function vs mailqueue
the weird thing is that I already use mybb's htmlspecialchars_uni on the message and it works fine when going through the mail queue.

there is something different about how send_mail_queue() processes the message as compared to a direct use of my_mail, which send_mail_queue uses as well.

Personal site: CommunityPlugins.com

Please do not PM me for MyBB support here. Use the forums, they are here for a reason. Thanks.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-17-2012, 10:24 PM
Post: #6
RE: direct use of my_mail() function vs mailqueue
This user has been denied support. This user has been denied support.
$db->escape_string() probably shouldn't be used when you don't actually put it into a database.

Apart from that you have a space missing before < in the from address.

Other than that I don't see anything out of the ordinary, but I didn't test it myself. Maybe you should add a debug in the my_mail function directly and log the exact parameters its called with and see if you can find a difference this way

Google SEO | Gravatar | Hooks | HTMLPurifier | Overview | Patches | PluginLibrary @ GitHub/frostschutz
Find all posts by this user
Quote this message in a reply
02-17-2012, 11:31 PM
Post: #7
RE: direct use of my_mail() function vs mailqueue
(02-17-2012 10:24 PM)frostschutz Wrote:  $db->escape_string() probably shouldn't be used when you don't actually put it into a database.

Apart from that you have a space missing before < in the from address.

Other than that I don't see anything out of the ordinary, but I didn't test it myself. Maybe you should add a debug in the my_mail function directly and log the exact parameters its called with and see if you can find a difference this way

maybe the $db->escape_string is causing it. I just want it to be safe if the post message has html in it. i guess the htmlspecialchars handles that though.

i will try it again

Personal site: CommunityPlugins.com

Please do not PM me for MyBB support here. Use the forums, they are here for a reason. Thanks.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-18-2012, 12:13 AM (This post was last modified: 02-18-2012 12:15 AM by Beardy.)
Post: #8
RE: direct use of my_mail() function vs mailqueue
(02-17-2012 11:31 PM)pavemen Wrote:  maybe the $db->escape_string is causing it. I just want it to be safe if the post message has html in it. i guess the htmlspecialchars handles that though.

i will try it again

If you don't mind using the my_mail function directly after a post has been created (instead of trying to find a solution for the send_mail_queue() problem), my earlier post should work for you.

htmlspecialchars() will display certain characters (<, >, etc) in HTML ASCII, and since the e-mail is being sent as plain-text they won't be displayed properly.

Using strip_tags() will only remove HTML tags (<a></a>, <br />, <hr />, etc) and won't affect single characters.
Find all posts by this user
Quote this message in a reply
02-25-2012, 06:04 AM
Post: #9
RE: direct use of my_mail() function vs mailqueue
i think you want to send email with some headers and <br /> or \n to create new line.

i needed in my email and i did it as following:
$admin_email_message = 'this is test <br /> and you must see a new line in your email.';

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
my_mail($from, $admin_email_subject, $admin_email_message , $from , '' ,$headers);


now my email is showing in html mode and <br /> is working fine

With Regards and many thanks.
------------------------------------------
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication