mail() in PHP

AngryJim

Limp Gawd
Joined
Apr 20, 2006
Messages
234
I am very new to PHP, so pardon my ignorance.

I've been trying to create a mail form in PHP for a site I'm working on but I've gotten stuck. I've been using the following format from the books I've been learning out of:

$to = "[email protected]";
$subject = "You got Mail!";
$message = "This is the message";
$header = "From: [email protected]";

mail($to,$subject,$message,$header);

I've been substituting my own values for the above information and having zero luck. Even typing the examples given in the books exactly as they appear gives me no results. I've been to about a dozen websites looking for information on this and they all pretty much provide the same template.

Just to be clear, the form shows up just fine, but when submitted with my own email address in the proper location gives me nothing in my inbox.

I'm not sure if this is the problem, but I'm running these pages on my personal laptop. It is connected to the internet and serving pages with the latest versions of Apache and PHP5. Is this the problem? Doesn't seem to make sense to me, I don't understand how my laptop connected to the internet running Linux, Apache, and PHP5 is any different from a server connected to the internet running the same applications, but then again I am very new to this.

Thanks and merry xmas.
 
Check and make sure your php.ini file is setup correctly. I use IIS mostly not apache so not sure how smtp/whatever should be set up for you.
 
you need to have mail() setup correctly if you are running it locally. It is not going to just magically send an email with no smtp server etc etc.

The problem with mail() is that there is no way to read the errors, the function will just execute.

So basically, if you are running it locally, you need to do more configuration to send emails from mail();
 
None of the books or websites I've consulted have mentioned anything regarding this (either in the sections on mail() or the initial setup chapters).

Currently searching around for info on setting this up properly, thanks for pointing me in the right direction.
 
i've suggested it before and will again.

just give up on trying to do it with mail() and get phpmailer
http://phpmailer.codeworxtech.com/index.html

it's fairly easy to get going
you don't have to deal with nitty gritty email headers
maybe it's a fairly large library but the ease of use far outweighs any negatives imo

the easiest way to get it going is to have an email account where you can get smtp access and know the server info for that. this is usually trivial if you pay for hosting. if it's on a test server you may have to figure something else out. some smtp servers don't let you send mail if you don't log in from the same machine, it just depends.

as mentioned, you would need to set up php's mail settings anyway so since you have to go through the trouble of getting smtp access you may as well use it with a feature rich library instead of just mail()
 
Thanks for the info, I'll check it out when I get a chance. I've currently moved back to working on my php/mysql code, I was making way more progress with that and I really never should have sidetracked myself with this email stuff.

I really don't intend to run a full mail server, I only need the ability to send email for a single form that submits directly to me. The ability for PHP mailer to work with Gmail looks interesting, so I'll probably try that. Thanks for the info.

By the way, I will probably be setting up my site with Slicehost, so getting smtp server info from my host wasn't really an option, which is why I was so lost to begin with.
 
Hey Tim, quick question, since I'm just sending the results of this form to myself, would it cause any problems with PHP Mailer if all messages were to me, from me, using the same Gmail address for both?
 
There is also a good chance that everything is working fine with mail(), but your ISP is blocking port 25 traffic out (if this is a local box). This is fairly common on some of the larger ISPs are they try to keep virii from being spread.
 
Back
Top