www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] 2 PHP Warnings when hitting submit button

  1. #1
    Join Date
    Jun 2013
    Posts
    36

    resolved [RESOLVED] 2 PHP Warnings when hitting submit button

    Hello All,

    I'm attempting submit an HTML form using PHP and I'm getting these 2 errors - not sure what is wrong.

    Warning: implode() expects at most 2 parameters, 6 given in C:\xampp\htdocs\transferform\send.php on line 67

    Warning: mail() expects at least 3 parameters, 1 given in C:\xampp\htdocs\transferform\send.php on line 67
    Thank you, your request has been sent!

    My 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.com',
    'R_columbia' => 'columbia@test.com',
    'R_raleigh' => 'raleigh@emailhere.com',
    'R_orlando' => 'test@email.com',
    'R_topeko' => 'columbia@emailhere.com',
    'R_toledo' => 'raleigh@emailhere.com',
    'R_cinncinatti' => 'test@email.com',
    'R_dallas' => 'columbia@emailhere.com',
    'R_buffalo' => 'raleigh@emailhere.com',
    'R_kansas' => 'test@email.com',
    'R_fairfax' => 'columbia@emailhere.com',
    'R_la' => 'raleigh@emailhere.com',
    );

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

    // Array for the S_emails option from form
    $S_emails = array(
    'S_boston' => 'boston@test.com',
    'S_columbia' => 'columbia@test.com',
    'S_raleigh' => 'raleigh@emailhere.com',
    'S_orlando' => 'test@email.com',
    'S_topeko' => 'columbia@emailhere.com',
    'S_toledo' => 'raleigh@emailhere.com',
    'S_cinncinatti' => 'test@email.com',
    'S_dallas' => 'columbia@emailhere.com',
    'S_buffalo' => 'raleigh@emailhere.com',
    'S_kansas' => 'test@email.com',
    'S_fairfax' => 'columbia@emailhere.com',
    'S_la' => 'raleigh@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 = 'user@example.com';
    $from = 'use2r@example.com';
    $headers = 'MIME-VERSION: 1.0' . '\n';
    $headers .= 'From: $from' . '\n';
    $subject = 'Online Order Request';
    $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 = mail( implode(',', array( $R_email, $S_email ), $subject, $body, $headers , '-f user@example.com') );
    echo 'Thank you, your request has been sent!';

    ?>

  2. #2
    Join Date
    Jun 2013
    Posts
    1
    $success = mail( implode(',', array( $R_email, $S_email )), $subject, $body, $headers , '-f user@example.com');

  3. #3
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    9
    The problem is here:

    PHP Code:
    $success mailimplode(',', array( $R_email$S_email ), $subject$body$headers '-f user@example.com') ); 
    You should replace it with this:
    PHP Code:
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers '-f user@example.com' ); 
    Note the fact that I've closed the implode bracket after the array bracket. This should do it just fine.

  4. #4
    Join Date
    Jun 2013
    Posts
    36

    Error msg gone but not receiving email

    Quote Originally Posted by DoubleBit View Post
    The problem is here:

    PHP Code:
    $success mailimplode(',', array( $R_email$S_email ), $subject$body$headers '-f user@example.com') ); 
    You should replace it with this:
    PHP Code:
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers '-f user@example.com' ); 
    Note the fact that I've closed the implode bracket after the array bracket. This should do it just fine.
    My error message is gone, I received msg. "Thank you, your request has been sent!"

    BUT I did not receive my email - Arrrggghhh.....

  5. #5
    Join Date
    Jun 2013
    Posts
    36

    Test PHP for email sent from form?

    Quote Originally Posted by sparkymom7 View Post
    My error message is gone, I received msg. "Thank you, your request has been sent!"

    BUT I did not receive my email - Arrrggghhh.....
    Anyone have a way to test server to see why email didn't send? Is there specific line of code that can be added to my PHP code for testing against server? If so, is it at beginning of PHP code after
    <?php

    ??blah, blah, blah??

    Thanks

  6. #6
    Join Date
    Jun 2013
    Posts
    36
    Update, I had problems with getting SMTP to work properly while making changes to php.ini and sendmail.ini so I setup PHPMailer and used the following code. I hope this helps someone else down the road.

    Now I just have to get server side validation working.

    [PHP]
    <?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_branch, 2)); // removes the R_ and capitalizes first letter of branch in final output to email
    $S_branch = ucfirst(substr($S_branch, 2)); // 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_emails[ $_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("user3@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!';
    }
    }
    ?>
    [/PHP}

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles