tags:

views:

51

answers:

3

What's wrong with this...? I don't get an email back... Also, does the from address have to be a real address? If I run this on a computer that doesn't have Outlook Express, will it not work? How can I make it work on computers like that?

<html>

<head>
<title>Test php</title>
</head>

<?php
$to = "[email protected]";
$subject = "testing php emailing";
$from = "[email protected]";
$headers = "From: $from";
$message = "Your username is " . $_POST['username'];
if (mail($to,$subject,$message,$headers))
    echo "Mail Sent.";
else
    echo "Problem with mail.";
?>

<body>
</body>
</html>
A: 

You have to send mail from a machine that can be accessed directly from outside - via IP or URL. Having Outlook has absolutely nothing to do with that.

Raveren
what do you mean by "accessed directly from outside"?I just mentioned Outlook because in computer labs, if I click an "email me" link, it'll say you have to configure Outlook before sending an email.
Asj
+1  A: 

If your running the script on a local server you'll need to configure the php.ini look for the following and change to your ISP's SMTP server.

[mail function]
SMTP = smtp.isp.net
sendmail_from = [email protected]

You code will send email, its an issue with your SMTP configuration.

Another way to do it is set SMTP to localhost then use a SMTP service http://www.softstack.com/freesmtp.html usually runs on port 25 If I remember correctly.

cocacola09
can you tell me what the php.ini is, and how to know if it's a local server?
Asj
Are you running PHP from your home or work machine? PHP.ini is the PHP configuration file. Are you running this on a webhost?
cocacola09
I got an account from Free Hostia and put it there, I'm at home, and I want it to work on some computers in a lab.
Asj
You may want to ask "Free Hostia" (whoever they are :) if they allow PHP-mailing. I know of some free webhosters who deactivate mailing to prevent spam.
Select0r
An alternative to modifying php.ini (php config file) is to use ini_set in your script (call these before calling mail() )...ini_set('SMTP', 'smtp.gmail.com');ini_set('smtp_port', '25');
John Himmelman
A: 

Outlook is an email client, you need to connect to an email server, the easy way is to buy a cheap hosting account as this replaces the option where you have to setup your own email server.(Some ISP block port 25 to prevent spam)

DCC