Link to home
Start Free TrialLog in
Avatar of ilandpro
ilandpro

asked on

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 :)
Avatar of wildzero
wildzero

Hi there,

Post the code of what you've done so far :-)
Avatar of b0lsc0tt
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
Avatar of ilandpro

ASKER

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

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']));
?>
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 :)
<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']));
?>
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,
ASKER CERTIFIED SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
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.
That's true - thanks for all your help on this one!