Notifications
Clear all

Did we help you in something? If so, we would very much appreciate if you Share our website or forums link. Thank you!

[Solved] How to email users after they post an ad  

  RSS
Saccao
(@saccao)
New Member

Hello.

I would like to send an email to the user, after he has posted his ad(s). With the ad link and information and maybe some other text.

If there an wasy way to do that? I haven't seen any plugin to do that.

Thanks

Quote
Posted : January 22, 2020 13:24
Topic Tags
Johannes de Sacrobosco
(@johannes-de-sacrobosco)
Eminent Member

There are two ways to do that.

1. Put some functions in your theme's function.php file

2. Create a plugin for all your custom functions, so no changes are overwritten. Do not worry, by "create a plugin" i mean only a dummy skeleton of a plugin. In there you can put the email function and other functions in the future. Piece of cake.

What do you prefer?

ReplyQuote
Posted : January 22, 2020 13:52
Saccao
(@saccao)
New Member

I have no idea about all that you ask.

ReplyQuote
Posted : January 22, 2020 14:08
Johannes de Sacrobosco
(@johannes-de-sacrobosco)
Eminent Member

Understood. I will post both ways.

The easier is to put the following code at the end of your theme's functions, before the closing bracket. Be careful not to add any spaces and you better enable debug to a log to check if everything is working right.

You can modify the text to suit your needs.

 
if(!function_exists('usr_published_sent_email')) {
    function usr_published_sent_email($item) {
        // if(osc_is_web_user_logged_in() && is_array($item)) {
    if(osc_is_web_user_logged_in() && is_array($item)) {

            $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id());
            View::newInstance()->_exportVariableToView('item', $item);
            // $ad = osc_item_url();
			// $ad = '<a href="'. osc_item_url() .'"></a>';
			$ad = '<a href="' . osc_item_url() . '">' . osc_item_url() . '</a>';
            $title = 'Thanks for posting!';

            $body =  'Hi there,<br>';
            $body .= '<br>';
            $body .= 'To see if your published ad: (' . $item["s_title"] . ') looks all good check it out here: <br><br>';
            $body .= $ad . "<br>";
            $body .= '<br>';
            $body .= 'In case the ad looks bad (visually) and breaks our page stucture, it will be removed. :)<br>';
            $body .= '<br>';
            $body .= 'Also you may want to keep this email for your archive. <br><br>';
            $body .= 'Kind regards,<br>';
            $body .= 'Admin & Your Ad(s) Guardian';

            $emailParams =  array('subject'  => $title
                                ,'to'       => $user['s_email']
                                ,'to_name'  => $user['s_name']
                                ,'body'     => $body
                                ,'alt_body' => $body);

            osc_sendMail($emailParams);
        }
    }
    osc_add_hook('posted_item', 'usr_published_sent_email');
}
ReplyQuote
Posted : January 22, 2020 14:20
Johannes de Sacrobosco
(@johannes-de-sacrobosco)
Eminent Member

The second way is to create a folder in your oc-content/plugins and name it whatever you want. "customf" for example.

In there put just an index.php like the one attached. In there you can put all your custom functions.

I hope it is clear, if not feel free post your questions here.

ReplyQuote
Posted : January 22, 2020 14:25
Saccao
(@saccao)
New Member

At first i did the first suggestion and then i tried also the second (after removing the first).

Both works for me. I will stay with the custom plugin since i found a second custom function i want to use and the plugin suits my needs better for the future.

I had no idea a plugin could be created for that purpose and that way.

Many thanks

 

ReplyQuote
Posted : January 22, 2020 21:07
Share: