Page 1 of 1

issue in passing variable to a mail function

Posted: Thu Dec 26, 2002 7:07 pm
by robin1
Hello everybody,
somewhat new to php. strange problem, i cant seem to solve...and not sure why its happening either...please have a look and let me know or correct me in what i'm doing wrong..
-email form issue.
- the email form receives the email address from a differnt page.. tested and this part does work. the email is rec. and i used echo to verify this informaton...but if i add the email field in the mail() funciton it does not work..
take a look at the first 4 lines..
<?PHP
$_GET['ecmd']; //works!
//$email_to = "name@hotmail.com"; //this format works!!
$email_to = $ecmd; // this works but not if i put $email_to in mail()!

echo $email_to ; //displays the correct email,works.

$classified_subject = "test subject, you posted this email";
if(isset($sendclassified))
{if (empty($edescfield) || empty($eaddress))
{echo "To send email, all fields must be filled!";}
else
{if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $eaddress))
{echo "E-Mail not valid1"; }
else
{ list($Username, $Domain) = split ("@",$eaddress);
if (getmxrr($Domain, $MXHost))
{$ConnectAddress = $MXHost[0];

/******* problem area --> $email_to ******/
mail($email_to,$classified_subject,$edescfield,$eaddress);
echo "Email sent. Thank you. $email_to"; //works but $email_to is blank
/*******************************************/
}
else
{ $ConnectAddress = $Domain;
print "Email format is correct but your Domain isn't";
}
} //end of else
} // end of if statment that checkes email format and doman anme
}//

html form for user input...

Posted: Fri Dec 27, 2002 7:53 am
by cybaf
If I understood your question correctly I think your problem lies where you assign $email_to the value of $ecmd

when the value is in the mail() function the value is not a string but a variable... so just test to add quotes around the variable $ecmd

not sure if this will help but I've had similar problems.

so:

Code: Select all

$email_to = "$ecmd";
might do it for you

//cybaf

Posted: Fri Dec 27, 2002 8:42 am
by robin1
Hi Cybaf,
I tried that too and probblem still remains.

Posted: Mon Dec 30, 2002 11:42 am
by cybaf
does it work if you do:

Code: Select all

mail($ecmd,$classified_subject,$edescfield,$eaddress);
??

Posted: Mon Dec 30, 2002 1:16 pm
by hob_goblin
try

Code: Select all

mail("$email_to",$classified_subject,$edescfield,$eaddress);


Have you tried echoing eaddress?

Are you sure that you've put in the "From: " part?

Maybe the problems not in email_to, but the other variables in mail()