Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Junior Member jennilynn6's Avatar
    Join Date
    Feb 2013
    Posts
    25
    Member #
    35169

    PHP Mail form - wont let me send to multiple addresses

    I have a PHP form that works like a charm when only one email address is used - however when I went to add an extra email address for the form to be sent to, separating them with a comma like was stated when I did a google search for the issue, I now get an error page when submitting. Adding that second email address was the only thing I changed from the version that worked just fine.

    The page is testing here: IMT Bootcamp

    enrollmath.php:

    Code:
    <?php
    
    $EmailFrom = $_POST['Email'];
    $EmailTo = "jenni@jennilynn.net,jennilynn6@gmail.com";
    $Subject = "Someone wants to enroll in SAT Math!";
    $SName = Trim(stripslashes($_POST['SName'])); 
    $PName = Trim(stripslashes($_POST['PName'])); 
    $Tel = Trim(stripslashes($_POST['Tel'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 
    $City = Trim(stripslashes($_POST['City'])); 
    $State = Trim(stripslashes($_POST['State'])); 
    $SATYESNO = Trim(stripslashes($_POST['SATYESNO'])); 
    $Score = Trim(stripslashes($_POST['Score'])); 
    $Colleges = Trim(stripslashes($_POST['Colleges'])); 
    
    
    
    
    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    
    // prepare email body text
    $Body = "";
    $Body .= "Students Name: ";
    $Body .= $SName;
    $Body .= "\n";
    $Body .= "Parent Name: ";
    $Body .= $PName;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "City: ";
    $Body .= $City;
    $Body .= "\n";
    $Body .= "State: ";
    $Body .= $State;
    $Body .= "\n";
    $Body .= "Taken the SAT?: ";
    $Body .= $SATYESNO;
    $Body .= "\n";
    $Body .= "Score: ";
    $Body .= $Score;
    $Body .= "\n";
    $Body .= "3 Top Colleges: ";
    $Body .= $Colleges;
    $Body .= "\n";
    
    
    
    
    
    
    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    
    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>

    and the HTML part:

    Code:
    <form method="post" action="enrollmath.php">				<label for="SName" class="enroll">Student's Name:</label>
    				<input type="text" name="SName" id="SName" /><br />
                    
                    <label for="PName" class="enroll">Parent's Name:</label>
    				<input type="text" name="PName" id="PName" /><br />
    				
    				<label for="Tel" class="enroll">Phone:</label>
    				<input type="text" name="Tel" id="Tel" /><br />
    	
    				<label for="Email" class="enroll">Email:</label>
    				<input type="text" name="Email" id="Email" /><br />
                    
                    <label for="City" class="enroll">City:</label>
    				<input type="text" name="City" id="City" /><br />
                    
                    <label for="State" class="enroll">State:</label>
    				<input type="text" name="State" id="State" /><br />
                    
                    <hr />
                    <br />
                    <label for="SAT" class="enroll_long">Has student taken the SAT before?</label>
    				<select name="SATYESNO" class="checkboxenroll" id="SATYESNO" name="SATYESNO">
                    <option value="Yes">Yes</option>
    				<option value="No">No</option>
    				</select>
                    <br />
                    <br /><br />
                    <div id="contact-area-enroll-bottom">
                    <label for="Score" class="enrollbottom">Most recent math score:</label>
    				<input type="text" name="Score" id="Score" width="15px" /><br />
                    
                    <label for="Colleges" class="enrollcollege">Top 3 universities/colleges<br />student wishes to attend:</label>
    				<input type="text" name="Colleges" id="Colleges" class="colleges" />
    <br /><br />
    				<input type="submit" name="submit" value="Submit" class="submit-button" />
    			</form>
    Thanks in advance!

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    I don't see anything wrong with it ...

    But try this instead:

    $EmailTo = "jenni@jennilynn.net;jennilynn6@gmail.com";

    maybe that comma is doing something to the mail() function?


    EDIT:
    With any website, you should have some properties in your .htaccess file that won't allow a directory to be viewed unless an "index" file exists.

    Otherwise, this happens: http://jennilynn.net/IMT/
    Until you fix it, that link displays all of the files in that directory (not a good thing to do).

    See: http://perishablepress.com/stupid-htaccess-tricks/#sec3
    Last edited by mlseim; Dec 03rd, 2013 at 05:23 PM.


  4. #3
    Junior Member jennilynn6's Avatar
    Join Date
    Feb 2013
    Posts
    25
    Member #
    35169
    Thanks for the htaccess help - working on that now.

    However, the php still isn't working

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Try this ...

    Put the comma back in.
    Then change this line ...

    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    To This:


    $EmailTo = array('jenni@jennilynn.net','jennilynn6@gmail.com' );
    success = mail(implode(',',$EmailTo), $Subject, $Body, "From: <$EmailFrom>");

    So you can use an array of email addresses instead.
    See if that works.

    By the way, with my webhost, I can use commas just fine. It must be a configuration with your webhost. I just tested it on my website and I can send to any number of names separated by commas.
    Last edited by mlseim; Dec 03rd, 2013 at 06:25 PM.


  6. #5
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    This forum's text editor is the worst ever! Sorry I could not edit my last post ... it should be OK now. I had to use a different browser. Ever since they changed this forum software, it has been total crap!


  7. #6
    Junior Member jennilynn6's Avatar
    Join Date
    Feb 2013
    Posts
    25
    Member #
    35169
    If there is another way to code this page without me having to change my HTML Form code (it took while for me to get it the way I wanted it, I'm much more of a designer than a developer) I am all ears. I just needs to send everything from the form to 2 emails, nothing fancy beyond that.

  8. #7
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    You are only changing the PHP send script, not the form.


  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Who is your webhost?


  10. #9
    Junior Member jennilynn6's Avatar
    Join Date
    Feb 2013
    Posts
    25
    Member #
    35169
    My webhost is Namecheap.com

    I tried that new line of code you suggested (on the form here: http://jennilynn.net/IMT/satmathenroll.html), and I get this error when submitting the form: Parse error: syntax error, unexpected '=' in /home/chucl/public_html/IMT/enrollmath.php on line 5

  11. #10
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Something isn't right with the PHP configuration, because commas should be fine.

    So, let's cheat and try this whole script instead ...
    make a safe copy of your original script before overwriting it with my changes ...

    PHP Code:
    <?php

    $EmailFrom 
    $_POST['Email'];
    $EmailTo1 "jenni@jennilynn.net";
    $EmailTo2 "jennilynn6@gmail.com";
    $Subject "Someone wants to enroll in SAT Math!";
    $SName Trim(stripslashes($_POST['SName'])); 
    $PName Trim(stripslashes($_POST['PName'])); 
    $Tel Trim(stripslashes($_POST['Tel'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
    $City Trim(stripslashes($_POST['City'])); 
    $State Trim(stripslashes($_POST['State'])); 
    $SATYESNO Trim(stripslashes($_POST['SATYESNO'])); 
    $Score Trim(stripslashes($_POST['Score'])); 
    $Colleges Trim(stripslashes($_POST['Colleges'])); 




    // validation
    $validationOK=true;
    if (!
    $validationOK) {
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }


    // prepare email body text
    $Body "";
    $Body .= "Students Name: ";
    $Body .= $SName;
    $Body .= "\n";
    $Body .= "Parent Name: ";
    $Body .= $PName;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "City: ";
    $Body .= $City;
    $Body .= "\n";
    $Body .= "State: ";
    $Body .= $State;
    $Body .= "\n";
    $Body .= "Taken the SAT?: ";
    $Body .= $SATYESNO;
    $Body .= "\n";
    $Body .= "Score: ";
    $Body .= $Score;
    $Body .= "\n";
    $Body .= "3 Top Colleges: ";
    $Body .= $Colleges;
    $Body .= "\n";


    // send email
    $success=0
    if(
    mail($EmailTo1$Subject$Body"From: <$EmailFrom>")){
    $success=1;
    }
    if(
    mail($EmailTo2$Subject$Body"From: <$EmailFrom>")){
    $success++;
    }

    // redirect to success page 
    if ($success==2){
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
    }
    else{
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>



Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:05 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com