How to email users ...
 
Notifications
Clear all

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

6 Posts
2 Users
0 Reactions
773 Views
(@saccao)
Posts: 3
Active Member
Topic starter
 

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

 
Posted : January 22, 2020 15:24
Topic Tags
Johannes de Sacrobosco
(@johannes-de-sacrobosco)
Posts: 83
Member Moderator
 

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?

 
Posted : January 22, 2020 15:52
(@saccao)
Posts: 3
Active Member
Topic starter
 

I have no idea about all that you ask.

 
Posted : January 22, 2020 16:08
Johannes de Sacrobosco
(@johannes-de-sacrobosco)
Posts: 83
Member Moderator
 

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');
}
 
Posted : January 22, 2020 16:20
Johannes de Sacrobosco
(@johannes-de-sacrobosco)
Posts: 83
Member Moderator
 

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.

 
Posted : January 22, 2020 16:25
(@saccao)
Posts: 3
Active Member
Topic starter
 

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

 

 
Posted : January 22, 2020 23:07