
April 17th, 2003, 06:42 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Knoxville, Tennessee (U.S.A.)
Posts: 58
Time spent in forums: 5 m 15 sec
Reputation Power: 8
|
|
|
How Do I Use mail($To, $Subject, $Message) Function Inside Class?
How Do I Use mail($To, $Subject, $Message) Function Inside Class?
Folks;
Below is a class that I am working on. The html form on Page One below outputs the $Email, $About, and $Data variables. The class script on Page Two processes the input information.
At the present time the script on Page Two processes the $Email, $About, and $Data input variables and assigns the values to $Variable1, $Variable2, and $Variable3, respectively. The values are then passed to the " SetAddress", " SetAddress2", and " SetAddress3" functions. And finally, the values are output in the browser window via the SendMail() function with the " $this->To", " $this->Subject", and " $this->Message" snippets as shown below.
But the functionality stops there. I need to go one step further and input the " $this->To", " $this->Subject", and " $this->Message" values into the mail($To, $Subject, $Message) function. I've tried using the following: mail($this->To, $this->Subject, $this->Message) but it won't work.
PHP Code:
//------------- Page One - Text Input Form -------
<?php
print "<html>\n";
print "<body leftmargin=200 topmargin=100>\n";
print "<form action=WorkMail.php method=post>\n";
print "<input type=text name=Email size=15 maxlength=25>Text Field One<p>\n";
print "<input type=text name=About size=15 maxlength=25>Text Field Two<p>\n";
print "<input type=text name=Data size=15 maxlength=25>Text Field Three<p>\n";
print "<input type=hidden name=TextField>\n";
print "<input type=submit value='Click Here'></form><p>\n";
print "</body>\n";
print "</html>\n";
?>
//------------- Page Two - entitled "WorkMail.php" ---
<?php
if ( isset($TextField) ){
//---------------------------
$Variable1 = $Email;
$Variable2 = $About;
$Variable3 = $Data;
//-- Mail Function: mail($To, $Subject, $Message)
class MailClass
{
var $To;
var $Subject;
var $Message;
function SetAddress($Address)//This function tells which e-mail address will be used.
{
$this->To = $Address;
}
function SetAddress2($Second)//This function tells which e-mail address will be used.
{
$this->Subject = $Second;
}
function SetAddress3($Description)//This function tells which e-mail address will be used.
{
$this->Message = $Description;
}
function SendMail()
{
print "The address is: $this->To";//Works ok here.
print "The request is as follows: $this->Subject";//Works ok here.
print "The prospective customer information is: $this->Message";//Works ok here.
//mail($To, $Subject, $Message) --Need to input variables here so sendmail will work.
}
}
$Object1 = new MailClass();//instantiates the class.
$Object1->SetAddress("$Variable1");//sets the "SetAddress" function to $Email.
$Object1->SetAddress2("$Variable2");//sets the "SetAddress2" function to $About.
$Object1->SetAddress3("$Variable3");//sets the "SetAddress3" function to $Data".
$Object1->SendMail();//Outputs the "SendMail()" function.
}else{
print "Didn't work. Try again.";
}
?>
I would appreciate any suggestions. Thank you in advance.
|