maddtechwf Posted February 9, 2015 Share Posted February 9, 2015 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('[email protected]', '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 https://forums.phpfreaks.com/topic/294483-sending-email-help/ Share on other sites More sharing options...
maddtechwf Posted February 9, 2015 Author Share Posted February 9, 2015 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('[email protected]', 'My Name'); } else { if((date("H") < 6) OR (date("H") > 17)) //Checks if before 6AM or after 5PM { $mail->addAddress('[email protected]', 'My Name'); } } Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505287 Share on other sites More sharing options...
CroNiX Posted February 9, 2015 Share Posted February 9, 2015 Not quite because you didn't put quotes around the Saturday or Sunday strings in your comparisons. Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505290 Share on other sites More sharing options...
tryingtolearn Posted February 9, 2015 Share Posted February 9, 2015 also looks like date("H") > 17 wont trigger until it is 6:00 pm, not after 5:00 pm do you need to factor in holidays for this? Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505291 Share on other sites More sharing options...
tryingtolearn Posted February 10, 2015 Share Posted February 10, 2015 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 https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505321 Share on other sites More sharing options...
maddtechwf Posted February 10, 2015 Author Share Posted February 10, 2015 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('[email protected]', 'My Name'); } Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505341 Share on other sites More sharing options...
tryingtolearn Posted February 10, 2015 Share Posted February 10, 2015 Change if(($nowTime < $startTime && $nowTime > $stopTime) OR (in_array(date('l'), $offDays)) to if(($nowTime < $startTime || $nowTime > $stopTime) || (in_array(date('l'), $offDays))) Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505356 Share on other sites More sharing options...
maddtechwf Posted February 10, 2015 Author Share Posted February 10, 2015 Thanks for all of the help. Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.