PDA

View Full Version : Having option of email recipient in form mail ?



Eternal_Howl
12-23-2007, 02:03 AM
Hi there,

I have a script I acquired from another site and it works fine, but I would like to have the option to let the user choose whether they send the email to the artist or the webmistress by either selecting from a drop down option or checking a box or radio button.

Is it possible to do this? Currently, all mail goes to both of us, but for the artist's privacy, I would like them to have their own email that goes exclusively to them and one for the webmistress. Does that make sense?

djr33
12-23-2007, 02:07 AM
Well, it's very possible. But the code would need to be changed so it does that. Send the dropdown value as the email for the to parameter of the mail() function. But we have no idea how the script works beyond such guesses without you actually posting at least part of the code.

If you can't/won't, then all I can say is that you could setup two separate forms, or submit to two different pages based on the dropdown menu.

thetestingsite
12-23-2007, 02:08 AM
You would need to post the code for us to modify it, but it is definitely possible. If you look through a few threads in this section, you will find some scripts that actually fit your needs.

Hope this helps.


Sorry dj, cross posted.

Eternal_Howl
12-23-2007, 02:32 AM
Thanks for your quick replies!


// $mailto - set to the email address you want the form
// sent to, eg
//$mailto = "someone@somewhere.com" ;

$mailto = 'someone@somewhere.com';

// $subject - set to the Subject line of the email, eg
//$subject = "Feedback Form" ;

$subject = "Website Enquiry" ;

$formurl = "http://www.example.com/feedback.html" ;
$errorurl = "http://www.example.com/error.html" ;
$thankyouurl = "http://www.example.com/thankyou.html" ;

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$fromemail = "From: someone@somewhere.com";
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"$fromemail", $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;

?>
This is the .php I've altered the email address it's going to so the bots don't grab it :)



<form action="http://www.ravenouspathogen.com/contact.php" method="post">
<table border="0" bgcolor="#000000" cellspacing="5">
<tr><td><font face="garamond">Name:</td><td><input type="text" size="30" name="name"></td></tr>
<tr><td><font face="garamond">Email address:</td><td><input type="text" size="30" name="email"></td></tr>
<tr><td valign="top"><font face="garamond">Enquiry:</td><td><textarea name="comments" rows="10" cols="40"></textarea></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" value="Send" style="color: black; font-family: verdana; font-size: 10pt; font-weight: bold; background-color: white;" class="send"></td></tr>
</table>
</form>
And that's the actual form script on the html page.
On the form, it should simply be a case of:

Select Email Recipient
<input type="radio" name="emailto" value="artist"> Artist
<br>
<input type="radio" name="emailto" value="webmistress"> Webmistress
Or something like that, right? I've never in my life used radio buttons - never had a need to, so maybe I'm a little out. But then there's still the matter of modifying the php to get it to send it where it's meant to go.

I had a look through the forum for an answer to my question, but the closest thing I came to was a javascript fix.

djr33
12-23-2007, 05:32 AM
$mailto is set near the top of the page. Set that to the value of your dropdown.
Or, use a number for that dropdown value, 0 and 1.
Then just use if ($_POST['dropdownname']===1) { $mailto = 'what@ever.1'; } else { $mailto = 'an@other.2'; }

Eternal_Howl
12-23-2007, 09:29 AM
Okay, I have the drop down box, but for some reason I'm not understanding what you mean about setting the option value to the dropdown in the $mailto section of the script at the top.
I tried $mailto = 'someone@somewhere.com', 'someoneelse@somewhere.com'

and then I tried $mail to = 'recipient'

followed by the bit of code further down in the isset and made it reflect the email addresses, but I it's coming up with parse errors saying something was identical and expecting '/' or and I KNOW I didn't quite understand what you meant, but tried many variables to see if I could figure it out. I also looked on the web.

A couple of years ago I bought a book with the intention in mind of learning php and learning to do my own scripts and got busy and the book got sold. I wish I had it now as I'm sure what you're telling me is fairly straight forward, but I'm not quite getting it.

thetestingsite
12-23-2007, 03:24 PM
Try this:

contact.html:


<form action="contact.php" method="post">
<table border="0" bgcolor="#000000" cellspacing="5">
<tr>
<td>Send To:</td>
<td>
<select name="mailto">
<option value="test@test.com">Test Name 1</option>
<option value="test2@test.com">Test Name 2</option>
</select>
</td>
</tr>
<tr>
<td><font face="garamond">Name:</td>
<td><input type="text" size="30" name="name"></td>
</tr>
<tr>
<td><font face="garamond">Email address:</td>
<td><input type="text" size="30" name="email"></td>
</tr>
<tr>
<td valign="top"><font face="garamond">Enquiry:</td>
<td><textarea name="comments" rows="10" cols="40"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Send" style="color: black; font-family: verdana; font-size: 10pt; font-weight: bold; background-color: white;" class="send"></td>
</tr>
</table>
</form>


