[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

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 :)
0
ilandpro
Asked:
ilandpro
1 Solution
 
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now