Log in

View Full Version : mailform without confirmation



chechu
10-24-2009, 01:45 PM
Hey all.
I have the following mailform code:

<?php
if ($_POST["action"] == "send"){
if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {
mail ("info@net.com", "via NET",
"
Name: ".$_POST['name']."
E-mail: ".$_POST['email']."
Message: ".$_POST['message']."

",

"From: ".$_POST['name']." <".$_POST['email'].">");

$subject = "PLANET confirmation";

$msg = "

This is an automatically sent email. Please do not reply.
Dear $_POST[name],
Thanks for your message to NET.
We will get back to you within two working days.

This was your message:

$_POST[message]

";



mail($_POST[email], $subject, $msg);


echo '<br>&nbsp;<br>Thanks ! <br>&nbsp;<br>Your message has been sent,<br> and you will receive a confirmation mail. <br>&nbsp;<br>&nbsp;<br> NET will get back to you within two working days.<br>&nbsp;<br>&nbsp;<br>';

}



else{

echo '<br>&nbsp;<br><font color="#565656;">Your mail has NOT been sent !</font><br>&nbsp;<br>Please fill in all data.<br>Your name, email adress and message are mandatory fields.<br>&nbsp;<br>&nbsp;<br><a href="about.php"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';

}

}

?>

I would like the same code, but without the confirmation mail sent to the visitor (but with confirmation on the site). Can anyone help me, please ?

In addition I'd need a mandatory select box (drop down) with different emails that are sent too.
F.ex. you can chose between 'webmaster', 'director', 'sales' and then the mails are sent to web@, director@ and sales@

chechu
10-25-2009, 10:19 AM
Anyone, please ?

djr33
10-25-2009, 07:37 PM
For the choice of who it is sent to, just create a dropdown menu in html inside the form: call it "to" and then in the PHP just use that $_POST['to'] as the person who gets the email. That is-- in the second line of code, replace "info@net.com" with $_POST['to'].

To not send the email to the user, delete all this:

$subject = "PLANET confirmation";

$msg = "

This is an automatically sent email. Please do not reply.
Dear $_POST[name],
Thanks for your message to NET.
We will get back to you within two working days.

This was your message:

$_POST[message]

";



mail($_POST[email], $subject, $msg); That's all.

chechu
10-25-2009, 08:46 PM
Thanks Daniel. I do not understand the part where I need to call the menu "to". What needs to be added here ?


<script type="text/JavaScript">

function clearDefault(el) {

if (el.defaultValue==el.value) el.value = ""

}

</script>

<form name="form1" method="post" action="contact.php">

<input type="hidden" name="action" value="send">
<table><tr><td align=left valign=top>
<input type="text" name="name" value=" your name" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted #cc6600; border-right:0px; border-bottom: 1px dotted #cc6600; width:160px; margin-top:24px;">

<input type="text" name="email" value=" your email adress" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:160px; margin-top:20px;">

<select>
<option>sales</option>
<option>director</option>
<option>web</option>
</select> <img src="images/vink.gif" border="0" style="padding-left:10px; margin-top:26px;"><input type="submit" value="send" style="border:0px; background-color: #ffffff; margin-top:26px;">

</td><td align=left valign=top>
<textarea name="message" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:240px; height:96px; margin-top:24px;" onfocus="clearDefault(this)"> your message</textarea>

</td></tr></table>
</form>


where "sales", "director" and "web", when chosen, should have the message sent to a different mail adres.

So this then what the php looks like, right ?


<?php



if ($_POST["action"] == "send"){



if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {

mail ("$_POST['to']", "via NET",

"

Name: ".$_POST['name']."

E-mail: ".$_POST['email']."

Message: ".$_POST['message']."



",

"From: ".$_POST['name']." <".$_POST['email'].">");



echo '<br>&nbsp;<br>Thanks ! <br>&nbsp;<br>Your message has been sent,<br> and you will receive a confirmation mail. <br>&nbsp;<br>&nbsp;<br> NET will get back to you within two working days.<br>&nbsp;<br>&nbsp;<br>';



}



else{

echo '<br>&nbsp;<br><font color="#565656;">Your mail has NOT been sent !</font><br>&nbsp;<br>Please fill in all data.<br>Your name, email adress and message are mandatory fields.<br>&nbsp;<br>&nbsp;<br><a href="about.php"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';

}

}

?>

bluewalrus
10-25-2009, 09:16 PM
I think



<select name="to">
<option value="salesemail@.com">sales</option>
<option value="directoremail@.com">director</option>
<option value="webemail@.com">web</option>
</select>

chechu
10-25-2009, 09:22 PM
Works perfectly, thanks !
I had made this mistake in the php:

