Hi

I need some help with a php script that creates a file, attaches and then emails it.

This can be seen here : http://www.phpbuilder.com/board/showthread.php?p=10975594

The slight issue I have is my mail server requires SMTP Authentication.

Can anyone help me with that ?

I haven some posts about pear, but I'm not sure how to add that to this script.

Thanks for any help or advice. 🙂

    cant do it with php's mail() command, install a third party script like phpmailer

      Thanks, using phpmailer's example I have the smtp auth working::

      require_once('../class.phpmailer.php');
      //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
      
      $mail             = new PHPMailer();
      
      $body             = file_get_contents('contents.html');
      $body             = eregi_replace("[\]",'',$body);
      
      $mail->IsSMTP(); // telling the class to use SMTP
      $mail->Host       = "mail.yourdomain.com"; // SMTP server
      $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                                 // 1 = errors and messages
                                                 // 2 = messages only
      $mail->SMTPAuth   = true;                  // enable SMTP authentication
      $mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
      $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
      $mail->Username   = "yourname@yourdomain"; // SMTP account username
      $mail->Password   = "yourpassword";        // SMTP account password
      
      $mail->SetFrom('name@yourdomain.com', 'First Last');
      
      $mail->AddReplyTo("name@yourdomain.com","First Last");
      
      $mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";
      
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      
      $mail->MsgHTML($body);
      
      $address = "whoto@otherdomain.com";
      $mail->AddAddress($address, "John Doe");
      
      $mail->AddAttachment("images/phpmailer.gif");      // attachment
      $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
      
      if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
      } else {
        echo "Message sent!";
      }
          

      How would I dynamically create an attachment and then add it ?

      This is the basic code from the last script that create the attachment and then added it to the mail.

      $cr = "\r\n";
      $csvdata = "data data" . $cr;
      $csvdata .= " More datatatata"  . $cr;
      
      $thisfile = 'test.txt';
      
      $encoded = chunk_split(base64_encode($csvdata));
      
      
      $subject = "File you requested from RRWH.com";
      $from = "email@test.com";
      $headers = 'MIME-Version: 1.0' . "\n";
      $headers .= 'Content-Type: multipart/mixed;
         boundary="----=_NextPart_001_0011_1234ABCD.4321FDAC"' . "\n";
      
      $message = '
      
      This is a multi-part message in MIME format.
      
      ------=_NextPart_001_0011_1234ABCD.4321FDAC
      Content-Type: text/plain;
             charset="us-ascii"
      Content-Transfer-Encoding: 7bit
      
      Hello
      
      We have attached for you the PHP script that you requested from http://rrwh.com/scripts.php
      as a zip file.
      
      Regards
      
      ------=_NextPart_001_0011_1234ABCD.4321FDAC
      Content-Type: application/octet-stream;  name="';
      
      $message .= "$thisfile";
      $message .= '"
      Content-Transfer-Encoding: base64
      Content-Disposition: attachment; filename="';
      $message .= "$thisfile";
      $message .= '"
      
      ';
      $message .= "$encoded";
      $message .= '

      Any Ideas ? Thanks 🙂

        Sorted 😃

        $cr = "\r\n";
        $csvdata = "data data" . $cr;
        $csvdata .= " More datatatata"  . $cr;
        
        
        $mail->AddStringAttachment($csvdata, $name = "test.txt", $encoding = "base64", $type = "application/octet-stream");
          Write a Reply...