Link to home
Start Free TrialLog in
Avatar of Cheryl Lander
Cheryl LanderFlag for United States of America

asked on

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.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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.
Avatar of Cheryl Lander

ASKER

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

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

ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America 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 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.
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.
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

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

Awesome works great.

I will now post a few questions regarding from.
Good.  I should have linked to the string handling pages on PHP.net: http://php.net/manual/en/language.types.string.php