SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTML5 form using PHP, email not sending

    Hello All,

    I have created the following HTML5 form (some wording changed for security reasons), I am posting to test.php. I go over to XAMPP and launch my Form which in turn goes to PHP code. I receive message 'Thank you, your request has been sent!' but no email is being received. I am not sure what the problem is - my server is setup for SMTP port = 25 and my domain is company name. Any thoughts? Code below...

    HTML Code:
    <head>
    <meta charset="UTF-8">
    <title>Transfer Form</title>
    <link href="css/goods.css" rel="stylesheet" type="text/css">
    
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    
    <script type="text/javascript">
    $(document).ready(function() {
        $('a').click(function() {
            $('#myTable tbody').append('<tr class="child"><td><input type="text" name="stockNumber" class="stocktext"  id="stockNumber" /></td><td><input type="text" name="serialNumber" class="serialtext" id="serialNumber" /></td><td><input type="text" name="description" class="descripttext" id="description"/></td></tr>');
        
    });
    });
    </script>
    
    <script>
      $(function() {
        $( "#datepicker" ).datepicker();
      });
      </script>
    </head>
    
    <body>
    
    <form method="POST" action="test.php"> 
    
    <fieldset>
    <legend class="legend"> Transfer Form</legend>
    
    <p class="currentdate">Current Date: 
    <script type="text/javascript">
    <!--
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()
    document.write(month + "/" + day + "/" + year)
    //-->
    </script></p>
    
    <p>
    <table class="table">
        <tr>
          <td><span class="requiredtable">*</span> <span class="fieldtext">Stock Number</span></td>
          <td><span class="requiredtable">*</span> <span class="fieldtext">Serial Number</span></td>
          <td class="descripttd"><span class="descriptiontxt"> Description</span></td>
        </tr>
      </table>
      
      <table id="myTable">
      <tbody>
        <tr>
          <TD> <input type="text" name="stockNumber" required class="stocktext"  id="stockNumber" tabindex="1" /> </TD>
                
          <TD> <input type="text" name="serialNumber" required class="serialtext" id="serialNumber" tabindex="2" /> </TD>
                
          <TD> <input type="text" name="description" class="descripttext" id="description" tabindex="3" /> </TD>
        </tr>
      </tbody>
    </table> 
        
     <p><span class="required">*
        </span><span class="fieldtext">Requested by:
        </span>
        <input type="text" name="Requested_by" required id="Requested_by" size="50" maxlength="500" tabindex="4">
            
          <span class="requestdate"><span class="required">*</span> Requested Date:
    <input type="text" name="requestedDate" required id="datepicker" value="Click to Select Date" tabindex="5"></span>
      </p>
        
      <p><span class="required">*</span>
      <span class="fieldtext">Customer Info:</span>
            <input type="text" name="Cust Info" required id="Cust_Info" size="50" maxlength="500" tabindex="6">
      </p>
    
     <label for="RequestingBranch"> 
         <span class="required">*</span>
         <span class="fieldtext"> Requesting Branch:</span>
        </label>
        
    <select class="select" name="R_branch" id="R_branch">
    <option value="">Select One:
    <option value="R_boston">Boston
    <option value="R_Buffalo">Buffalo
    <option value="R_Cinncinatti">Cinncinatti
    <option value="R_columbia">Columbia
    <option value="R_Dallas">Dallas
    <option value="R_Fairfax">Fairfax
    <option value="R_Kansas City">Kansas City
    <option value="R_Los Angeles">Los Angeles
    <option value="R_Orlando">Orlando
    <option value="R_Raleigh">Raleigh
    <option value="R_Toledo">Toledo
    <option value="R_Topeka">Topeka
    </select>
     
        <label for="ShippingBranch">
         <span class="required">*</span>
         <span class="fieldtext"> Shipping Branch:</span>
        </label>
      
       <select class="select" name="S_branch" id="S_branch">
    <option value="">Select One:
    <option value="S_boston">Boston
    <option value="S_Buffalo">Buffalo
    <option value="S_Cinncinatti">Cinncinatti
    <option value="S_columbia">Columbia
    <option value="S_Dallas">Dallas
    <option value="S_Fairfax">Fairfax
    <option value="S_Kansas City">Kansas City
    <option value="S_Los Angeles">Los Angeles
    <option value="S_Orlando">Orlando
    <option value="S_Raleigh">Raleigh
    <option value="S_Toledo">Toledo
    <option value="S_Topeka">Topeka
      </select>
        <br> <br>
     <input type="submit"> 
          
        <input name="resetbutton" type="reset" id="resetbutton" value="Clear"></p>
        
      </fieldset>
    </form>
    
    </body>
    PHP Code:
     <?php 
    sleep
    (2);

    //Sanitize incoming data and store in variable

    $stockNumber =  trim(stripslashes(htmlspecialchars ($_POST['stockNumber'])));        
    $serialNumber =  trim(stripslashes(htmlspecialchars ($_POST['serialNumber'])));    
    $description =  trim(stripslashes(htmlspecialchars ($_POST['description'])));    
    $requestedBy trim(stripslashes(htmlspecialchars ($_POST['requestedBy'])));
    $requestedDate =  trim(stripslashes(htmlspecialchars ($_POST['requestedDate'])));    
    $customerInfo =  trim(stripslashes(htmlspecialchars ($_POST['customerInfo'])));    
        
    // Array for the R_emails option from form
    $R_emails = array(
        
    'R_boston' => 'boston@test.com'
        
    'R_buffalo' => 'buffalo@emailhere.com',
        
    'R_cinncinatti' => 'cinncinatti@email.com'
        
    'R_columbia' => 'columbia@test.com',
        
    'R_dallas' => 'dallas@emailhere.com',  
        
    'R_fairfax' => 'fairfax@emailhere.com'
        
    'R_kansas' => 'kansas@email.com'
        
    'R_la' => 'la@emailhere.com',
        
    'R_orlando' => 'orlando@email.com'
        
    'R_raleigh' => 'raleigh@emailhere.com',
        
    'R_toledo' => 'toledo@emailhere.com',
        
    'R_topeka' => 'topeka@emailhere.com'
    );

    // get receiving email and turn in the the R_email variable
    $R_email $R_email$_POST['R_branch'] ];    

    // Array for the S_emails option from form
    $S_emails = array(
        
    'S_boston' => 'boston@test.com'
        
    'S_buffalo' => 'buffalo@emailhere.com',
        
    'S_cinncinatti' => 'cinncinatti@email.com'
        
    'S_columbia' => 'columbia@test.com',
        
    'S_dallas' => 'dallas@emailhere.com',  
        
    'S_fairfax' => 'fairfax@emailhere.com'
        
    'S_kansas' => 'kansas@email.com'
        
    'S_la' => 'la@emailhere.com',
        
    'S_orlando' => 'orlando@email.com'
        
    'S_raleigh' => 'raleigh@emailhere.com',
        
    'S_toledo' => 'toledo@emailhere.com',
        
    'S_topeka' => 'topeka@emailhere.com'
            
    );

    // get receiving email and turn in the the S_email variable
    $S_email $S_emails$_POST['S_branch'] ];    

    //Prepare information from form to be sent 
    $to 'sparkymom78@gmail.com';
    $from 'sharepoint@company.com';
    $subject 'Online Order Request';
    $headers 'MIME-VERSION: 1.0' '\n';
    $headers .= 'From: $from' '\n';
    "CC: testing123@company.com";
    $body 'Stock Number: ' .$stockNumber PHP_EOL;
    $body .= 'Serial Number: ' .$serialNumber PHP_EOL;
    $body .= 'Description: ' .$description PHP_EOL;
    $body .= 'Requested By: ' .$requestedBy PHP_EOL;
    $body .= 'Requested Date: ' .$requestedDate PHP_EOL;
    $body .= 'Customer Info: ' .$customerInfo PHP_EOL;

    // Form data was successful so we will now send admin email and return message to the user
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers '-f user123@company.com' ); 
    echo 
    'Thank you, your request has been sent!';    

    ?>
    Thanks in advance,
    SparkyMom

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi SparkyMom,

    I've got a recent copy of XAMMP on my machine, and it seems that by default it's setup to save emails to disk instead of sending them. Check for a folder, inside your XAMPP folder, called mailoutput.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you get them out of Apache/Output email to recipient?

    Quote Originally Posted by fretburner View Post
    Hi SparkyMom,

    Check for a folder, inside your XAMPP folder, called mailoutput.
    Yeah, I just found them there. Now the question is how do I get them out of there? And have them actually email to correct recipients?

    Thanks,
    Sparkymom

  4. #4
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Open up php/php.ini and comment out this line:
    Code:
    sendmail_path = "\xampp\mailtodisk\mailtodisk.exe"
    and uncomment this one:
    Code:
    sendmail_path = "\"\xampp\sendmail\sendmail.exe\" -t"
    Then open up sendmail/sendmail.ini and fill in the details for an email account that you can use to send the email.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    Open up php/php.ini and comment out this line:
    Code:
    sendmail_path = "\xampp\mailtodisk\mailtodisk.exe"
    and uncomment this one:
    Code:
    sendmail_path = "\"\xampp\sendmail\sendmail.exe\" -t"
    Then open up sendmail/sendmail.ini and fill in the details for an email account that you can use to send the email.
    I have done what is suggested here and my emails are still getting hung up in the Apache/mailoutput folder.

    Enclosed are my php.ini and sendmail.ini - What do I need to do to get the emails to actually send?


    php.ini

    [mail function]
    ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
    SMTP = ip address for exchange server here
    smtp_port = 25

    ; For Win32 only.
    ; http://php.net/sendmail-from
    sendmail_from = sharepoint@companyname.com

    ; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
    ; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.

    ; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

    ; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
    ;sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"

    sendmail.ini

    [sendmail]

    ; you must change mail.mydomain.com to your smtp server,
    ; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
    ; emails delivered via IIS's pickup directory cause sendmail to
    ; run quicker, but you won't get error messages back to the calling
    ; application.

    smtp_server=ip address for exchange server here

    ; smtp port (normally 25)

    smtp_port=25

  6. #6
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    If your emails are still ending up in the mailoutput folder, it sounds like you'll need to restart XAMPP for the changes in php.ini to take effect.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    restart of Xampp and server reboot did not help

    Quote Originally Posted by fretburner View Post
    If your emails are still ending up in the mailoutput folder, it sounds like you'll need to restart XAMPP for the changes in php.ini to take effect.
    I restarted Xampp and even rebooted the server - emails still stuck.

    Is there something else I need to do on the server?

  8. #8
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Are they still being saved to mailoutput? Can you check to see if you have another php.ini file in your \xampp\apache\bin folder

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, they are still going to mail output and no I do not have another php.ini file in my \xampp\apache\bin folder

  10. #10
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    In your php.ini, try commenting out the following lines:
    Code:
    [mail function]
    ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
    ; SMTP = ip address for exchange server here
    ; smtp_port = 25
    and check if you need to add a username and password for your exchange server in sendmail.ini:
    Code:
    auth_username=
    auth_password=

  11. #11
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I attempted the first part with the code and it didn't work. Waiting on Admin for second part.

    I have another question, I have been trying to figure out how to validate my code. Do I put the php validation code within the HTML form? Or at the top of the send.php code? I am so confused on what to do and there is not anything real clear out there.

    Then the next question is how to start it.

    Thanks

  12. #12
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    It's probably easiest to put the validation at the top of the form page. If the validation is successful, the form gets emailed and then you can display a message or redirect to another page. If the validation fails, the form is redisplayed with the values pre-filled and the error messages displayed to the user so they can correct the problem.

    Here's a basic example, showing how you could do that for a field called email.
    PHP Code:
    <?php
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        
        
    $validForm TRUE;
        
    $errors = array();
        
        
    $email filter_input(INPUT_POST'email'FILTER_SANITIZE_EMAIL);

        if (
    FALSE == filter_var($emailFILTER_VALIDATE_EMAIL)) {
            
    $validForm FALSE;
            
    $errors['email'] = "Email address is not valid";
        }

        if (
    $validForm) {
            
    // Send email
            // Redirect to thank you page
        
    }
    }
    ?>

    <form method="post">
        <input name="email" value="<?php echo $email ?>">
        <?php if (isset($errors['email'])): ?><p class="error"><?php echo $errors['email'?></p><?php endif; ?>
    </form>

  13. #13
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    The standard mail function in php really sucks. In that it is quite limited in its capabilities and error handling. I would recommend using a library like SwiftMailer that provides an stmp transport. The stmp transport provides increasingly portable and predictable funcionality across different environments. Also, it provides very good feedback for errors and such.
    The only code I hate more than my own is everyone else's.

  14. #14
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since I couldn't get email to send through PHP via SMTP by making changes to my php.ini and sendmail.ini, I decided to setup PHPMailer.

    After the install, I was able to successfully receive the test mail from PHPMailer BUT I'm not sure what all I need to do to get the email to send properly via my send.php code.

    ** I shouldn't have to have the form setup in the PHPMailer folder to work properly - right?

    My error messages:

    Warning: require(class.phpmailer.php): failed to open stream: No such file or directory in C:\xampp\htdocs\transferform\send.php on line 3

    Fatal error: require(): Failed opening required 'class.phpmailer.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\transferform\send.php on line 3

    Not sure what PEAR has to do with PHPMailer. I have PHPMailer installed in htdocs\PHPMailer

    PHP Code:
    //Top of my send.php code:

    <?php 
    sleep
    (2)/
    require(
    "class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     "ip address"// SMTP server

    //bottom of code:
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers'-f [email]user123@company.com[/email]' ); 
    echo 
    'Thank you, your request has been sent!';    
        
    ?>
    ** I tried to add the following statement
    require("php\PEAR\class.phpmailer.php");

    ** As a test, I copied class.phpmailer.php into my folder that contains my html form and send.php files and I didn't receive any error messages but I also didn't get the email.
    ARRRGGGHHH...


    Thanks

  15. #15
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    If your form is in the file C:\xampp\htdocs\transferform\send.php and you've got PHPMailer in C:\xampp\htdocs\PHPMailer, try changing the require call at the top of you form like this:
    PHP Code:
    require("../PHPMailer/class.phpmailer.php"); 
    Edit: What this does it tell require "go up one level from my current directory (transferform) and into the PHPMailer directory, and include the file class.phpmailer.php from there".
    Last edited by fretburner; Jul 3, 2013 at 07:30. Reason: Add an explanatory note

  16. #16
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    If your form is in the file C:\xampp\htdocs\transferform\send.php and you've got PHPMailer in C:\xampp\htdocs\PHPMailer, try changing the require call at the top of you form like this:
    PHP Code:
    require("../PHPMailer/class.phpmailer.php"); 
    Edit: What this does it tell require "go up one level from my current directory (transferform) and into the PHPMailer directory, and include the file class.phpmailer.php from there".
    I have tried the following and keep getting errors:

    require("xampp/htdocs/PHPMailer/class.phpmailer.php");
    require("/PHPMailer/class.phpmailer.php");
    require("../PHPMailer/class.phpmailer.php");

    Do I need to make edits to the class.phpmailer?

    OR is this code supposed to go into my html form at the beginning?

    <?php
    sleep(2)/
    require("../class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host = "ip address"; // SMTP server

    ?>

  17. #17
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by sparkymom7 View Post
    After the install, I was able to successfully receive the test mail from PHPMailer BUT I'm not sure what all I need to do to get the email to send properly via my send.php code.
    What did you do to receive the test email? Is it a script that's included with PHPMailer? If so, what folder did you run it from?

  18. #18
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have this working without any errors

    require("../PHPMailer/class.phpmailer.php");

    but I'm still not receiving emails, they are going into the Apache/mailoutput folder

  19. #19
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I created a test file in the PHPMailer folder.

    PHP Code:
    ?php

    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     "ipaddress"// SMTP server

    $mail->From     "sharepoint@company.com";
    $mail->FromName "user123";
    $mail->AddAddress("user123@company.com");

    $mail->Subject  "First PHPMailer Message";
    $mail->Body     "Hi! \n\n This is my first e-mail sent through PHPMailer.";
    $mail->WordWrap 50;

    if(!
    $mail->Send()) {
      echo 
    'Message was not sent.';
      echo 
    'Mailer error: ' $mail->ErrorInfo;
    } else {
      echo 
    'Message has been sent.';
    }
    ?> 

  20. #20
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by sparkymom7 View Post
    but I'm still not receiving emails, they are going into the Apache/mailoutput folder
    Can you re-post the code of your send.php file please? I expect you're still getting mails in the mailoutput folder due to the mail() function still being called at the bottom of the file.

    Edit: Nevermind, I've just seen your latest message. In your send.php file, change this part:
    PHP Code:
    //Prepare information from form to be sent  
    $to 'sparkymom78@gmail.com'
    $from 'sharepoint@company.com'
    $subject 'Online Order Request'
    $headers 'MIME-VERSION: 1.0' '\n'
    $headers .= 'From: $from' '\n'
    "CC: testing123@company.com"


    // Form data was successful so we will now send admin email and return message to the user 
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers '-f user123@company.com' );  
    echo 
    'Thank you, your request has been sent!'
    for this:

    PHP Code:
    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     "ipaddress"// SMTP server

    $mail->From     "sharepoint@company.com";
    $mail->FromName "user123";
    $mail->AddAddress("user123@company.com");

    $mail->Subject  "Online Order Request";
    $mail->Body     $body;
    $mail->WordWrap 50;

    if(!
    $mail->Send()) {
      echo 
    'Message was not sent.';
      echo 
    'Mailer error: ' $mail->ErrorInfo;
    } else {
      echo 
    'Thank you, your request has been sent!';

    Note: don't forget to make sure you've the require("../PHPMailer/class.phpmailer.php"); line at the top of your script.
    Last edited by fretburner; Jul 3, 2013 at 09:07. Reason: Tidied up code

  21. #21
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here it is, notice I changed my require path - I'm not getting any errors and email is sitting in Apache/mailoutput folder.

    PHP Code:
      <?php 
    sleep
    (2)/
    require(
    'C:\xampp\htdocs\PHPMailer\class.phpmailer.php');

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     "ipaddress"// SMTP server

    //Sanitize incoming data and store in variable

    $stockNumber =  trim(stripslashes(htmlspecialchars ($_POST['stockNumber'])));        
    $serialNumber =  trim(stripslashes(htmlspecialchars ($_POST['serialNumber'])));    
    $description =  trim(stripslashes(htmlspecialchars ($_POST['description'])));    
    $requestedBy trim(stripslashes(htmlspecialchars ($_POST['requestedBy'])));
    $requestedDate =  trim(stripslashes(htmlspecialchars ($_POST['requestedDate'])));    
    $customerInfo =  trim(stripslashes(htmlspecialchars ($_POST['customerInfo'])));    
    $R_branch trim(stripslashes(htmlspecialchars ($_POST['R_branch'])));
    $S_branch trim(stripslashes(htmlspecialchars ($_POST['S_branch'])));

    $R_branch ucfirst(substr($R_branch2));
    $S_branch ucfirst(substr($S_branch2));
        
    // Array for the R_emails option from form
    $R_emails = array(
        
    'R_boston' => 'boston@test.com'
        
    'R_buffalo' => 'buffalo@emailhere.com',
        
    'R_cinncinatti' => 'cinncinatti@email.com'
        
    'R_columbia' => 'columbia@test.com',
        
    'R_dallas' => 'dallas@emailhere.com',  
        
    'R_fairfax' => 'fairfax@emailhere.com'
        
    'R_kansas' => 'kansas@email.com'
        
    'R_la' => 'la@emailhere.com',
        
    'R_orlando' => 'orlando@email.com'
        
    'R_raleigh' => 'raleigh@emailhere.com',
        
    'R_toledo' => 'toledo@emailhere.com',
        
    'R_topeka' => 'topeka@emailhere.com'
    );

    // get receiving email and turn in the the R_email variable
    $R_email $R_email$_POST['R_branch'] ];    

    // Array for the S_emails option from form
    $S_emails = array(
        
    'S_boston' => 'boston@test.com'
        
    'S_buffalo' => 'buffalo@emailhere.com',
        
    'S_cinncinatti' => 'cinncinatti@email.com'
        
    'S_columbia' => 'columbia@test.com',
        
    'S_dallas' => 'dallas@emailhere.com',  
        
    'S_fairfax' => 'fairfax@emailhere.com'
        
    'S_kansas' => 'kansas@email.com'
        
    'S_la' => 'la@emailhere.com',
        
    'S_orlando' => 'orlando@email.com'
        
    'S_raleigh' => 'raleigh@emailhere.com',
        
    'S_toledo' => 'toledo@emailhere.com',
        
    'S_topeka' => 'topeka@emailhere.com'
            
    );

    // get receiving email and turn in the the S_email variable
    $S_email $S_emails$_POST['S_branch'] ];    

    //Prepare information from form to be sent 
    $to 'sparkymom78@gmail.com';
    $from 'sharepoint@company.com';
    $subject 'Online Order Request';
    $headers 'MIME-VERSION: 1.0' '\n';
    $headers .= 'From: $from' '\n';
    "CC: testing123@company.com";
    $body 'Stock Number: ' .$stockNumber PHP_EOL;
    $body .= 'Serial Number: ' .$serialNumber PHP_EOL;
    $body .= 'Description: ' .$description PHP_EOL;
    $body .= 'Requested By: ' .$requestedBy PHP_EOL;
    $body .= 'Requested Date: ' .$requestedDate PHP_EOL;
    $body .= 'Customer Info: ' .$customerInfo PHP_EOL;

    // Form data was successful so we will now send admin email and return message to the user
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers '-f user123@company.com' ); 
    echo 
    'Thank you, your request has been sent!';    

    ?>

  22. #22
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    I've put the modified code for the whole file here: https://gist.github.com/LordZicon/68240442483f02877732

  23. #23
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so VERY, VERY much Fretburner.

    I'm finally receiving emails, I even have CC working but how do I get it to go to my 2 arrays? $R_mail and $S_mail.


    I have tried a couple of ways but they don't seem to work I even googled it.

    $mail->AddAddress($R_email, $S_email);
    $mail->AddCC("user123@company.com");

  24. #24
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by sparkymom7 View Post
    Thank you so VERY, VERY much Fretburner.
    You're welcome, I'm glad it's working

    Quote Originally Posted by sparkymom7 View Post
    I'm finally receiving emails, I even have CC working but how do I get it to go to my 2 arrays? $R_mail and $S_mail.

    I have tried a couple of ways but they don't seem to work I even googled it.

    $mail->AddAddress($R_email, $S_email);
    $mail->AddCC("user123@company.com");
    I've taken a quick look at the PHPMailer docs, and it looks like the second parameter for AddAddress is a 'friendly' name, so to add two recipients you'd have to call it twice:
    PHP Code:
    $mail->AddAddress($R_email'Branch One'); // With a friendly name (optional)
    $mail->AddAddress($S_email); // Without name 

  25. #25
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    You're welcome, I'm glad it's working
    Thank you again Fretburner
    Fretburner helped me a lot, this coming from a beginner PHP developer.

    I'm posting the final output to share with everyone because I could not find a good inclusive set of code anywhere to help me out. This has been a huge project with an HTML form, posting to send.php (which is attached below) using PHPMailer.


    PHP Code:
     <?php 
    sleep
    (2);
    require(
    '../PHPMailer/class.phpmailer.php');

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     "ip address"// SMTP server

    //Sanitize incoming data and store in variable
     
    $stockNumber =  trim(stripslashes(htmlspecialchars ($_POST['stockNumber'])));        
    $serialNumber =  trim(stripslashes(htmlspecialchars ($_POST['serialNumber'])));    
    $description =  trim(stripslashes(htmlspecialchars ($_POST['description'])));    
    $requestedBy trim(stripslashes(htmlspecialchars ($_POST['requestedBy'])));
    $requestedDate =  trim(stripslashes(htmlspecialchars ($_POST['requestedDate'])));    
    $customerInfo =  trim(stripslashes(htmlspecialchars ($_POST['customerInfo'])));    
    $R_branch trim(stripslashes(htmlspecialchars ($_POST['R_branch'])));
    $S_branch trim(stripslashes(htmlspecialchars ($_POST['S_branch'])));

    $R_branch ucfirst(substr($R_branch2));  // removes the R_ and capitalizes first letter of branch in final output to email
    $S_branch ucfirst(substr($S_branch2));  // removes the S_ and capitalizes first letter of branch in final output to email
        
    // Array for the R_emails option from form
    $R_emails = array(
        
    'R_boston' => 'boston@test.com'
        
    'R_buffalo' => 'buffalo@emailhere.com',
        
    'R_cinncinatti' => 'cinncinatti@email.com'
        
    'R_columbia' => 'columbia@test.com',
        
    'R_dallas' => 'dallas@emailhere.com',  
        
    'R_fairfax' => 'fairfax@emailhere.com'
        
    'R_kansas' => 'kansas@email.com'
        
    'R_la' => 'la@emailhere.com',
        
    'R_orlando' => 'orlando@email.com'
        
    'R_raleigh' => 'raleigh@emailhere.com',
        
    'R_toledo' => 'toledo@emailhere.com',
        
    'R_topeka' => 'topeka@emailhere.com'
    );

    // get receiving email and turn in the the R_email variable
    $R_email $R_email$_POST['R_branch'] ];    

    // Array for the S_emails option from form
    $S_emails = array(
        
    'S_boston' => 'boston@test.com'
        
    'S_buffalo' => 'buffalo@emailhere.com',
        
    'S_cinncinatti' => 'cinncinatti@email.com'
        
    'S_columbia' => 'columbia@test.com',
        
    'S_dallas' => 'dallas@emailhere.com',  
        
    'S_fairfax' => 'fairfax@emailhere.com'
        
    'S_kansas' => 'kansas@email.com'
        
    'S_la' => 'la@emailhere.com',
        
    'S_orlando' => 'orlando@email.com'
        
    'S_raleigh' => 'raleigh@emailhere.com',
        
    'S_toledo' => 'toledo@emailhere.com',
        
    'S_topeka' => 'topeka@emailhere.com',       
    );

    // get receiving email and turn in the the S_email variable
    $S_email $S_email$_POST['S_branch'] ];    
     
    //Prepare information from form to be sent 
    $body 'Stock Number: ' .$stockNumber PHP_EOL;
    $body .= 'Serial Number: ' .$serialNumber PHP_EOL;
    $body .= 'Description: ' .$description PHP_EOL;
    $body .= 'Requested By: ' .$requestedBy PHP_EOL;
    $body .= 'Requested Date: ' .$requestedDate PHP_EOL;
    $body .= 'Customer Info: ' .$customerInfo PHP_EOL;
    $body .= 'Requesting Branch: ' .$R_branch PHP_EOL;
    $body .= 'Shipping Branch: ' .$S_branch PHP_EOL;
     
    // Form data was successful so we will now send admin email and return message to the user
    $mail = new PHPMailer();
     
    $mail->IsSMTP();
    $mail->Host     "ip address"

    $mail->From     "sharepoint@company.com";
    $mail->FromName "Excited";
    $mail->AddAddress($R_email'R_branch');
    $mail->AddAddress($S_email'S_branch');
    $mail->AddCC("user345@company.com");
     
    $mail->Subject  "Order Request Form";
    $mail->Body     $body;
    $mail->WordWrap 50;
     
    if(!
    $mail->Send()) {
      echo 
    'Message was not sent.';
      echo 
    'Mailer error: ' $mail->ErrorInfo;
    } else {
      echo 
    'Thank you, your request has been sent!';
    }
        
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •