two forms on one page

Hi all,

Screenshot here will explain this.
http://prntscr.com/6uabsd

We have one php page, with one form on it.

The results are currently emailed to one email address.

We now require parts of the form to be emailed to two different email addresses.

We need results on "info to email address 1" to be emailed to info@mydomain.com.au

We need results on "info to email address 2" to be emailed to info@mydomain2.com.au

ive also included values in this screenshot.
http://prntscr.com/6uaco1

Any help would be appreciated.
Cheryl LanderAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
I made some changes as well as adding code to the PHP page.  The indexes in the $_POST variables must exactly match the names in the form <input>s.

Form page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Untitled</title>
</head>
<body>
     <form action="referral-request.php" method="post">
               <h2 style="color:#FF0000; font-size: 19px;">info to email address 1</h2>
               <p>
                 <span class="formft fltlft"><label>From Address:</label></span>
                 <span class="formrt fltlft"><input name="From_Address" type="text" class="txtfld"/></span>
               </p>
               
               <p>
                 <span class="formft fltlft"><label>Client Email Address:</label></span>
                 <span class="formrt fltlft"><input type="text" name="client_email_address" class="txtfld"/></span>
               </p>
               
               <p>
                 <span class="formft fltlft"><label>Email Message:</label></span>
                 <span class="formrt fltlft">
                 <textarea cols="45" rows="9" style="width:650px; height:135px; border:1px solid #d7d7d7; padding:0 10px; line-height:35px;color:#515151; font-family:Arial;" name="email_message_one"></textarea></span>
               </p>
               
               <br><br><br>
               
               <h2 style="color:#FF0000; font-size: 19px;">info to email address 2</h2>
               <p>
                 <span class="formft fltlft"><label>First Name:</label></span>
                 <span class="formrt fltlft"><input type="text" name="first_name" class="txtfld"/></span>
               </p>
               
               <p>
                 <span class="formft fltlft"><label>Last Name:</label></span>
                 <span class="formrt fltlft"><input type="text" name="last_name" class="txtfld"/></span>
               </p>               
               <p>
                 <span class="formft fltlft"><label>Company Name:</label></span>
                 <span class="formrt fltlft"><input type="text" name="company_name" class="txtfld"/></span>
               </p>
               
               <input type="submit" value="Submit" class="submitbtn" />
            </form>
</body>
</html>

Open in new window


PHP page  Where I process the input variables first to eliminate 'missing index' errors.
<?php
// process POST variables first
if (!isset($_POST['From_Address']))  $From_Address = ''; else $From_Address = $_POST['From_Address'];
if (!isset($_POST['client_email_address']))  $client_email_address = ''; else $client_email_address = $_POST['client_email_address'];
if (!isset($_POST['email_message_one']))  $email_message_one = ''; else $email_message_one = $_POST['email_message_one'];
if (!isset($_POST['first_name']))  $first_name = ''; else $first_name = $_POST['first_name'];
if (!isset($_POST['last_name']))  $last_name = ''; else $last_name = $_POST['last_name'];
if (!isset($_POST['company_name']))  $company_name = ''; else $company_name = $_POST['company_name'];

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// subject
$subject = 'Subject Name';


$message1 = "
From Address: $From_Address \r\n
Client Email Address: $client_email_address \r\n
Email Message: $email_message_one \r\n 
";

$message2 = "
First Name: $first_name \r\n
Last Name: $last_name \r\n
Company Name: $company_name 
";

// Additional headers
//$headers .= 'To: Company Name <email@mydomain.com.au>' . "\r\n";

$to1 = "you@yours.com";
// Mail it to first recipient
mail($to1, $subject, $message1, $headers);

$to2 = "them@theirs.com";
// Mail it to second recipient
mail($to2, $subject, $message2, $headers);
?>

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
It's not difficult.  But since you posted that as an image (on another site no less), we can't copy and paste it and edit it to show you how to do it.  If you would paste your PHP in a code window here, I would be happy to show you how to do it.
0
 
