Fog Creek Software
Discussion Board




PHP Email

I am not sure if I have the terminolgy correct.

However, I have written a script in PHP, I would like to be able to send an email to the user from the script (ie user enters email address, script is processed, script sends confirmation email to user).

Before I get google-sickness can anyone point me in the right direction. ie would it be a simple script, function, do I need to install a big program...

Aussie Chick
Monday, June 14, 2004

Well, assuming your script in on *nix box, you could just use the mail() function.

See: http://uk.php.net/manual/en/ref.mail.php

Robert Smithson
Monday, June 14, 2004

Might I suggest a quick trip to your local bookstore for a copy of O'Reilly's PHP book?

Mr Jack
Monday, June 14, 2004

I second Robert Smith.

RP
Monday, June 14, 2004

PHP's online docs are excellent.  Have you tried them yet?  If you haven't done so yet download the chm and set it up for F1 help in your editor.
http://www.php.net/download-docs.php

The documentation for the mail() function is here and includes examples:
http://www.php.net/manual/en/function.mail.php

The hardest part of sending mail is getting the configuration right, which you can read about here:

http://www.php.net/manual/en/ref.mail.php

If you have any specific problems search through the additional user comments.  I've always found my answers there.

Ged Byrne
Monday, June 14, 2004

Thanks, I will check those out, I am trying to find out what OS the server is (sent an email through to the guy who hosts my webpage for me).

Aussie Chick
Monday, June 14, 2004

Just write a page that calls PHPInfo.

This should will give you all the server info you need:

http://www.php.net/manual/en/function.phpinfo.php

Ged Byrne
Monday, June 14, 2004

You should also check out the Mail modules in the PEAR repository ( http://pear.php.net ).  They enable the sending of more complex mail messages.

Clay Dowling
Monday, June 14, 2004

I've done this, and it's not hard. But I don't have my code at hand, so I can't just copy/paste the few lines it takes.

As others said, the PHP site is very useful, and googling on the problem will likely turn up a solution.

DaveF
Monday, June 14, 2004

The mail() function works on any platform -- assuming that PHP is configured correctly.

Almost Anonymous
Monday, June 14, 2004

If you are comfortable using classes in PHP, I would also reccommend using PHPMailer.  You can get it at http://phpmailer.sourceforge.net

You might find this especially helpful if you have used ASP mailing componenets like ASP Email or similar.  You essentially define a bunch of properties and then call the send() method and their you go.  This supports SMTP on any OS.

I also agree that PHP makes the mail() function very nice and easy.  Using a class like phpmailer of the one from PEAR just makes it more organized and stuff.

Clay Whipkey
Monday, June 14, 2004

Example:

$to = 'victim@victimdomain.com';
$subject = 'IP Address of user';
$message = $REMOTE_ADDR;
if ( mail( $to, $subject, $message ) )
{
}
else
{
}

I'm a Windows & Delphi guy and even this is easy for me. :-)

Bored Bystander
Monday, June 14, 2004

Interesting. Why would you have not gone to php.net? Expect easy things to be easy and impossible things to be possible (apologies to Larry Wall). Maybe you tried "man php" ... the question is rather amazing really.

But ... that is beside the point. If you accept someone to enter an email and then you send to that email you have sent an invitation to spammers.  I may have misunderstood what you have done ... but if are really doing that then I HIGHLY suggest you track usage and and set an alarm if the script exceeds expected usage ... also, I'd have the alarm shut the script down. I once took over at an ISP where they had these formmail.cgi scripts all over the place and hackers just played with them .... I highly suggest you not put the recipient in the form ... I've used IDs when I needed to do this and then I check if I have an email address associated with the ID and send if I do otherwise I log it as an error. Careful with forms which send email on public websites.

seekingDataModels
Monday, June 14, 2004

I recently wrote a system in PHP using the PHPMailer code Clay mentioned.  Just ripped off their example code and was up and running in ~ 15 minutes.  I had to authenticate to the SMTP server, so mail() didn't work for me.  Has a bunch of other nice features I might use down the road too.

Lee

Lee
Monday, June 14, 2004

One thing. Sending email from PHP using a technique like that for which I gave the example, is pretty secure. The source code of a PHP script (which contains the logic for sending email) doesn't make it to the browser - instead it is consumed by the PHP parser engine.

Whereas: the security issue of formail.cgi is that the arguments to formmail are contained in clear text HTML statements, so it's quite easy to spoof the sending web form and use someone else's CGI to send email from their server.

Bored Bystander
Monday, June 14, 2004

seekingDataModels:

I have looked through the manual, however didn't expect any sort of built-in funciton. Google search brought me up alot of different scripts that had been written. Also I was unsure about platforms, so I asked the question here, and got alot more detailed response which is excellent. I may just being grumpy, but I hate being told to go search when I have, I spend my life doing it. Sometimes I just want to ask a question to real people, and get inciteful feedback.

I am also not worried about spammers, only that the function is being used to send a registration email based on supply of a registration code...

Everyone Else:
Thankyou I am reading those pages now.

Aussie Chick
Tuesday, June 15, 2004

*  Recent Topics

*  Fog Creek Home