Submit form with changeable receiver-address

Hi there

I would like a 2 page solution on a webform.

1st page: should contain a normal webform using eg. sendmail.

2nd page: should contain a field with the "action: send-to email address" used on the 1st page.

The 2nd page will act like a kind of admin page so when the person who has the webform on his website changes the send-to email address from the 2nd page it will be effective on the first page as well..

You hopefully get the picture :)
ilandproAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wildzeroCommented:
Hi there,

Post the code of what you've done so far :-)
0
b0lsc0ttIT ManagerCommented:
ilandpro,

How is page 1 rendered (i.e. server script or just html)?  Is the send-to email in the html, in the server script, or is it from a database, etc that another page can also access and update?

The problem is having page2's choice go to page1.  Without a better idea of how the pages are setup we can't suggest how to do that part.  if it is in the html or in the server script then page2 would have to edit the code of page1.  That doesn't seem to be a great option.  How often will this change be done?

If I misunderstood and you just want page2 to choose the send-to address then that is relatively easy.  I do this on some forms by having a select list of the available emails.  It is best to use something like this so you limit the addresses that can be used; you don't want a typo or misuse to cause some issue with your script or sending the email.

This should at least get you started.  Let me know if you have any questions or what other information you need.

b0lsc0tt
0
ilandproAuthor Commented:
Hi there :)

I thought about something like this:
The email doesnt need to be edited that often but the person Im (suppose) to help wants this feature anyway.. :)
============
Form page:
============
<form method="post" action="sendmail.php">
  Email: <input name="email" type="text" /><br />
  Message:<br />
  <textarea name="message" rows="15" cols="40">
  </textarea><br />
  <input type="submit" />
</form>
 
=============
Sendmail.php:
=============
<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
 
  mail( "$mailtoemail = $_REQUEST ['mailtoemail']", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://www.example.com/thankyou.html" );
?>
 
===========
Admin.php:
===========
Send to this email: <input name="mailtoemail" type="text" />

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Marcus BointonCommented:
This should do the trick. it keeps the destination address in a local text file.

============
Form page:
============
<form method="post" action="sendmail.php">
      Email: <input name="email" type="text" /><br />
      Message:<br />
      <textarea name="message" rows="15" cols="40">
      </textarea><br />
      <input type="submit" />
</form>
 
=============
Sendmail.php:
=============
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$mailtoemail = file_get_contents('mailtoemail.txt');
mail($mailtoemail, "Feedback Form Results", $message, "From: $email" );
header("Location: http://www.example.com/thankyou.html");
?>
 
===========
Admin.php:
===========
<form method="post" action="admin.php">
Send to this email: <input name="mailtoemail" type="text" />
<input type="submit" />
</form>
<?php
if (isset($_POST['mailtoemail']))
      file_put_contents('mailtoemail.txt', trim($_POST['mailtoemail']));
?>
0
ilandproAuthor Commented:
Thanks Squinky!

This is perfect. Only one thing remains: I woud like the email currently in the textfile to be shown in the field in admin.php - in case he forgets what email he's using

Hope its not too diffucult :)
0
Marcus BointonCommented:
<form method="post" action="admin.php">
Send to this email: <input name="mailtoemail" type="text" value="<?php file_get_contents('mailtoemail.txt'); ?>"/>
<input type="submit" />
</form>
<?php
if (isset($_POST['mailtoemail']))
      file_put_contents('mailtoemail.txt', trim($_POST['mailtoemail']));
?>
0
ilandproAuthor Commented:
Hi again

Im sorry but it does put any values in the field. In fact it looks just like before.
It doesnt has to be in  the field if this causes problems.

It could also say 'Currently this mail is used: <value>

Is the PHP sendmail more likely to get caught by spamfilters than the sendmail in Perl?
I have tested the form with 4 different emails accounts:
- 1 recieved it okay
- 2 caught it in the spam folder
- 1 didnt got through

Thanks,
0
Marcus BointonCommented:
Well, I did forget to echo it... Also it won't display an email address until you've set one, so enter one and submit it then hit the page again and it should be populated. Also you need to make sure that the web server has write permission in the folder the script is running in. It makes sense to change the order of events in the admin script. Revised version below.

No difference between PHP and Perl for email, though I would recommend very strongly that you use a PHP mail class such as phpmiler or swiftmailer as otherwise it's extremely likely you will create non-RFC-compliant messages that are more likely to get blocked/spamfiltered.
<?php
if (isset($_POST['mailtoemail']))
      file_put_contents('mailtoemail.txt', trim($_POST['mailtoemail']));
?>
<form method="post" action="admin.php">
Send to this email: <input name="mailtoemail" type="text" value="<?php echo file_get_contents('mailtoemail.txt'); ?>"/>
<input type="submit" />
</form>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ilandproAuthor Commented:
Thank you so very much - now everything works!

Being a total novice in this area - I have no idea how to use nor implement phpmailer or swiftmailer.
Im using servage.net as hosting company and couldnt find any of the above mentioned as installed.

Should I open another question with this?
0
Marcus BointonCommented:
Glad it worked.

Given how simple this example is, I wouldn't worry too much about it, but if you want to do more on the email itself, I would definitely head in that direction. I'd suggest you go read the docs and look at the examples, then ask questions when you have specific concerns - very general questions tend to get very general answers.
0
ilandproAuthor Commented:
That's true - thanks for all your help on this one!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.