mail() yes again, but different

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MedaXis
Forum Newbie
Posts: 16
Joined: Tue Nov 12, 2002 12:49 pm
Location: the netherlands

mail() yes again, but different

Post by MedaXis »

hi everyone
I recently tried the mail() function in php, but I got this error:

Fatal error: Call to undefined function: mail() in mail.php on line 2

I used this piece of code:

Code: Select all

<?php
mail("me@myprovider.com","testtie","ooh nooo","From: Hi");
?>
why doesn't it work

//I tried the forum search, did find some mail() topics, but none of contain info on the error I got.

Steve
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It's telling you that the mail() function does not exist in your build of PHP, which version of PHP are you using and on what OS are you using it?

Mac
MedaXis
Forum Newbie
Posts: 16
Joined: Tue Nov 12, 2002 12:49 pm
Location: the netherlands

Post by MedaXis »

OS = windows
PHP4

Steve
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Which version of PHP 4 and which version of Windows? How did you install PHP - using the self-installer or manually?

Mac
MedaXis
Forum Newbie
Posts: 16
Joined: Tue Nov 12, 2002 12:49 pm
Location: the netherlands

Post by MedaXis »

okay, I'm sorry I didn't give much info

on the server: php 4.2.3
I'm using win xp

Steve
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tried reinstalling PHP?

Mac
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

mail() should be in php. I would do as Mac suggested and reinstall php. OR maybe it is because that content you have in mail()... I use this format for mailing:

Code: Select all

&lt;?php
  &lt;?
  if($Submit){
  $To = "oromian@hotmail.com";
  $Subject = trim($Subject);
  $Body = trim($msg);
  $Name = trim($from);
  $Email = trim($fromaddy);
  if(mail($To, $Subject, $Body, "From: $Name &lt;$Email&gt;")){
  echo "&lt;b&gt;Thanks! $Name,&lt;/b&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;Your Email was sent!";
  } else {
  echo "&lt;b&gt;Sorry! $Name&lt;/b&gt;,&lt;br&gt;&lt;br&gt;Your Email was not sent!&lt;br&gt;&lt;br&gt;contact me here: oromian@hotmail.com";
  }
  }
  ?&gt;
?&gt;
That is a snipplet of my script i use so people can send me feedback, i see in yours there isn't a proper mailing address nor proper from address, could that be it??
MedaXis
Forum Newbie
Posts: 16
Joined: Tue Nov 12, 2002 12:49 pm
Location: the netherlands

Post by MedaXis »

thanks guys,
I didn't reinstall php, but I tried my file at an account at lycos
it worked
maybe I should have tried that before posting, sorry
anyway, thanks for the replies!

Steve
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

I know why...

Post by evilmonkey »

I know why this happenned. I am running Windows XP with PHP 4.1.1.

The problem is Windows doesn't have a mail server, unliess you install it. Therefore, there is no way for a mail function to work. Once you upload it to a linux server (lycose, whatever), it starts working.

Cheers.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

that would give you an mail error like "error: unknown mail host" or similiar
Fatal error: Call to undefined function: mail() in mail.php on line 2
really means php does not know the function at all ;)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You should probably reinstally PHP locally even though you have a remote host because your version could have other bugs aside from a missing mail() function.

Mac
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Right now, I don't have a php.ini at hand so correct me if I'm wrong...

Isn't mail some kind of extension that has to be enabled in php.ini, when using Windows?

That error message seems like PHP requires a linked library that is not linked.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The mail() function should be built into PHP as standard - you have to tell it where to send mail in the php.ini but the actual function should just be available by default.

Mac
Post Reply