issue in passing variable to a mail function

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
robin1
Forum Newbie
Posts: 20
Joined: Thu Aug 01, 2002 4:36 pm

issue in passing variable to a mail function

Post 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...
User avatar
cybaf
Forum Commoner
Posts: 89
Joined: Tue Oct 01, 2002 5:28 am
Location: Gothenburg Sweden

Post 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
robin1
Forum Newbie
Posts: 20
Joined: Thu Aug 01, 2002 4:36 pm

Post by robin1 »

Hi Cybaf,
I tried that too and probblem still remains.
User avatar
cybaf
Forum Commoner
Posts: 89
Joined: Tue Oct 01, 2002 5:28 am
Location: Gothenburg Sweden

Post by cybaf »

does it work if you do:

Code: Select all

mail($ecmd,$classified_subject,$edescfield,$eaddress);
??
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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()
Post Reply