PHP Mail Form won't allow to send to multiple addresses

Discussion in 'PHP' started by Jennilynn, Dec 3, 2013.

  1. #1
    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: http://jennilynn.net/IMT/satmathenroll.html

    enrollmath.php:

    <?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\">";
    }
    ?>
    Code (markup):

    and the HTML part:

    <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>
    
    
    
    Code (markup):
    Thanks in advance!
     
    Jennilynn, Dec 3, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    The code isn't very good, but I'm on a cellphone and can't be arsed going through it all, just wanna say you should definitely make sure your form sanitizes input a little better. The error might be as simple as not having a space between , and the next email.
     
    PoPSiCLe, Dec 3, 2013 IP
  3. Jennilynn

    Jennilynn Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #3
    I had tried it with and without a space around the comma, which didn't change the outcome I'm not a PHP expert obviously but I had found that code and it worked without issue until I added that second address in.
     
    Jennilynn, Dec 3, 2013 IP
  4. Jennilynn

    Jennilynn Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #4
    tried with a ; between the addresses and no such luck
     
    Jennilynn, Dec 3, 2013 IP
  5. Jennilynn

    Jennilynn Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #5
    this was solved elsewhere - thanks for your time!
     
    Jennilynn, Dec 3, 2013 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Again - providing a solution, even though you find the solution elsewhere, is common practice, simply to help others in the future who might experience the same problems find a solution. If the solution was found to be something else than the PHP script alltogether, for instance the setup of the mail server, or something similar, then say so, so people can check for this if they experience something similar.
     
    PoPSiCLe, Dec 4, 2013 IP