then, contact.php:



<?php

$mailto = $_POST['mailto'];

// $subject - set to the Subject line of the email, eg
//$subject = "Feedback Form" ;

$subject = "Website Enquiry" ;

$formurl = "http://www.example.com/feedback.html" ;
$errorurl = "http://www.example.com/error.html" ;
$thankyouurl = "http://www.example.com/thankyou.html" ;

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$fromemail = "From: someone@somewhere.com";
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"$fromemail", $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;

?>


Hope this helps.

djr33
12-23-2007, 03:49 PM
I would recommend the code highlighted in my post. Just put it where Blizzard's code is in the script.

That would work as well, but in doing so, you open yourself up to be a spam server. Anyone can submit a similar form from their website, or using Javascript, and send to any email they would like.

Alternatively, you could check if the email of $_POST['mailto'] is in an allowed list, but just using a number is:
1. easier
2. prevents people from finding and harvesting your emails in the form, if that appeals to you

Eternal_Howl
12-24-2007, 07:53 AM
Parse error: syntax error, unexpected T_IS_IDENTICAL, expecting ',' or ')' in /home/www/ravenouspathogen.com/contact.php on line 79


To see what I'm doing wrong:
$mailto = $_POST['mailto'];

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$fromemail = "From: info@someplace.com";
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['mailto']===1) { $mailto = 'info@someplace.com'; } else { $mailto = 'webmistress@someplace.com'; }

<tr><td><font face="garamond">Select Recipient:</font></td><td><select name="mailto" size="1">
<option value="1">Artist</option>
<option value="2">Webmistress</option>
</select></td></tr>

I even tried it without the 'isset' - but that just messes things up. At one stage it came up with a syntax error unexpected }

What is so blindingly obvious that I am missing?

djr33
12-24-2007, 06:24 PM
Haha. Yes, you are missing my typo.

if (!isset($_POST['mailto'])===1) { $mailto = 'info@someplace.com'; } else { $mailto = 'webmistress@someplace.com'; }

Eternal_Howl
12-25-2007, 06:06 AM
Hey,
I added your ) but then I got this:


Parse error: syntax error, unexpected '}' in /home/www/ravenouspathogen.com/contact.php on line 83
So I tried taking that out knowing full well the } was part of the format of the script code (like css) and then the page reloads and doesn't send a thing, so I put it back.

djr33
12-25-2007, 06:22 AM
I don't see anything wrong with that. Has the line I wrote, as posted in my previous post, become line 83?

Eternal_Howl
12-25-2007, 07:30 AM
I've repasted the code, including the form variables from the html page as I cannot see what the problem is and I will highlight what is 'line 83' for you. Maybe you can see it.



<form action="http://www.ravenouspathogen.com/contact.php" method="post">
<table border="0" bgcolor="#000000" cellspacing="5">
<tr><td><font face="garamond">Select Recipient:</font></td><td><select name="mailto" size="1">
<option value="1">Artist</option>
<option value="2">Webmistress</option>
</select></td></tr>
<tr><td><font face="garamond">Name:</td><td><input type="text" size="30" name="name"></td></tr>
<tr><td><font face="garamond">Email address:</td><td><input type="text" size="30" name="email"></td></tr>
<tr><td valign="top"><font face="garamond">Enquiry:</td><td><textarea name="comments" rows="10" cols="40"></textarea></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" value="Send" style="color: black; font-family: verdana; font-size: 10pt; font-weight: bold; background-color: white;" class="send"></td></tr>
</table>
</form>


<?php

// ------------- CONFIGURABLE SECTION ------------------------

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto = "info@someplace.com" ;

$mailto = $_POST['mailto'];

// $subject - set to the Subject line of the email, eg
//$subject = "Feedback Form" ;

$subject = "Website Enquiry" ;

// the pages to be displayed, eg
//$formurl = "http://www.example.com/feedback.html" ;
//$errorurl = "http://www.example.com/error.html" ;
//$thankyouurl = "http://www.example.com/thankyou.html" ;

$formurl = "http://www.ravenouspathogen.com/contact.html" ;
$errorurl = "http://www.ravenouspathogen.com/error.html" ;
$thankyouurl = "http://www.ravenouspathogen.com/thankyou.html" ;

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$fromemail = "From: info@someplace.com";
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['mailto'])===1) { $mailto = 'info@someplace.com'; } else { $mailto = 'webmistress@someplace.com'; }

header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"$fromemail", $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;

?>


Oh and Meri Kirihemete - (Maori for Merry Christmas)

Eternal_Howl
12-27-2007, 05:06 PM
Still no joy. I may have to put two forms on the site.