Jump to content

Sending email help


maddtechwf
Go to solution Solved by maddtechwf,

Recommended Posts

I'm using PHPMailer and it works great.  The only issue I'm having is that I need to add an extra recipient back on the time of day and whether it's the weekend.  Currently I'm using:

if((date("G") < 6) OR (date("G") > 17) OR (date("N") === 6) OR (date("N") === 7))
{
$mail->addAddress('name@mysite.com', 'My Name');
}

I need to add this person if it's before 6AM or after 5PM during the week and any time on Saturday and Sunday.

 

Can anyone help me with this logic?

Link to comment
Share on other sites

I tried to rewrite it just now.  Was hoping someone could tell me if this logic will work.

if(date("l") == Saturday) OR (date("l") == Sunday)) // Runs if it's Saturday or Sunday
{
     $mail->addAddress('name@mystime.com', 'My Name');
} else {
     if((date("H") < 6) OR (date("H") > 17)) //Checks if before 6AM or after 5PM
     {
           $mail->addAddress('name@mysite.com', 'My Name');
     }
}
Link to comment
Share on other sites

Im sure there are other ways but here is a stab at something to try..

 

Set the off days, and holiday arrays and change the start and stop times to suit your needs

//Set the days off here [i.e. 'Monday', 'Tuesday'.... or 'Wednesday', 'Saturday'...]
$offDays = array('Sunday','Saturday');

//Set the holidays here [Full month and Date]
$holiday = array('January 1', 'March 5', 'April 7');

//Business Hours 
$date = date_create(date('Y-m-d'));
$setNow = date_time_set($date, date('H'),date('i'),date('s'));
$nowTime = date_format($setNow, 'Y-m-d H:i:s');


//set the time you open [If you open at 5:00 a.m. set 5, 0, 0 - if you open at 10:30 a.m. set 10, 30, 0]
$setStart = date_time_set($date, 6, 0, 0);
$startTime = date_format($setStart, 'Y-m-d H:i:s');

//set the time you close [If you close at 5:00 p.m. set 17, 0, 0 - if you close at 10:30 p.m. set 22, 30, 0]
$setStop = date_time_set($date, 17, 0, 0);
$stopTime = date_format($setStop, 'Y-m-d H:i:s');



if( ($nowTime > $startTime && $nowTime < $stopTime) && (!in_array(date('l'), $offDays)) && (!in_array(date('F d'), $holiday)) ){
    //normal busines hour code
    echo"We are open";
}else{
    //after hours / weekend / holiday code
    echo"We are closed";
}
Link to comment
Share on other sites

Hi Tryingtolearn,

 

I really appreciate the code above.  I'm trying to modify the last part of the code to only add an email recipient if it's outside of the start and end time and only on Saturday and Sunday.

 

This is what I came up with.

     $offDays = array('Sunday', 'Saturday');
			
     //Business Hours
     $date = date_create(date('Y-m-d'));
     $setNow = date_time_set($date, date('H'),date('i'),date('s'));
     $nowTime = date_format($setNow, 'Y-m-d H:i:s');
			
     $setStart = date_time_set($date, 6, 0, 0);
     $startTime = date_format($setStart, 'Y-m-d H:i:s');
			
     $setStop = date_time_set($date, 17, 0, 0);
     $stopTime = date_format($setStop, 'Y-m-d H:i:s');
			
     if(($nowTime < $startTime && $nowTime > $stopTime) OR (in_array(date('l'), $offDays))
     {
          $mail->addAddress('my.name@mysite.com', 'My Name');
     }
Edited by maddtechwf
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.