Hi,

I’m trying to add an attachment to an automated email resonse that someone else setup under php. The form, response and thank you all work fine but I just can’t get the response to attach a file. I’m probably getting the syntax wrong but I don’t see where. These are only two lines I’m changing:

$numfileattachments = 1;
$attachments = '\downloads\test.pdf';

Any ideas? What am I missing?

    what you've shown us doesnt help much as we have no idea what the rest of the script looks like... is it using the stock mail() functions or the phpmailer package, etc

    once we know that we can assist you in properly sending an attachment via email

    if you check out [man]mail[/man] there are some user based examples down the page that show how to send attachments

      Sorry, I though the syntax would be unique: Here is the full page:

      <html>
      <head>
      <title>Torbay Scooters - Enquiry sent - thank you</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>

      <body>
      <?php
      //error_reporting(E_ALL);
      //Collect post variables.
      $customername=($POST['contact']);
      $company=($
      POST['company']);
      $telephone=($POST['telephone']);
      $email=($
      POST['email']);
      $scooters=($POST['scooters']);
      $accessories=($
      POST['accessories']);
      $training=($POST['training']);
      $insurance=($
      POST['insurance']);
      $maintenance=($POST['maintenance']);
      $finance=($
      POST['finance']);
      $comments=($_POST['comments']);

      //EMail Details

      $recipient = 'john.shepherd@torbayscooters.co.uk';
      $sender = 'web-feedback@torbayscooters.co.uk';
      $subject = 'Top Tips Scooter Buying Guide Download';

      $email_format = '';
      $email_type = 'plain';
      $smtp = 'mail.torbayscooters.co.uk';
      $referer_check = 0;
      $gpg_use = 0;

      $message = "CONTACT DETAILS\n\nName: \t\t".$contact."\nCompany: \t\t".$company."\n"."Telephone:";
      $message.= "\t\t".$telephone."\n"."Email: \t\t".$email."\n";
      $message.="Enquiry Detail:\n\n";
      $message.="Scooters: ".$scooters."\n";
      $message.="Accessories: ".$accessories."\n";
      $message.="Training: ".$training."\n";
      $message.="Maintenance: ".$maintenance."\n";
      $message.="Finance: ".$finance."\n";
      $message.="Comments: ".$comments."\n";
      $message.="** End of Message **\n";

      $custmes="Hi,

      Thank you for requesting our ‘Top Tips to Buying a Scooter’ guide, we hope you find it useful.

      This guide requires Adobe Acrobat Reader to view. If you do not have this installed on your computer, it can be downloaded from http://get.adobe.com/uk/reader. An HTML version can be requested by emailing sales@torbayscooters.co.uk or by using our online contact form located at http://www.torbayscooters.co.uk/contact.php.

      We always appreciate feedback from customers and users of our website. If you have any comments, please email us at sales@torbayscooters.co.uk or use our online contact form located at http://www.torbayscooters.co.uk/contact.php.

      Regards,

      Torbay Scooter & Motorcycle Centre
      141 – 143 Winner Street
      Paignton
      Devon
      TQ3 3BP
      Tel: 01803 557788\n\n";

      $custmes.="Please DO NOT RESPOND to this email. If you need to contact us again please email sales@torbayscooters.co.uk\n\n";

      $numfileattachments = 1;
      $attachments = 'test.pdf';
      $senttime = senttime();
      $required = '';
      global $vars;
      if(!isset($SERVER)) { $SERVER = $HTTP_SERVER_VARS; }
      if(!isset($POST)) { $POST = $HTTP_POST_VARS; }
      if(!isset($GET)) { $GET = $HTTP_GET_VARS; }
      if(!isset($COOKIE)) { $COOKIE = $HTTP_COOKIE_VARS; }
      if(!isset($FILES)) { $FILES = $HTTP_POST_FILES; }
      if(!isset($ENV)) { $ENV = $HTTP_ENV_VARS; }
      if(!isset($SESSION)) { $SESSION = $HTTP_SESSION_VARS; }
      while(list($key, $var) = each($GET)) { $vars[$key] = $var; }
      while(list($key, $var) = each($
      POST)) { $vars[$key] = $var; }
      //get_details();
      //check_details();
      $boundary = '';
      $rands = array(
      "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
      "R","S","T","U","V","W","X","Y","Z","0","9","8","7","6","5","4","3",
      "2","1");

      srand((double)microtime()*1000000 );

      do {
      $s = sizeof($rands);
      for($l=1; $l<=32; ++$l){
      //$boundary .= $rands[rand()*$s];
      $boundary .= $rands[rand(0,$s-1)];
      }
      } while(strpos($message, $boundary) or strpos($attachments, $boundary));

      $gpg_use = 0;
      $custmes=message_construct($custmes);
      sendmail_php($email,$custmes);
      $message=message_construct($message);
      sendmail_php($recipient,$message);

      if(!strlen($redirect)){
      sentok();
      } else {
      if(sizeof($forward)) {
      $redirect .= '?';
      for($l=0; $l<sizeof($forward); ++$l) {
      $redirect .= urlencode($forward[$l]).'='.urlencode($vars[$forward[$l]]).'&';
      }
      $redirect = preg_replace("'&$'", "", $redirect);
      }
      sentok();
      //header("Location: ".$redirect);
      }

      exit();

      function senttime() {
      return date("D, d M Y H:i:s O", time()+($tdif*3600));
      }

      function sendmail_php($recipient,$message) {
      global $subject;
      global $_ENV;
      global $sender;
      global $senttime;
      global $email_type;
      global $boundary;
      global $attachments;

      $host = $_ENV['HTTP_HOST'];
      if($host == '') {
      	$host = $recipient;
      	$host = preg_replace('/^.*@/', "", $host);
      	$host = preg_replace('/^,*$/', "", $host);
      } else {
      	$host = preg_replace('/^www\./i', "", $host);
      }
      
      // make sure the sender is set and that it's a valid email address
      if(!$sender or !preg_match('/^[[0-9]|[a-z]|\-|\_|\.]{2,}\@[[0-9]|[a-z]|\-]+\.[[0-9]|[a-z]|\-|\.]+$/s', $sender)){
      	$sender = "noreply@".$host;
      }
      
      $recipients = split(',', $recipient);
      $mrecipients = array();
      for($l=0; $l<sizeof($recipients); ++$l) {
      	$r = $recipients[$l];
      	// make sure it's not a fake recipient e-mail address, if so then
      	// we may as well bomb...
      	if(!preg_match('/^[[0-9]|[a-z]|\-|\_|\.]{2,}\@[[0-9]|[a-z]|\-]+\.[[0-9]|[a-z]|\-|\.]+$/is', $r)) {
      		cant_send();
      	}
      	$r = preg_replace('/(^\s)|(\s$)/', "", $r);
      	$mrecipients[] = $r;
      }
      
      $headers =	"From: ".$sender."\n".
      		"Subject: ".$subject."\n".
      		"Date: ".$senttime."\n".
      		"To: ".$recipient."\n".
      		"X-Mailer: RCCDS Automated\n".
      		"X-Mailer-URL: http://rccds.co.uk\n".
      		"MIME-Version: 1.0\n".
      		"Content-type: multipart/mixed; charset=US-ASCII; boundary=".$boundary."\n\n".
      		"--".$boundary."\n".
      		"Content-Type: text/".$email_type."; charset=US-ASCII\n";
      
      //$buf .= "\n".$boundary."\n\n";
      
      if(!mail(implode(",", $mrecipients), $subject, $message, $headers)) {
      	cant_send('viaapp');	
      }

      }

      function message_construct($message) {
      global $vars;
      global $email_format;
      global $COOKIE;
      global $
      ENV;
      global $gpg_use;

      // make all necessary variable exchanges
      while(preg_match('/<\$([0-9]|[a-z]|[A-Z]|_|\-|!>)+>/', $message, $matches)) {
      	$var = $matches[0];
      
      	$var = ereg_replace('^(<\$)|>$', '', $var);
      
      	$val = '['.$var.' - undefined]';
      
      	// firstly, is it an internal variable?
      	if($var == "senttime") {
      		$val = senttime();
      	} else if ($var == "all_vars") {
      		$val = '';
      		while(list($key,$valt) = each($vars)) {
      			$val .= "\"".$key."\" => \"".$valt."\"\n";
      		}
      	} else {
      		// the variable is POST or GET, swap it
      		if(isset($vars[$var])) {
      			$val = $vars[$var];
      		} else {
      			// hrm, is it an environment variable?
      			if(isset($_ENV[$var])) {
      				// yup, make the change
      				$val = $_ENV[$var];
      			} else {
      				// is it a cookie?
      				if(isset($_COOKIE[$var])) {
      					// yay
      					$val = $_COOKIE[$var];
      				}
      			}
      		}
      	}
      
      	$message = str_replace('<$'.$var.'>', $val, $message);
      }
      
      $message = str_replace("\n", "\r\n", $message);
      
      return $message;

      }

      // the following commands all show different errors/success' details

      function smtp_error() {
      global $smtp;

      echo '

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
      <title>SMTP error</title>
      </head>
      <body>
      <h3 align="center">Unable to send email because the SMTP server located @ ', $smtp, ' did not send the correct response.</h3>
      <font face="verdana" size="3"><div align="center">Please click <a href="javascript:window.back();">here</a> to go back and try again.</div></font>
      </body>
      </html>
      ';

      exit();

      }

      function sentok() {
      global $recipient;
      global $db;
      global $userid;
      global $HTTP_COOKIE_VARS;
      echo '
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <title>Torbay Scooters - Mopeds and Scooters from Baotian, Keeway, Benelli - Budget personal transport in Devon</title>
      <link href="torbayscooters.css" rel="stylesheet" type="text/css" />
      </head>
      <body bgcolor="#ffffff">

      <p>&nbsp;</p>
      <p><div align="center"><h1>ENQUIRY SUBMITTED</h1></div></p>

      <br><br>
      <font size="xx-large" colour="#990000"><b><div align="center">THANK YOU!</div></b></font>
      <br>
      <br>
      <br>
      <font size="xx-large" colour="#990000"><div align="center">Your enquiry has been submitted.</div><br>
      <br>
      <div align="center">We will endeavour to respond within 24 hours wherever possible.<br>
      <br>
      Click <a href="index.php">here</a> to return to homepage.
      <br>
      </div>

      </font>
      </body>
      </html>

      ';
      exit();
      }

      function cant_send() {

      echo '
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
      <title>Unable to send email</title>
      <body>
      <p>&nbsp;</p>
      <div align="center">
      Oops! - Unable to send your email...<br><br>
      Please check your email address and try again!<br><br>
      Click <a href="javascript:window.back();">here</a> to go back and check the form.</div>
      </body>
      </html>
      ';
      
      exit();

      }

      ?>

        Write a Reply...