www.webdeveloper.com
Results 1 to 3 of 3

Thread: PhpMailer Redirect Error Message

  1. #1
    Join Date
    Dec 2008
    Posts
    134

    PhpMailer Redirect Error Message

    I am using the below code for a webform but getting the below error messages. Please help. Thanks.

    Error 1
    Code:
    Warning: Cannot modify header information - headers already sent by (output started at class.phpmailer.php:1370) in processform.php on line 63
    Error 2 - With this error message the attachment is not required but can upload max 4 files.
    Code:
    Could not access file: Array Could not access file: Array Could not access file: Array Could not access file: Array
    PHP Code:
    <?php
        $errors 
    = array();
        if (
    'POST' === $_SERVER['REQUEST_METHOD'])
        {
            
    $name           sanitize($_POST['name']);
            
    $email                 sanitize($_POST['email']);

            if (empty(
    $name))
            {
                
    $errors['name'] = "Please provide name.";
            }
     
            if (!
    filter_var($emailFILTER_VALIDATE_EMAIL))
            {
                
    $errors['email'] = "Please provide a valid email address.";
            }
               
    // If there are no errors let's process the payment
            
    if (count($errors) === 0)
            {
                
        require(
    "class.phpmailer.php");
        
        
    $mail = new PHPMailer();
        
    $mail->From     $email;
        
    $mail->AddAddress("myfriend@example.net");

        
    $mail->Subject  "Test";
        
    $mail->Body     "some message here.";
        
    $mail->WordWrap 50;

        
    $mail->AddAttachment($_FILES['file']['tmp_name']);
        
    $mail->AddAttachment($_FILES['file']['tmp_name']);
        
    $mail->AddAttachment($_FILES['file']['tmp_name']);
        
    $mail->AddAttachment($_FILES['file']['tmp_name']);

        
    $mail->Send();
        
        exit(
    header("Location: thankyou.php"));
                }    }

    function 
    sanitize($value)
        {
            return 
    trim(strip_tags($value));
        }
    ?>
    Last edited by phpnewbie08; 03-10-2013 at 01:43 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,338
    If you defined your HTML file inputs using the "[]" notation for its name, then instead of this...
    PHP Code:
        $mail->AddAttachment($_FILES['file']['tmp_name']);
        
    $mail->AddAttachment($_FILES['file']['tmp_name']);
        
    $mail->AddAttachment($_FILES['file']['tmp_name']);
        
    $mail->AddAttachment($_FILES['file']['tmp_name']); 
    ...you'll want to do something like this...
    PHP Code:
    foreach($FILES['file']['tmp_name'] as $file_name) {
        if(!empty(
    $file_name)) {
            
    $mail->AddAttachment($file_name);
        }

    I'm guessing for now that the error message #2 is coming from that code, and is actually happening before error message #1, which is caused by the output of the #2 errors. If that's not the case, then it could be something else generating output, such as a BOM (byte order mark) before the opening <?php tag (if saving your PHP file as UTF-8, make sure it is without a BOM). If that's not it, then you might want to start the script with an ob_start() to buffer output.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2013
    Posts
    18
    Thanks nogdog, ob_start() helps the first problem.

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