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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change 'from' in email 1

Status
Not open for further replies.

pelajhia

Programmer
Joined
May 19, 1999
Messages
592
Location
US
Is it possible to change the 'from' when sending via mail()? (eg: feed a variable from a form...) If so, how?
What is the correct syntax, if it is a part of mail()?

THanks!
 
It is definately possible, but depending on your run environment, it takes different methods to do it. On a Linux box running qmail, for example, you have to set or modify environment variables to make the change.

What is your run environment?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
nt2000, just installed php and iis.
Script is running fine but I can't find any info on using a variable as my 'from' email address.
Please let me know if I have not answered the question completely.
THanks.
 
hos2 - I have read this doc before and just reskimmed it; I am not sure where in this one it shows how to do a more 'dynamic' "from" address. Eg: I get user to enter address in html form, then post this to my sending form, and use it as the from address...I don't want a static from, as can be done in the php.ini file.
Am I still missing something on this page?
Thanks.
 
OK, on the Third time looking through this page you sent, hos2, I have found the ini_set() function. Works great to set the sendmail_from var, then resets it after script runs.

Many Thanks!!
 
perhaps you can also use
Code:
$descr="hello here is an email";
$message="with this message";

mail($emailtoaddress,$descr,$message,"From: info@youredomain.com\nReply-to:info@youredomain.com");

ofcourse you can also make it dynamic I think
mail($emailtoaddress,$descr,$message,"From: ". $fromemail."\nReply-to:".$replyemail);

I haven never used the last combination and I don't know if it will suit you're needs even better.

 
So, it looks like you are saying that the mail syntax is as follows:

Takes 4 arguments:
mail(toaddress,subject,body,fromaddress)

I have also seen documentation that seemed to indicate the function would allow for 5 arguments:
mail(toaddress,subject,body,header,from)

I was not able to get this to work other than w/3 args:
mail(toaddress,subject,body), even with varying the php.ini sendmail value (eg: "none", blank, etc.)

Ini_set() is working fine...but I am curious about what arguments total are acceptable to mail().



 
I am using PHP 4.3.4;

I attempted to do this and it only picked up what I had in sendmail_from (the 4th arg is changed in each example):

mail("myaddr@somewhere.org","$data1 - $data2","$more info","","$fromemail");

I also tried:
mail("myaddr@somewhere.org","$data1 - $data2","$more info",,"$fromemail");

as well as:
mail("myaddr@somewhere.org","$data1 - $data2","$more info","$fromemail");
 
and how about
mail("myaddr@somewhere.org","$data1 - $data2","$more info","From: ".$fromemail);

??
 
hos2:
That may or may not work. An MTAs like sendmail and qmail can, depending on configuration, override the "From:" header in the message header section. Qmail always ignores it and overrides with a value from an environment variable. The 5th parameter to the function exists to, for example, invoke the sendmail sending client using the "-f" command-line parameter, which sets the sender.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Came to this forum to see what 'php' is all about.

Generally, would this type of request (changing the "from" adress) be needed for education purposes or purely for the thrill of skill or for masquerading as someone else?

End.

 
It's for a very good use.

A PHP web application will run as the username used by the web server. But you may have multiple sites running on a single server, and each of these sites should have its own email identity.

By changing the identity of the sender of an email, each site on a server can send individualized mail, despite the fact that they are all the same user on the system.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
ananthap-
my purpose is: I will have users enter their email as part of a 'help' form; this form sends to a group email address, then the recipients of the email will only have to hit 'reply' in order to respond (using outlook).
 
Excellent. Thanks. I did not understand what a header was, but now I think it is more clear.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top