[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Request form using a textfield and textarea. phpmail()

Hi.
I have a request page that contains a text field and text area in a form.  After both areas are filled out and the submit button is clicked, whatever is in the textfield and textarea should be submitted in an email to the administrator(s).  I am not sure exactly how many administrators there will end up being, so instead of having the phpmail() function mail directly to one person's email address, I need it to email all users with 'Level_access' of "1".  This means, after the submit button is clicked, it goes through the SQL database and grabs the email address for everyone who is 'Level_access" of "1"...It then emails all of those users.

Since I have to select multiple email addresses from the database, I'm confused as to how to email all of these users at the same time.  Any ideas?  Thanks a lot!

Here is my form
==================
<form name="form1" method="post" action="">
                     
              <p align="left"></p>
                     
              <table width="100%">
                <tr>
                  <td align="center" valign="top">&nbsp;</td>
                  <td><font size="-2" face="Arial, Helvetica, sans-serif">Filename:</font></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td align="center" valign="top"><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font><font color="#000000" size="-2" face="Arial, Helvetica, sans-serif"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"><img src="http://*.*.*.*/dialer/graphics/logo.JPG" width="14" height="14"></font></td>
                  <td> <div align="left">
                      <input type="text" name="textfield">
                    </div></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="25%" rowspan="2" align="center" valign="top"> <div align="center">
                      <table width="75%">
                        <tr> </tr>
                      </table>
                    </div>
                    <div align="left">
                      <p><font size="-2" face="Arial, Helvetica, sans-serif">If
                        you would like to request a temporary <font color="#FF0000">1-day</font>
                        account for another user, please do so here. Remember
                        to include the name of the file along with its extension.</font></p>
                    </div></td>
                  <td><font size="-2" face="Arial, Helvetica, sans-serif">Reason
                    for request:</font></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="61%"><textarea name="textarea"></textarea></td>
                  <td width="14%" valign="top">&nbsp;</td>
                </tr>
                <tr>
                  <td align="center" valign="middle">
<div align="left"><font color="#FF0000" size="-2" face="Arial, Helvetica, sans-serif">***Once
                      submitted, a request email will be sent to the administrator.***</font></div></td>
                  <td><input type="submit" name="Submit" value="Submit"></td>
                  <td>&nbsp;</td>
                </tr>
              </table>
                   </p>
                    </form>
0
dialeradmin
Asked:
dialeradmin
  • 3
  • 2
1 Solution
 
steelseth12Commented:
In the first parameter of the mail() function you can add several email addresses separated by a comma.
Or you can add a CC or BCC to in the headers.

Eg.

mail("email@example.com, email2@example.com , email3@example.com","subject","message","headers");

or

mail("email@example.com","subject","message","Bcc: email2@example.com, email3@example.com , email4@example.com\r\n");
0
 
steelseth12Commented:
Have a look at http://de.php.net/manual/en/function.mail.php for more information.
0
 
dialeradminAuthor Commented:
So, something similar to this could work?  Does this look correct so far?

=============================================================

if(isset($_POST['Submit']))
      {
            if($_POST['textfield']!='' && $_POST['textarea']!='')
                                             {
                                                      $to = 'something@something.com';
                       $headers =       'From: Dialer Secure Server';
                           $subject = 'Temporary user account request';
                       $message = 'There has been a request for a temporary, one day account on the Dialer Secure Server.\n The requested file is: $_POST['textfield']\n Description: $_POST['textarea']\n';
                        
                                                       if(mail($to, $subject, $message, $headers))
                             {
                  header('Location: request_sent.php');
                             }
                             else {
                  header('Location: request_error.php');
                             }
               }
}
0
 
dialeradminAuthor Commented:
Ok...I have this working...

But, now how do I have it email whatever the user entered into both forms on the request page?  Where I want the form information to be printed is where I inserted ['textfield'] and ['textarea'] inside the $message.

============================================

if(isset($_POST['Submit']))
      {
            if($_POST['textfield']!='' && $_POST['textarea']!='')
            {
                  $to = something@something.com';
                $headers =       'From: Dialer Secure Server';
                $subject = 'Temporary user account request';
                $message = "There has been a request for a temporary, one day account on the Dialer Secure Server.\n\n The requested file is: ['textfield']\n\n Description: ['textarea']\n";
                       
                             if(mail($to, $subject, $message, $headers))
                             {
                                          echo("Your mail has been sent!");
                             }
                             else {
                                          echo("There has been an error. Please try again!");
                             }
               }
}
?>
0
 
steelseth12Commented:
Hi dialeradmin
Whaever is submitted through a form is either in the $_POST or $_GET superglobals depending on which method you used to send your form.I seen that you are submitted via post so you will use the $_POST array.
Your code will look something like this.

<?
if(isset($_POST['Submit']))
      {
            if($_POST['textfield']!='' && $_POST['textarea']!='')
            {
                  $to = 'something@something.com';
                $headers = 'From: Dialer Secure Server';
                $subject = 'Temporary user account request';
                $message = "There has been a request for a temporary, one day account on the Dialer Secure Server.\n\n The requested file is: ".$_POST['textfield']."\n\n Description: ".$_POST['textarea']."\n";
                       
                             if(mail($to, $subject, $message, $headers))
                             {
                                          echo("Your mail has been sent!");
                             }
                             else {
                                          echo("There has been an error. Please try again!");
                             }
               }
}
?>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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