Can anyone tell me is i want to post the $to with the select box how to do it

i write the code

$to= $_POST['to'];
if($to == ''1") {POST "address 1";}
else {
$to=="0" {POST "address 2"}}

Then i mail will post to email address 1 or 0.

But the code is wrong pls help me to correct it

Recommended Answers

All 5 Replies

$to=stripslashes($_POST['to']);
if($to == '1'){
mail($email, $subject, $message, $headers);
}else {
mail($email, $subject, $message, $headers);
}

Above is an example and for further reading the mail function manual is at http://au2.php.net/function.mail

$to=stripslashes($_POST['to']);
if($to == '1'){
mail($email, $subject, $message, $headers);
}else {
mail($email, $subject, $message, $headers);
}

Above is an example and for further reading the mail function manual is at http://au2.php.net/function.mail

May be i not clear about it. In my index i got a option bar to send email to two different people so what code i need to read

Usually the code is $to=$_POST
with $send = @mail($to, $subject, $body,$headers);

Now i got two so what should i do. if i choose one then it will send to that person only

To make it easier below is a more complete version of my code:

$to=stripslashes($_POST['to']);
$subject='This is a test';
$message='This is a test email and this text will apear in the message body.';
$headers='';
if($to == '1'){
$email='user@gmail.com';
mail($email, $subject, $message, $headers);
}else {
$email='name@hotmail.com';
mail($email, $subject, $message, $headers);
}

Another version of the same thing but with error reporting is as follows:

$to=stripslashes($_POST['to']);
$subject='This is a test';
$message='This is a test email and this text will apear in the message body.';
$headers='';
if($to == '1'){
$email='user@gmail.com';
}else {
$email='name@hotmail.com';
}
if (mail($email, $subject, $message, $headers)) {
echo '<b>Success</b>, email sent to '.$email;
} else {
echo '<b>Failure</b>, try checking your server settings or that you have specified a valid email.';
}

To make it easier below is a more complete version of my code:

$to=stripslashes($_POST['to']);
$subject='This is a test';
$message='This is a test email and this text will apear in the message body.';
$headers='';
if($to == '1'){
$email='user@gmail.com';
mail($email, $subject, $message, $headers);
}else {
$email='name@hotmail.com';
mail($email, $subject, $message, $headers);
}

I want to send the email to other with the drop down box.
When i select the name in the drop down box it will send to that person.

So how??

Another version of the same thing but with error reporting is as follows:

$to=stripslashes($_POST['to']);
$subject='This is a test';
$message='This is a test email and this text will apear in the message body.';
$headers='';
if($to == '1'){
$email='user@gmail.com';
}else {
$email='name@hotmail.com';
}
if (mail($email, $subject, $message, $headers)) {
echo '<b>Success</b>, email sent to '.$email;
} else {
echo '<b>Failure</b>, try checking your server settings or that you have specified a valid email.';
}

I want to send the email to other with a drop down box. when i select the people then it will send to that people only.

So what i need to do??

If $_POST contains the email address then that would not be such a wise idea since it would be open to experienced hackers. I would suggest making a html form like the following then below that is the php code that will process the form.

<?
if (isset($_POST) && !empty($_POST)) {
//set details
$subject='This is a test';
$message='This is a test email and this text will apear in the message body.';

//set email addresses
$email[0]='email1@domain.com';
$email[1]='another@domain.com';
$email[2]='user@gmail.com';
$email[3]='user@hotmail.com';

//decide which email to use
$n=stripslashes($_POST['to']);
$to=$email[$n];
unset($n);

//process email
if (mail($to, $subject, $message)) {
echo '<b>Success</b>, email sent to '.$email;
} else {
echo '<b>Failure</b>, try checking your server settings or that you have specified a valid email.';
}
} //!empty($_POST)
?> <form method="post"><select name="to">
<option value="0">email1@domain.com
<option value="1">another@domain.com
<option value="2">user@gmail.com
<option value="3">user@hotmail.com
</select></form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.