Send emails with PHP by using a predefined function in Osclass in which you only need to add the parameters for that email. Osclass has a predefined function that will send emails and is used in most of the plugins.
Osclass function for sending emails:
osc_sendMail($emailParams);
$emailParams variable is an array that will contain all the email information.
$emailParams = array('subject' => $subject
, 'to' => $to
, 'to_name' => $to_name
, 'body' => $body
, 'alt_body' => $body);
$subject = the subject of this email;
$to = the receiver email address;
$to_name = the name of the receiver;
$body = the content of the email;
Some example of use:
We will send an email every time the cron runs on the site and we will use hourly cron. This is just for testing purposes, you can test this in any other way.
function test_email_osclass() {
$subject = __('Test email in osclass');
$body = __('Hi Admin <br />');
$body .= __('If you receive this email the cron and your email server are running on your site, this was sent by a cron job.<br />');
$body .= __('Time:') . date('Y-m-d H:i:s');
$emailParams = array('subject' => $subject
, 'to' => osc_contact_email()
, 'to_name' => __('Admin')
, 'body' => $body
, 'alt_body' => $body);
osc_sendMail($emailParams);
}
osc_add_hook('cron_hourly', 'test_email_osclass');
osc_contact_email() is the function that returns the site contact email, the email address that will receive all the emails send by osclass on the contact form.