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
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 6:38 am
Can anyone help me:
I want to send an email and i have a 'sendmail.php' page with this code:
Code: Select all
<form action="include/mail.php" method="POST" name="Mail Send" id="sendmail">
<?php
@$to = $_POST['to'];
@$from = $_POST['from'];
@$subject = $_POST['subject'];
@$message = $_POST['message'];
?>
$to = "";
$email[1] = "caselcoop@caselcoop.pt";
$email[2] = "webmaster@caselcoop.pt";
$email[3] = "marco@caselcoop.pt";
$email[4] = "carlos.coradinho@caselcoop.pt";
$email[5] = "anabela.fialho@caselcoop.pt";
$email[6] = "jorge.ramelhete@caselcoop.pt";
$email[7] = "alberto.ferreira@caselcoop.pt";
$email[8] = "anabela.prudencio@caselcoop.pt";
$email[9] = "dulce.lucas@caselcoop.pt";
$email[10] = "joao.traquina@caselcoop.pt";
$email[11] = "mcoelho123@hotmail.com";
$default_email = "caselcoop@caselcoop.pt"; // To choose default mail address if none chosen
$default_error = "Email Inválido"; // To display error msg if none chosen
$use_error_msg = 0;
$use_default_mail = 1;
// Choose one of the above methods to use
$email_address = $email[$send];
if($email_address == "" xor !isset($email_address) xor $send == "") {
if($use_error_msg == "1") {
$to = $default_error;
} else if($use_default_mail == "1") {
$to = $default_email;
}
// end if email address string is blank
} else {
$to = $email_address;
}
echo " " . $to;
?>
<input name="from" type="text" id="from" size="50" >
<input name="subject" type="text" id="subject" size="50">
<textarea name="message" cols="50" rows="10" id="message" type="text"></textarea>
And in mail.php i have:
Code: Select all
<?php
/*
$to = $to2 . ", ";
$to .= "mcoelho123@hotmail.com";
*/
/*
$subject = $subject2;
$message = "<html><head><title>NET</title></head><body>" . nl2br($message2) . "</body></html>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: NET ' . '<' . $from2 . '>' . "\r\n";
// $headers .= 'Cc: ' . "\r\n";
// $headers .= 'Bcc: ' . "\r\n";
// mail($to, $subject, $message, $headers);
// header("Location: " . "../sendmail.php?msg=sent");
*/
echo "to: " . $to . "<br>";
echo "from: " . $from . "<br>";
echo "subject: " . $subject . "<br>";
echo "message: " . $message . "<br>";
?>
I only have the echo just to try. That is not working the echo $to and the others are.
I think its because the $to is in a variable and from, subject, message are in a input.
How can i do?
Thanks in advance
neophyte
DevNet Resident
Posts: 1537 Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota
Post
by neophyte » Tue Jun 06, 2006 7:04 am
I don't see a input tag with the name 'to'. I might start looking there. If it's not echoing it's not set. Try
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 8:23 am
Its not a input, the 'to' is catched by $_GET like $to = $_GET['send']
I tried like this and get the value of NULL
Code: Select all
<?php
var_dump($_POST['to']);
//@$to = $_POST['to'];
@$from = $_POST['from'];
@$subject = $_POST['subject'];
@$message = $_POST['message'];
?>
Last edited by
mcoelho123 on Tue Jun 06, 2006 8:28 am, edited 1 time in total.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Jun 06, 2006 8:28 am
Try removing the @s from in front of the variable assignments:
Code: Select all
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
instead of:
Code: Select all
@$from = $_POST['from'];
@$subject = $_POST['subject'];
@$message = $_POST['message'];
you really shouldn't be suppressing errors here, if you get an undefined index error then there's something you need to recode to prevent rather than hide the error.
Is the $_POST array sent successfully? What do you get if you do:
Code: Select all
echo '<pre>';
print_r($_POST);
echo '</pre>';
Mac
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 8:31 am
Array
(
[from] => fdgdf
[subject] => gdg
[message] => fdfg
[Enviar] => Enviar
)
It has to be a
[to] => 'email'
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Jun 06, 2006 8:42 am
Apologies, I interpreted the question in a slightly wonky manner, I think what you probably need to do is to add a hidden input to your form which will pass the $to variable's data. So after:
Code: Select all
<input name="from" type="text" id="from" size="50" >
<input name="subject" type="text" id="subject" size="50">
<textarea name="message" cols="50" rows="10" id="message" type="text"></textarea>
just add:
Code: Select all
<input name="to" type="hidden" value="<?php echo $to; ?>" />
Although - you definitely want to have some security in there to prevent any old hacker using your form as a spam relay - doing your e-mail validity checking in the form processing page would be a good idea.
Mac
Last edited by
twigletmac on Tue Jun 06, 2006 8:45 am, edited 1 time in total.
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 8:44 am
And if i insert a input named 'to' it works but i dont want a input i want only to define a variable that is '$to' and then to POST
but what is not workin is the $_POST i think
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Jun 06, 2006 8:47 am
The POST is working fine, however, if you don't have a hidden input or something like that to send the $to variable it can't be passed by the form. If you don't want a hidden input maybe sessions is what you're after?
Mac
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 8:54 am
OK. i insert that line and it shows the value of 'to' but now i dont receive any email
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Jun 06, 2006 9:00 am
What does the code look like that you are now using to prepare and send the e-mail?
Mac
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 9:03 am
And how can i do a e-mail validity check?
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 9:10 am
no, its something wrong
the post its ok but if i do
Code: Select all
echo "to: ". $to . "<br>";
echo "from: ". $from . "<br>";
echo "subject: ". $subject . "<br>";
echo "message: ". $message . "<br>";
it appears:
to: ,
mcoelho123@hotmail.com
from:
test@test.com
subject:
message:
like u see i have two emails in 'to' and only appears one
it should be "
marco@caselcoop.pt ,
mcoelho123@hotmail.com "
the from is ok but the subject and the message either are blank
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 9:13 am
the mail.php is
Code: Select all
<?php
$to = $to2 . ", ";
$to .= "mcoelho123@hotmail.com";
$subject = $subject2;
$message = "<html><head><title>NET</title></head><body>" . nl2br($message2) . "</body></html>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: NET ' . '<' . $from2 . '>' . "\r\n";
// $headers .= 'Cc: ' . "\r\n";
// $headers .= 'Bcc: ' . "\r\n";
// mail($to, $subject, $message, $headers);
// header("Location: " . "../sendmail.php?msg=sent");
echo "to: ". $to . "<br>";
echo "from: ". $from . "<br>";
echo "subject: ". $subject . "<br>";
echo "message: ". $message . "<br>";
?>
mcoelho123
Forum Commoner
Posts: 37 Joined: Tue Jun 06, 2006 6:27 am
Post
by mcoelho123 » Tue Jun 06, 2006 9:22 am
sorry i forget to change the variables. Its ok now
How can i do an e-mail validity check?