Kate
Kate

Reputation: 287

Temporarily change Timezone to that of email recipient

Is there a way to set the time zone for one specific email at a time in PHPMailer?

People want their notification emails to be in their time zone (so they don't have to do the math), but everywhere else in the app needs to be whatever it's set to already, so global (date_default_timezone_set(‘Asia/Calcutta’);) and config file editing is out of the question.

Any hints?

Upvotes: 1

Views: 1391

Answers (2)

Marcin Orlowski
Marcin Orlowski

Reputation: 75646

date_default_timezone_set() is NOT global. What is set global sits either in php.ini or is set via .htaccess. Calling date_default_timezone_set() sets TZ in scope of invoking script only, so simply calling it prior building mail should be perfectly sufficient

Upvotes: 6

Emissary
Emissary

Reputation: 10148

The DateTime object makes it a breeze :)

$myTime = new DateTime('now', new DateTimeZone('Europe/London'));
$myTime->setTimeZone(new DateTimeZone('Asia/Calcutta'));

example

Upvotes: 4

Related Questions