mail() problem

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
nid
Forum Newbie
Posts: 2
Joined: Sat Oct 26, 2002 1:04 am

mail() problem

Post by nid »

Like many I seem to be having problems with mail().

If I try to send a simple message, it works, but it arrives from "root@myserver.myhost.com".

I tried to get around this by plugging in the userid and SMTP settings I use for my email account:

ini_set("sendmail_from","user@mywebsite.com");
ini_set("SMTP","myserver.myhost.com");
phpinfo(); // looks ok
mail("sometest@hotmail.com", "My Subject", "Line 1\nLine 2\nLine 3");


BUT this doesn't work.

Also, one thing I don't get about this is what about the password? When I set up an email account in my email software, I need to supply a userid and password. mail() doesn't seem to allow for this, but everyone (except me) seems to be using it successfully. Can someone fill me in on how this works?

Thanks.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

mail with the from

Post by phpScott »

I don't quite know how this will fit in with your code but this should help solve that from problem.

Code: Select all

<?php

mail ("you@here", "$subject", "$message", "From: <$sender>\n". "Reply-To: <$sender>\n");

?>
phpScott
nid
Forum Newbie
Posts: 2
Joined: Sat Oct 26, 2002 1:04 am

Post by nid »

ok, thanks, that seems to work, but...

if you do this and examine the email (properties/details/message source in Outlook Express), it's still coming from "root@myserver.myhost.com".

I'm thinking of putting together a mass-mailing application (no spam!), and I'm not sure if it's ok to have my host's root id associated with the message... ?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

I don't know

Post by phpScott »

I have never encountered that problem before.
I use a very simillar script and when I looked at the header info in outlook I couldn't see anythin like that. :?
I will do some searching and see what I come up with.
go to http://www.php.net and do a search for mail.
It will come up with all sorts of info for you.

phpScott
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I use this script and guess what it works! So it should wor on yours too.

Code: Select all

<?php
mail("your_email_address","subject","message","From: Hi");
?>
Then in Outlook it should say "From: Hi".
Post Reply