...

View Full Version : PHP Issue



Hostlb
01-19-2010, 07:24 PM
Hello guys , hope everybody is okay .
I'm having a little problem with a php code


<? //enter recipient's email address. If multiple recipients, separate with comma:
$to="someemail@yourdomain.com";
if(isset($_POST['email'])){
if(ereg("^[^@]{1,64}@[^@]{1,200}\.[a-zA-Z]{2,3}$",$_POST['email'])){
mail($to,$_POST['subject'],$_POST['message'],"From: ".$_POST['email']);
echo'<font color="green">Your message was sent</font>';
}else echo'<font color="red">"'.$_POST['email'].'" is not a valid email address.</font>';
}
?><form action="" method="post"><table><tr><td>Your Email:</td><td><input name="email"></td></tr>
<tr><td>Subject:</td><td><input name="subject"></td></tr></table>Message:
<br><textarea rows="8" cols="50" name="message"></textarea><br>
<input type="submit" value="send"></form>


Okay, now to explain more on the issue , the code is working just fine as it now i'm trying to add more text areas & inputs like i want to add more information to be sent within the page like ex: Firstname , Lastname, Arrival Date , ect...
i've added them and prepared tables and everything but my biggest issue get related to $_POST

Check here .


mail($to,$_POST['subject'],$_POST['message'],"From: ".$_POST['email']);
Now in $_POST['message'] , it's working but when trying to add more inputs like ['L_name'] , or anything else the script stop working and messages never sent .

Any ideas how should i modify the code to fix it .

Best Regards

tomws
01-19-2010, 07:31 PM
You can't just toss parameters at the mail function, if that's what you're trying to do - that's not how it works. Consult the documentation here:
http://php.net/manual/en/function.mail.php

Hostlb
01-19-2010, 08:06 PM
You can't just toss parameters at the mail function, if that's what you're trying to do - that's not how it works. Consult the documentation here:
http://php.net/manual/en/function.mail.php

Dear , what i want to do is simply add more values to be sent in the mail

the code as it's in here send what is typed in the textarea , called ['message'] what if i want to add second textarea and 3rd one for expamle message2 & message3 how should i edit that prefix

$_POST['message']
should i put it like this

$_POST['message'],$_POST['message2'],$_POST['message3']

or it should be typed in another way , because i tired this but it haven't worked .

tomws
01-19-2010, 08:28 PM
Another way, as already suggested. The documentation, linked above, shows that the second argument to the mail function is the message body. Whatever you want to send, cram it all into one variable and use that as the second argument.

Hostlb
01-19-2010, 09:56 PM
I have read the documentation from the top to the end and i have edited my code but after applying the second value the script cease sending
check what i have edited


<? php>
$to="ht.server@gmail.com";
$message=$_POST['message'];
$lname=$_POST['lname'];
if(isset($_POST['email'])){
if(ereg("^[^@]{1,64}@[^@]{1,200}\.[a-zA-Z]{2,3}$",$_POST['email'])){
mail($to,$_POST['subject'], $lname, $message, "From: ".$_POST['email']);
echo'<font color="Blue">Your message was sent</font>';
}else echo'<font color="red">"'.$_POST['email'].'" is not a valid email address.</font>';
}
?>

i have added 3rd and 4th line
and edited the $POST .

I should mention , that it works when using only one value like message or lname , after adding second value it stop sending .

any ideas ?

Regards

tomws
01-19-2010, 10:22 PM
I have read the documentation from the top to the end and i have edited my code but after applying the second value the script cease sending

No, that's still doing it the first way you tried and it's still not going to work - you can't throw in extra parameters out of nowhere. I mis-posted in the last response:


Whatever you want to send, cram it all into one variable and use that as the second argument.

That should say the third argument.

Anything that you want to send as the body of your email must go into the variable that is passed as the third argument to the mail function. It's only as complicated as you want to make it.


$var1 = "I'm ";
$var2 = "a ";
$var3 = "sentence.";

$message_body = $var1.$var2.$var3;
$message_body .= " And I'm another sentence."
$message_body .= " 123 456 789";
$to = "me@example.com";
$subject = "test message";

mail($to, $subject, $message_body);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum