Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email script in PHP 1

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
Hi All,
I am trying to help out the local Parent Teachers Organization (PTO) with their web site.
I am wondering if PHP typically comes with an email handler that can be used to submit email messages from forms on the web site.
The site was setup a long time ago and nobody currently has much information on it. When I email the hosting service I get automated responses back but never any answers.

So I wonder if there is a default mail handler included with PHP that I can submit forms from their web site through email.
And if the answer is possibly yes but dependent upon server or PHP versions is there an easy way for me to determine these?

If I had to I could push the form data through my home server and route it out as email but my server it just for learning and play and may not be consistantly available so...
The other alternative would be to store the data and build an interface to read responses on the site itself but that is not the most efficient way for responses from the site to get reviewed.



Stamp out, eliminate and abolish redundancy!
 
PHP has no default mechanism for automatically emailing data from a form. That would have to be handled from within a PHP script.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I know that it's been covered here a lot... I happened to have this script sitting locally. Obviously you will need to set the 'from' and 'to' addresses for your test... but if your PHP is set up (and configured for mail) correctly it ought to work.

Code:
/***
* Email sending test
***/
$from = "fromemail@yourdomain.com";
$to = "toemail@somedomain.com";
$subject = "This is a test email message";
$headers = "mime-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: " . $from . "\r\n";
$body = "<html>\r\n<head>\r\n<style type=\"text/css\">";
$body .= "body {margin:20px;font-family: Verdana, sans-serif;font-size:12px;}";
$body .= "\r\n</style>\r\n</head>\r\n<body>";
$body .= "<h3>Test message</h3>\r\n";
$body .= "<p>This is a test email</p>";
$body .= "\r\n</body>\r\n</html>";
mail($to, $subject, $body, $headers);

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I do not mean automatically handling from the form, I mean does it have a server-side component that will accept the values from a script page and send them as SMTP email.

I know that it is generally the server providing the service such as IIS servers using CDONTS or CDOSYS and ASP is just a mechanism to call upon those objects.
I am hoping though that a component may be included with popular releases of PHP that register themselves with the server during installation.

I can handle the script side though I may need sample code or specs specific to whatever email component is provided.
I just need to know what if any service may be available and have not gotten a response from the hosting service.

Hey, if people have an idea of what is most likely to be available and sample scripts I can put up the code on the server and try it out to see which if any of them work.

I am just hoping that experienced people here would either have an answer, direction on how to get the answer or at least info that would enable me to narrow the scope of what I need to try to find my own answer.


Stamp out, eliminate and abolish redundancy!
 
Thanks Jeff.
Can I assume then that this means there is a default handler to submit the info to? Or that this code is written for the most-likely-to-be-installed handler?

I am learning PHP as I go and can puzzle out the code but I am not familiar with the environment and it's abilities/restrictions yet.

Thanks.

Stamp out, eliminate and abolish redundancy!
 
I'm no php expert... so I bet I get this wrong... but here goes:

You can use the <? php_info() ?> command to display all the modules and settings for the current PHP install you are running.

One of the modules that can be configured is the mail module. My belief is that the mail module comes with the default PHP installation - and that you merely need to configure it (SMTP server etc) and away you go.

My ISP did all the configuration for me... so I have never dealt with that side of things though [smile]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top