View Full Version : Using php info to check if mail function is enabled
mathew edison
04-30-2008, 06:51 PM
Ok so I know how to use the phpinfo function however the problem is that I don't know how to identify only the mail function so I was wondering if there was any way in which I could use the phpinfo to check if the mail function is enabled by the host/server. Basically what I need is a script that allows me to check the mail function of the host/server and if it proves to be enabled allow the user to continue the install and else echo an error. Any suggestions would be appreciated!
Iszak
04-30-2008, 07:31 PM
<?php
$to = "email@example.com";
$header = "From: {$to}";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body, $header)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
sourcE: http://www.trap17.com/index.php/how-enable-mail-function-php_t35581.html
is it that hard to use google?
Inigoesdr
04-30-2008, 08:14 PM
http://php.net/function.mail
Return Values
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
kbluhm
04-30-2008, 09:44 PM
Duh... stupid mental slip.
if ( function_exists( 'mail' ) )
{
echo 'mail() is available';
}
else
{
echo 'mail() has been disabled';
}
do function_exists('mail') or is_callable('mail') not work with disabled functions? I've never disabled anything, but I'd think either would work...
kbluhm
04-30-2008, 09:56 PM
That is a good question. It had occurred to me, but I've never even tried it.
It would make sense that if the function was disabled, both of them would fail.
...
Yeah, just use function_exists.
mlseim
05-01-2008, 04:06 AM
Gjay ...
I wondered about the same thing you're talking about.
I just didn't have any way to test it, so I didn't say anything.
Let's see if someone that has their own server and can experiment for us
and give us the real answer as to whether those commands work or not.
PappaJohn
05-01-2008, 04:15 AM
Not that I've tried it, but a note from the php manual for function_exists():
Note that a function name may exist even if the function itself is unusable due to configuration or compiling options (with the image functions being an example). Also note that function_exists() will return FALSE for constructs, such as include_once() and echo().
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.