Cheryl LanderAuthor Commented:
Form code

     <form action="referral-request.php" method="post">
               <h2 style="color:#FF0000; font-size: 19px;">info to email address 1</h2>
               <p>
                 <span class="formft fltlft"><label>From Address:</label></span>
                 <span class="formrt fltlft"><input name="first_name" type="text" class="txtfld"/></span>
               </p>
               
                 <p>
                 <span class="formft fltlft"><label>Client Email Address:</label></span>
                 <span class="formrt fltlft"><input type="text" name="client_email_address" class="txtfld"/></span>
               </p>
               
               <p>
                 <span class="formft fltlft"><label>Email Message:</label></span>
                 <span class="formrt fltlft">
                 <textarea cols="45" rows="9" style="width:650px; height:135px; border:1px solid #d7d7d7; padding:0 10px; line-height:35px;color:#515151; font-family:Arial;" name="email_message_one"></textarea></span>
               </p>
               
               <br>
<br>
<br>

               
               <h2 style="color:#FF0000; font-size: 19px;">info to email address 2</h2>
               <p>
                 <span class="formft fltlft"><label>First Name:</label></span>
                 <span class="formrt fltlft"><input type="text" name="first_name" class="txtfld"/></span>
               </p>
               
                              <p>
                 <span class="formft fltlft"><label>Last Name:</label></span>
                 <span class="formrt fltlft"><input type="text" name="last_name" class="txtfld"/></span>
               </p>
               
                                             <p>
                 <span class="formft fltlft"><label>Company Name:</label></span>
                 <span class="formrt fltlft"><input type="text" name="company_name" class="txtfld"/></span>
               </p>
               
   
               
                   
               
               <input type="submit" value="Submit" class="submitbtn" />
            </form>

Open in new window

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Cheryl LanderAuthor Commented:
Processing code

<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// subject
$subject = 'Subject Name';


$message1 = "
From Address: " . $_POST['from address']." <br />
Client Email Address: " . $_POST['client_email_address']." <br />
Email Message: " . $_POST['email_message_one']." <br />

";

$message2 = "
First Name: " . $_POST['first_name']." <br />
Last Name: " . $_POST['last_name']." <br />
Company Name: " . $_POST['company_name']." <br />

";


// Additional headers
$headers .= 'To: Company Name <email@mydomain.com.au>' . "\r\n";


// Mail it
mail($to, $subject, $message, $headers);
?>

Open in new window

0
 
Cheryl LanderAuthor Commented:
Thank so much for this.

We have added all fields and works great.

But a couple of issues and I'm happy to open another question if easier?

From_Address is meant to be the actual email address the email is from.

So the new email client (first part of the form) is meant to be sent from $From_Address
At the moment it comes from $From_Address@mydomainname where the site is hosted.

And the second form is meant to be from another email address.

I've also added another subject field and for some reason it comes through as $client_subject

We have verified all values are ok.
0
 
Dave BaldwinFixer of ProblemsCommented:
From_Address is meant to be the actual email address the email is from.
While you can put that in the $headers, in an important sense that will never happen.  The actual account that it is sent from on the server will be an account on the server.  That is for traceability.  But if you put it in the $headers, it should show that way when it is received.

For different subject lines, you would need different variables like $subject1 and $subject2 for the two different mail() lines just like I did with $to1 and $to2.
0
 
Cheryl LanderAuthor Commented:
For the subject, this is what we ahve done.

But comes up as $client_subject

Subject Form Field
<input name="client_subject" type="text" class="txtfld"/>

Open in new window


Processing Code
if (!isset($_POST['client_subject']))  $client_subject = ''; else $client_subject = $_POST['client_subject'];

$subject = '$client_subject';

// Mail it to first recipient
mail($to1, $subject, $message1, $headers);

Open in new window

<input name="client_subject" type="text" class="txtfld"/>

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
It needs to be double quotes to allow variable substitution.
$subject = "$client_subject";

Open in new window

But if that's all there is, you can use it directly.  There is nothing sacred about the variable names.
mail($to1, $client_subject, $message1, $headers);

Open in new window

0
 
Cheryl LanderAuthor Commented:
Awesome works great.

I will now post a few questions regarding from.
0
 
Dave BaldwinFixer of ProblemsCommented:
Good.  I should have linked to the string handling pages on PHP.net: http://php.net/manual/en/language.types.string.php
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.