mail ("$_POST['to']", "via NET",
should be

mail ($_POST['to'], "via NET",

Only thing is, now everyone can see the email adresses. Is there a way to have them in the php file instead of the html ?

bluewalrus
10-25-2009, 09:26 PM
I don't see anything wrong. I just ran a test with test in the fields and got success page. Are you getting an error page, email not being sent, email being sent incorrectly, nothing?



Thanks !

Your message has been sent,
and you will receive a confirmation mail.


CasalPLANET will get back to you within two working days.

chechu
10-25-2009, 09:28 PM
I adjusted the error; see my post above.
But can you do something about the following:

1/ now everyone can see the email adresses. Is there a way to have them in the php file instead of the html ?
2/ the select box is not mandatory now

Thanks for your help !

bluewalrus
10-25-2009, 09:36 PM
yea put the values as 1, 2, 3 in the html. In php


if ($_post['to'] === "1") {
$mail_to = "sales@such.com";
}

if ($_post['to'] === "2") {
$mail_to = "director@such.com";
}
if ($_post['to'] === "3") {
$mail_to = "web@such.com";
}

mail ($mail_to, "via NET", keep the rest of your code the same from this point

For the being mandatory do you mean it doesn't process the data if the select isn't selected or it doesn't send.

chechu
10-25-2009, 09:41 PM
Like this ?


<?php
if ($_POST["action"] == "send"){
if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {
mail (if ($_post['to'] === "1") {
$mail_to = "sales@such.com";
}
if ($_post['to'] === "2") {
$mail_to = "director@such.com";
}
if ($_post['to'] === "3") {
$mail_to = "web@such.com";
}
mail ($mail_to, "via NET", "
Name: ".$_POST['name']."
E-mail: ".$_POST['email'].
Message: ".$_POST['message']."
",
"From: ".$_POST['name']." <".$_POST['email'].">");
echo '<br>&nbsp;<br>Thanks ! <br>&nbsp;<br>Your message has been sent.<br>&nbsp;<br>&nbsp;<br> NET will get back to you within two working days.<br>&nbsp;<br>&nbsp;<br>';
}
else{
echo '<br>&nbsp;<br><font color="#565656;">Your mail has NOT been sent !</font><br>&nbsp;<br>Please fill in all data.<br>Your name, email adress and message are mandatory fields.<br>&nbsp;<br>&nbsp;<br><a href="about.php"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';
}
}
?>

And this:


<select name="to" style="width:160px; margin-top:26px;">
<option selected value="who do you wish to contact">who do you wish to contact</option>
<option value="1">sales</option>
<option value="2">director</option>
<option value="3">web</option>
</select>


Is the option field now a mandatory field ?

How does it feel to talk to someone who has no clue what he is doing ? ;)

bluewalrus
10-25-2009, 09:46 PM
Remove your first "mail (" on line 4.

So line 4 should read.


if ($_post['to'] === "1") {


For the being mandatory do you mean it doesn't process the data if the select isn't selected or it doesn't send.

chechu
10-25-2009, 09:51 PM
I mean that I want people to select "director" or "sales" or... when sending. When they haven't selected one, the mail shouldn't send and go to the error message, like it does when f.ex. you didn't fill in your name.

This doesn't seem to work:


<?php
if ($_POST["action"] == "send"){
if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {
if ($_post['to'] === "1") {
$mail_to = "info@ce.com";
}
if ($_post['to'] === "2") {
$mail_to = "admin@h.be";
}
if ($_post['to'] === "3") {
$mail_to = "me@post.be";
}
mail ($mail_to, "via NET", "
Name: ".$_POST['name']."
E-mail: ".$_POST['email'].
Message: ".$_POST['message']."
",
"From: ".$_POST['name']." <".$_POST['email'].">");
echo '<br>&nbsp;<br>Thanks ! <br>&nbsp;<br>Your message has been sent.<br>&nbsp;<br>&nbsp;<br> NET will get back to you within two working days.<br>&nbsp;<br>&nbsp;<br>';
}
else{
echo '<br>&nbsp;<br><font color="#565656;">Your mail has NOT been sent !</font><br>&nbsp;<br>Please fill in all data.<br>Your name, email adress and message are mandatory fields.<br>&nbsp;<br>&nbsp;<br><a href="about.php"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';
}
}
?>

bluewalrus
10-25-2009, 09:57 PM
Sorry, captilize the posts.

$_POST

For mandatory change line 2 to


if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "" and $_POST['to'] != "" and $_POST['to'] != "0") {


I'd put in a test field like Select a User and set the option value there to 0. This will make the default value 0 and not equal to an email address I've put this code into the validator statment above as well.

chechu
10-25-2009, 10:03 PM
Still doesn't work.

<?php
if ($_POST["action"] == "send"){
if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {
if ($_POST['to'] === "1") {
$mail_to = "info@erzj.com";
}
if ($_POST['to'] === "2") {
$mail_to = "admin@hetel.be";
}
if ($_POST['to'] === "3") {
$mail_to = "bno@po.be";
}
mail ($mail_to, "via NET", "
Name: ".$_POST['name']."
E-mail: ".$_POST['email'].
Message: ".$_POST['message']."
",
"From: ".$_POST['name']." <".$_POST['email'].">");
echo '<br>&nbsp;<br>Thanks ! <br>&nbsp;<br>Your message has been sent.<br>&nbsp;<br>&nbsp;<br> NET will get back to you within two working days.<br>&nbsp;<br>&nbsp;<br>';
}
else{
echo '<br>&nbsp;<br><font color="#565656;">Your mail has NOT been sent !</font><br>&nbsp;<br>Please fill in all data.<br>Your name, email adress and message are mandatory fields.<br>&nbsp;<br>&nbsp;<br><a href="about.php"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';
}
}
?>

FYI, this is where I am testing (http://casalplanet.com/testabout.php)

bluewalrus
10-25-2009, 10:08 PM
cancel that

on line 17 you lost a quote

E-mail: ".$_POST['email'].
"Message: "

chechu
10-25-2009, 10:11 PM
I get an error 500

bluewalrus
10-25-2009, 10:15 PM
I'm not getting a 500, I'm getting a blank page. Did you try my post before this one? I hadn't seen it was a blank page i thought the problem was the code. If you get another blank page error say it's blank. To be sure it's blank hit view source nothing should be there.

chechu
10-25-2009, 10:19 PM
I hadn't een your post, sorry. Now the form works, but when the mail is not sent (did'nt select an option), this message appears:

TO IS EQUAL TO: who do you wish to contact
Your mail has NOT been sent !
Please fill in all data.
Your name, email adress and message are mandatory fields.
[again please]


When it has been sent (selected an option and filled in all fields), this message appears:

TO IS EQUAL TO: 1
TO IS 1
Was to set?
Thanks !
Your message has been sent.
NET will get back to you within two working days.

bluewalrus
10-25-2009, 10:23 PM
Okay then it's working...i think did you get an email when it was set to 1? The problem with mandatory is... assuming you changed your second line change it once more from "0" to "who do you wish to contact".

The != means not equal to so those statements on line 2 say if such and such is not equal to nothing and not equal to the starting value then process them.

chechu
10-25-2009, 10:26 PM
You mean place this ?


<select name="to" style="width:170px; margin-top:26px;">
<option selected value="0">who do you wish to contact</option>
<option value="1">safaris in africa</option>
<option value="2">places for rent in BsAs</option>
<option value="3">ski in Argentina</option>
</select>

With that change, this appears:


TO IS EQUAL TO: 0
Your mail has NOT been sent !
Please fill in all data.
Your name, email adress and message are mandatory fields.
[again please]

bluewalrus
10-25-2009, 10:29 PM
When does that appear when nothing is selected?
When any are selected?

chechu
10-25-2009, 10:31 PM
Please try it yourself here (http://casalplanet.com/testabout.php)
Send as many mails as you like ;)

bluewalrus
10-25-2009, 10:33 PM
Looks like it's working to me just remove the echos. Are you not getting emails?

DONT REMOVE ALL ECHOS. If you dont know which to remove please ask.

chechu
10-25-2009, 10:35 PM
I received your 2 test emails so far.

May I ask you which echo's to remove, please ? ;)
Walrus, I have NO IDEA of php !

Please note that now the mail is sent without selecting an option !

chechu
10-25-2009, 10:37 PM
No, sorry, the mail gets not send, but the message on the site says it has !

bluewalrus
10-25-2009, 10:39 PM
Can you post your full php code? I'll remove the echos you don't need and look for the unknown !. I'll post back in about 1/2 hour gotta run right now.

chechu
10-25-2009, 10:41 PM
This is the php so far:


<?php
echo "TO IS EQUAL TO: " . $_POST['to'] . "<br />";
if ($_POST["action"] == "send"){
if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {
if ($_POST['to'] === "1") {
echo "TO IS 1<br />";
$mail_to = "info@cego.com";
}
if ($_POST['to'] === "2") {
echo "TO IS 2<br />";
$mail_to = "admin@hrdeel.be";
}
if ($_POST['to'] === "3") {
echo "TO IS 3<br />";
$mail_to = "bro@post.be";
}
echo "Was to set?<br />";

mail ($mail_to, "via NET", "
Name: ".$_POST['name']."
E-mail: ".$_POST['email']."
Message: ".$_POST['message']."
",
"From: ".$_POST['name']." <".$_POST['email'].">");
echo '<br>&nbsp;<br>Thanks ! <br>&nbsp;<br>Your message has been sent.<br>&nbsp;<br>&nbsp;<br> NET will get back to you within two working days.<br>&nbsp;<br>&nbsp;<br>';
}
else{
echo '<br>&nbsp;<br><font color="#565656;">Your mail has NOT been sent !</font><br>&nbsp;<br>Please fill in all data.<br>Your name, email adress and message are mandatory fields.<br>&nbsp;<br>&nbsp;<br><a href="about.php"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';
}
}
?>

And this is the form:


<select name="to" style="width:170px; margin-top:26px;">
<option selected value="0">what is your message about</option>
<option value="1">safaris in africa</option>
<option value="2">places for rent in BsAs</option>
<option value="3">ski in Argentina</option>
</select>

Regarding the not sending of message when not selected an option, but showing the 'message sent': could it have to do with the selected value="0" ?

bluewalrus
10-25-2009, 11:13 PM
Not sure try just value though, I think the default value is the first value so you should be all set there anyway.


<?php
if ($_POST["action"] == "send"){
if ($_POST['name'] != " your name" and $_POST['name'] != "" and $_POST['email'] != " your e-mail adress" and $_POST['email'] != "" and $_POST['message'] != "" and $_POST[to] != "" and $_POST['to'] != "0") {
if ($_POST['to'] === "1") {
$mail_to = "info@cego.com";
}
if ($_POST['to'] === "2") {
$mail_to = "admin@hrdeel.be";
}
if ($_POST['to'] === "3") {
$mail_to = "bro@post.be";
}
mail ($mail_to, "via NET", "
Name: ".$_POST['name']."
E-mail: ".$_POST['email']."
Message: ".$_POST['message']."
",
"From: ".$_POST['name']." <".$_POST['email'].">");
echo '<br>&nbsp;<br>Thanks ! <br>&nbsp;<br>Your message has been sent.<br>&nbsp;<br>&nbsp;<br> NET will get back to you within two working days.<br>&nbsp;<br>&nbsp;<br>';
}
else{
echo '<br>&nbsp;<br><font color="#565656;">Your mail has NOT been sent !</font><br>&nbsp;<br>Please fill in all data.<br>Your name, email adress and message are mandatory fields.<br>&nbsp;<br>&nbsp;<br><a href="about.php"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';
}
}
?>

chechu
10-25-2009, 11:25 PM
All works well, except that, when not selecting an option, the mail does not get sent, but the message that the mail has been sent, appears. How come ?

bluewalrus
10-26-2009, 01:19 AM
I'm going to run 4 tests.

Test one nothing be entered returned this.





Your mail has NOT been sent !

Please fill in all data.
Your name, email adress and message are mandatory fields.


[again please]

Test two



Thanks !

Your message has been sent.


NET will get back to you within two working days.


Test three



Thanks !

Your message has been sent.


NET will get back to you within two working days.

test four


Thanks !

Your message has been sent.


NET will get back to you within two working days.


If this is working you should have 3 emails with subject email and message all being the same, but different per email address. If you do not let me know which you did not get.

chechu
10-26-2009, 08:02 AM
Sorry, but I had to go yesterday. I didn't receive test1 (good), received test2 and test3, but test4 is missing. I hope you still remember what you tested last night ! ;)

The issue is that, when you fill in name, email and message, but do not select an option
1/ the mail does not get sent (good !)
2/ the message on the site says the mail has been sent (no good !)

How come ?

bluewalrus
10-26-2009, 01:57 PM
You never changed the value in your html

<option selected value="what is your message about">what is your message about</option>

You should get an email because of that too though...

chechu
10-26-2009, 08:24 PM
But you asked me to place it like this:


<option selected value="0">what is your message about</option>

When I change it back into the following, it still doesn't work:


<option selected value="what is your message about">what is your message about</option>

djr33
10-27-2009, 12:54 AM
Why would you have a nonfunctioning option in the select menu? Just have the three VALID options (so the form will never be sent without a valid recipient) and format it like this:
Send to: [select], with options 1-3 in the list.

chechu
10-27-2009, 10:52 AM
Don't really understand your remark, Daniel.
I need to have aan option selected value to point out what the dropmenu is about, no ?
What does your new format mean ? Something to be implemented in the php ?

I would like the option to be obligated, so an option must be chosen in order to send the email.
Also if possible, can the option be placed in the confirmation mail and the mail sent to the opted choice ?
Something like
"Thanks for your message to [option]. He will get in touch ..."