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('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? Quote 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('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'); } } Quote 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. Quote 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? Quote 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"; } Quote 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 (edited) 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 February 10, 2015 by maddtechwf Quote 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))) Quote Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505356 Share on other sites More sharing options...
Solution maddtechwf Posted February 10, 2015 Author Solution Share Posted February 10, 2015 Thanks for all of the help. Quote Link to comment https://forums.phpfreaks.com/topic/294483-sending-email-help/#findComment-1505365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.