So I have a function in my wordpress custom theme witch I am using in all my forms. This function is in my wordpress functions.php and look like :
function mail_utf8($to, $subject = '(No subject)', $message = '', $from , $header = '') {
$header_ = "From: $from" . "
" . 'MIME-Version: 1.0' . "
" . 'Content-type: text/plain; charset=UTF-8' . "
";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
}
So the question is - Does this function is executing all the time, when some on refresh page? Or the function is executing only when I call it?
Because, I am getting from my host massages, that I have exceed the mail limit every hour. When I removed this function and hard coded in every form, everything is all right.
I tried :
if( !empty( $message ) ) {
function mail_utf8($to, $subject = '(No subject)', $message = '', $from , $header = '') {
$header_ = "From: $from" . "
" . 'MIME-Version: 1.0' . "
" . 'Content-type: text/plain; charset=UTF-8' . "
";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
}
}
but it didnt work
If you don't have an opcode cache, this code is going to be parsed each time someone loads the page (loads/includes the file containing this code).
But it's only going to be executed when someone calls it.
Note: there is no point of specifying default arguments before $from
because that field is mandatory.
Function executes only when something calls it. Calling function looks like some_fnc(arg1, arg2)
.
What you showed us is a function declaration. To actually call it one should write mail_utf8('some@email.com')
. Look for it in your code and comment out if needed with \\
symbols.
What you did actually can cause fatal error now: when something will try to call mail_utf8()
without $message
set function will not be declared and script will exit with error:
PHP Fatal error: Call to undefined function mail_utf8()