472,102 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

How to add phone number to contact form and send with email

This is my HTML...

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script>
  3. <script type="text/javascript" src="js/script.js"></script>
  4. </head>
  5.  
  6. <body>
  7.  
  8. <form method="post" id="QuoteFormMain"  
  9.                     action="sendEmail.php">
  10.  
  11.  <div id="container">
  12.  
  13.  <div id="main">
  14.  
  15.    <p> <small>Name:</small> 
  16.         <input type="text" name="name" id="name" />
  17.    </p>
  18.  
  19.    <p> <small>Email Address:</small> 
  20.         <input type="text" name="email" id="email" />
  21.    </p>
  22.  
  23.    <p> <small>Phone Number:</small> 
  24.        <input type="text" name="phone" id="phone" />
  25.    </p>
  26.  
  27.    <p> <small>Enquiry/Questions/Comments:</small> 
  28.  <textarea name="comments" 
  29.            id="comments" 
  30.            rows="12">
  31.  </textarea></p>    
  32.  
  33.    <p> <input type="submit" name="submit" 
  34.               id="submit" value="Email Us!" />
  35.    </p>
  36.          <ul id="response" />
  37.  
  38.   </div><!--end main -->
  39.  
  40.   </div><!-- end container -->
  41.  
  42. </form>  
  43.  
  44.  
This is my php script for processing... (sendEmail.php)

Expand|Select|Wrap|Line Numbers
  1.  
  2. $name = trim($_POST['name']);
  3.     $email = $_POST['email'];
  4.  
  5.     $phone = $_POST['phone'];
  6.  
  7.     $comments = $_POST['comments'];
  8.  
  9.     $site_owners_email = '2893@hotmail.co.uk'; // my email address
  10.     $site_owners_name = 'Jj'; // my name
  11.  
  12.     if (strlen($name) < 2) {
  13.         $error['name'] = "Please enter your name";    
  14.     }
  15.  
  16.     if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
  17.         $error['email'] = "Please enter a valid email address";    
  18.     }
  19.  
  20.     if ($phone == '') {
  21.         $error['phone'] = "Please enter a valid phone number";    
  22.  
  23.     }
  24.  
  25.     if (strlen($comments) < 10) {
  26.         $error['comments'] = "Please leave a comment.";
  27.     }
  28.  
  29.     if (!$error) {
  30.  
  31.         require_once('phpMailer/class.phpmailer.php');
  32.         $mail = new PHPMailer();
  33.  
  34.         $mail->From = $email;
  35.         $mail->FromName = $name; 
  36.         $mail->Subject = "Website Contact Form";
  37.         $mail->AddAddress($site_owners_email, $site_owners_name);
  38.         $mail->AddAddress('2893@hotmail.co.uk', jayj');
  39.         $mail->Body = $phone;
  40.         $mail->Body = $comments;
  41.  
  42.  
  43.  
  44.         $mail->Send();
  45.  
  46.         echo "<li class='success'> Congratulations, " . $name . ". We've received your email. We'll be in touch as soon as we possibly can! </li>";
  47.  
  48.     } # end if no error
  49.     else {
  50.  
  51.         $response = (isset($error['name'])) ? "<li>" . $error['name'] . "</li> \n" : null;
  52.         $response .= (isset($error['email'])) ? "<li>" . $error['email'] . "</li> \n" : null;
  53.         $response .= (isset($error['phone'])) ? "<li>" . $error['phone'] . "</li> \n" : null;
  54.         $response .= (isset($error['comments'])) ? "<li>" . $error['comments'] . "</li>" : null;
  55.  
  56.         echo $response;
  57.     } # end if there was an error sending
  58.  
This is script.js

Expand|Select|Wrap|Line Numbers
  1.  
  2. $(function() {
  3.     // These first three lines of code compensate for Javascript being turned on and off. 
  4.     // It simply changes the submit input field from a type of "submit" to a type of "button".
  5.  
  6.     var paraTag = $('input#submit').parent('p');
  7.     $(paraTag).children('input').remove();
  8.     $(paraTag).append('<input type="button" name="submit" id="submit" value="Email Us Now!" />');
  9.  
  10.     $('#main input#submit').click(function() {
  11.         $('#main').append('<img src="images/ajax-loader.gif" class="loaderIcon" alt="Loading..." />');
  12.  
  13.         var name = $('input#name').val();
  14.         var email = $('input#email').val();
  15.         var phone = $('input#phone').val();
  16.         var comments = $('textarea#comments').val();
  17.  
  18.         $.ajax({
  19.             type: 'post',
  20.             url: 'sendEmail.php',
  21.             data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&comments=' + comments,
  22.  
  23.              success: function(results) {
  24.                 $('#main img.loaderIcon').fadeOut(1000);
  25.                 $('ul#response').html(results);
  26.             }
  27.         }); // end ajax
  28.     });
  29. });
  30.  
  31.  
  32.  
  33.  
these are php classes from phpMailer/class.phpmailer.php

Expand|Select|Wrap|Line Numbers
  1. class PHPMailer {
  2.  
  3.   /////////////////////////////////////////////////
  4.   // PROPERTIES, PUBLIC
  5.   /////////////////////////////////////////////////
  6.  
  7.   /**
  8.    * Email priority (1 = High, 3 = Normal, 5 = low).
  9.    * @var int
  10.    */
  11.   public $Priority          = 3;
  12.  
  13.   /**
  14.    * Sets the CharSet of the message.
  15.    * @var string
  16.    */
  17.   public $CharSet           = 'iso-8859-1';
  18.  
  19.   /**
  20.    * Sets the Content-type of the message.
  21.    * @var string
  22.    */
  23.   public $ContentType       = 'text/plain';
  24.  
  25.   /**
  26.    * Sets the Encoding of the message. Options for this are "8bit",
  27.    * "7bit", "binary", "base64", and "quoted-printable".
  28.    * @var string
  29.    */
  30.   public $Encoding          = '8bit';
  31.  
  32.   /**
  33.    * Holds the most recent mailer error message.
  34.    * @var string
  35.    */
  36.   public $ErrorInfo         = '';
  37.  
  38.   /**
  39.    * Sets the From email address for the message.
  40.    * @var string
  41.    */
  42.   public $From              = 'root@localhost';
  43.  
  44.   /**
  45.    * Sets the From name of the message.
  46.    * @var string
  47.    */
  48.   public $FromName          = 'Root User';
  49.  
  50.   /**
  51.    * Sets the Sender email (Return-Path) of the message.  If not empty,
  52.    * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  53.    * @var string
  54.    */
  55.   public $Sender            = '';
  56.  
  57.   /**
  58.    * Sets the Subject of the message.
  59.    * @var string
  60.    */
  61.   public $Subject           = '';
  62.  
  63.   /**
  64.    * Sets the Body of the message.  This can be either an HTML or text body.
  65.    * If HTML then run IsHTML(true).
  66.    * @var string
  67.    */
  68.   public $Body              = '';
  69.  
  70.   /**
  71.    * Sets the text-only body of the message.  This automatically sets the
  72.    * email to multipart/alternative.  This body can be read by mail
  73.    * clients that do not have HTML email capability such as mutt. Clients
  74.    * that can read HTML will view the normal Body.
  75.    * @var string
  76.    */
  77.   public $AltBody           = '';
  78.  
  79.   /**
  80.    * Sets word wrapping on the body of the message to a given number of
  81.    * characters.
  82.    * @var int
  83.    */
  84.   public $WordWrap          = 0;
  85.  
  86.   /**
  87.    * Method to send mail: ("mail", "sendmail", or "smtp").
  88.    * @var string
  89.    */
  90.   public $Mailer            = 'mail';
  91.  
  92.   /**
  93.    * Sets the path of the sendmail program.
  94.    * @var string
  95.    */
  96.   public $Sendmail          = '/usr/sbin/sendmail';
  97.  
  98.   /**
  99.    * Path to PHPMailer plugins.  This is now only useful if the SMTP class
  100.    * is in a different directory than the PHP include path.
  101.    * @var string
  102.    */
  103.   public $PluginDir         = '';
  104.  
  105.   /**
  106.    * Holds PHPMailer version.
  107.    * @var string
  108.    */
  109.   public $Version           = "2.2";
  110.  
  111.   /**
  112.    * Sets the email address that a reading confirmation will be sent.
  113.    * @var string
  114.    */
  115.   public $ConfirmReadingTo  = '';
  116.  
  117.   /**
  118.    * Sets the hostname to use in Message-Id and Received headers
  119.    * and as default HELO string. If empty, the value returned
  120.    * by SERVER_NAME is used or 'localhost.localdomain'.
  121.    * @var string
  122.    */
  123.   public $Hostname          = '';
  124.  
  125.   /**
  126.    * Sets the message ID to be used in the Message-Id header.
  127.    * If empty, a unique id will be generated.
  128.    * @var string
  129.    */
  130.   public $MessageID      = '';
  131.  
  132.   /////////////////////////////////////////////////
  133.   // PROPERTIES FOR SMTP
  134.   /////////////////////////////////////////////////
  135.  
  136.   /**
  137.    * Sets the SMTP hosts.  All hosts must be separated by a
  138.    * semicolon.  You can also specify a different port
  139.    * for each host by using this format: [hostname:port]
  140.    * (e.g. "smtp1.example.com:25;smtp2.example.com").
  141.    * Hosts will be tried in order.
  142.    * @var string
  143.    */
  144.   public $Host        = 'localhost';
  145.  
  146.   /**
  147.    * Sets the default SMTP server port.
  148.    * @var int
  149.    */
  150.   public $Port        = 25;
  151.  
  152.   /**
  153.    * Sets the SMTP HELO of the message (Default is $Hostname).
  154.    * @var string
  155.    */
  156.   public $Helo        = '';
  157.  
  158.   /**
  159.    * Sets connection prefix.
  160.    * Options are "", "ssl" or "tls"
  161.    * @var string
  162.    */
  163.   public $SMTPSecure = "";
  164.  
  165.   /**
  166.    * Sets SMTP authentication. Utilizes the Username and Password variables.
  167.    * @var bool
  168.    */
  169.   public $SMTPAuth     = false;
  170.  
  171.   /**
  172.    * Sets SMTP username.
  173.    * @var string
  174.    */
  175.   public $Username     = '';
  176.  
  177.   /**
  178.    * Sets SMTP password.
  179.    * @var string
  180.    */
  181.   public $Password     = '';
  182.  
  183.   /**
  184.    * Sets the SMTP server timeout in seconds. This function will not
  185.    * work with the win32 version.
  186.    * @var int
  187.    */
  188.   public $Timeout      = 10;
  189.  
  190.   /**
  191.    * Sets SMTP class debugging on or off.
  192.    * @var bool
  193.    */
  194.   public $SMTPDebug    = false;
  195.  
  196.   /**
  197.    * Prevents the SMTP connection from being closed after each mail
  198.    * sending.  If this is set to true then to close the connection
  199.    * requires an explicit call to SmtpClose().
  200.    * @var bool
  201.    */
  202.   public $SMTPKeepAlive = false;
  203.  
  204.   /**
  205.    * Provides the ability to have the TO field process individual
  206.    * emails, instead of sending to entire TO addresses
  207.    * @var bool
  208.    */
  209.   public $SingleTo = false;
  210.  
  211.   /////////////////////////////////////////////////
  212.   // PROPERTIES, PRIVATE
  213.   /////////////////////////////////////////////////
  214.  
  215.   private $smtp            = NULL;
  216.   private $to              = array();
  217.   private $cc              = array();
  218.   private $bcc             = array();
  219.   private $ReplyTo         = array();
  220.   private $attachment      = array();
  221.   private $CustomHeader    = array();
  222.   private $message_type    = '';
  223.   private $boundary        = array();
  224.   private $language        = array();
  225.   private $error_count     = 0;
  226.   private $LE              = "\n";
  227.   private $sign_cert_file  = "";
  228.   private $sign_key_file   = "";
  229.   private $sign_key_pass   = "";
  230.  
  231.   /////////////////////////////////////////////////
  232.   // METHODS, VARIABLES
  233.   /////////////////////////////////////////////////
  234.  
  235.   /**
  236.    * Sets message type to HTML.
  237.    * @param bool $bool
  238.    * @return void
  239.    */
  240.   public function IsHTML($bool) {
  241.     if($bool == true) {
  242.       $this->ContentType = 'text/html';
  243.     } else {
  244.       $this->ContentType = 'text/plain';
  245.     }
  246.   }
  247.  
  248.   /**
  249.    * Sets Mailer to send message using SMTP.
  250.    * @return void
  251.    */
  252.   public function IsSMTP() {
  253.     $this->Mailer = 'smtp';
  254.   }
  255.  
  256.   /**
  257.    * Sets Mailer to send message using PHP mail() function.
  258.    * @return void
  259.    */
  260.   public function IsMail() {
  261.     $this->Mailer = 'mail';
  262.   }
  263.  
  264.   /**
  265.    * Sets Mailer to send message using the $Sendmail program.
  266.    * @return void
  267.    */
  268.   public function IsSendmail() {
  269.     $this->Mailer = 'sendmail';
  270.   }
  271.  
  272.   /**
  273.    * Sets Mailer to send message using the qmail MTA.
  274.    * @return void
  275.    */
  276.   public function IsQmail() {
  277.     $this->Sendmail = '/var/qmail/bin/sendmail';
  278.     $this->Mailer   = 'sendmail';
  279.   }
  280.  
  281.   /////////////////////////////////////////////////
  282.   // METHODS, RECIPIENTS
  283.   /////////////////////////////////////////////////
  284.  
  285.   /**
  286.    * Adds a "To" address.
  287.    * @param string $address
  288.    * @param string $name
  289.    * @return void
  290.    */
  291.   public function AddAddress($address, $name = '') {
  292.     $cur = count($this->to);
  293.     $this->to[$cur][0] = trim($address);
  294.     $this->to[$cur][1] = $name;
  295.   }
  296.  
  297.   /**
  298.    * Adds a "Cc" address. Note: this function works
  299.    * with the SMTP mailer on win32, not with the "mail"
  300.    * mailer.
  301.    * @param string $address
  302.    * @param string $name
  303.    * @return void
  304.    */
  305.   public function AddCC($address, $name = '') {
  306.     $cur = count($this->cc);
  307.     $this->cc[$cur][0] = trim($address);
  308.     $this->cc[$cur][1] = $name;
  309.   }
  310.  
  311.   /**
  312.    * Adds a "Bcc" address. Note: this function works
  313.    * with the SMTP mailer on win32, not with the "mail"
  314.    * mailer.
  315.    * @param string $address
  316.    * @param string $name
  317.    * @return void
  318.    */
  319.   public function AddBCC($address, $name = '') {
  320.     $cur = count($this->bcc);
  321.     $this->bcc[$cur][0] = trim($address);
  322.     $this->bcc[$cur][1] = $name;
  323.   }
  324.  
  325.   /**
  326.    * Adds a "Reply-to" address.
  327.    * @param string $address
  328.    * @param string $name
  329.    * @return void
  330.    */
  331.   public function AddReplyTo($address, $name = '') {
  332.     $cur = count($this->ReplyTo);
  333.     $this->ReplyTo[$cur][0] = trim($address);
  334.     $this->ReplyTo[$cur][1] = $name;
  335.   }
  336.  
  337.   /////////////////////////////////////////////////
  338.   // METHODS, MAIL SENDING
  339.   /////////////////////////////////////////////////
  340.  
  341.   /**
  342.    * Creates message and assigns Mailer. If the message is
  343.    * not sent successfully then it returns false.  Use the ErrorInfo
  344.    * variable to view description of the error.
  345.    * @return bool
  346.    */
  347.   public function Send() {
  348.     $header = '';
  349.     $body = '';
  350.     $result = true;
  351.  
  352.     if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  353.       $this->SetError($this->Lang('provide_address'));
  354.       return false;
  355.     }
  356.  
  357.     /* Set whether the message is multipart/alternative */
  358.     if(!empty($this->AltBody)) {
  359.       $this->ContentType = 'multipart/alternative';
  360.     }
  361.  
  362.     $this->error_count = 0; // reset errors
  363.     $this->SetMessageType();
  364.     $header .= $this->CreateHeader();
  365.     $body = $this->CreateBody();
  366.  
  367.     if($body == '') {
  368.       return false;
  369.     }
  370.  
  371.     /* Choose the mailer */
  372.     switch($this->Mailer) {
  373.       case 'sendmail':
  374.         $result = $this->SendmailSend($header, $body);
  375.         break;
  376.       case 'smtp':
  377.         $result = $this->SmtpSend($header, $body);
  378.         break;
  379.       case 'mail':
  380.         $result = $this->MailSend($header, $body);
  381.         break;
  382.       default:
  383.         $result = $this->MailSend($header, $body);
  384.         break;
  385.         //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
  386.         //$result = false;
  387.         //break;
  388.     }
  389.  
  390.     return $result;
  391.   }
  392.  
  393.   /**
  394.    * Sends mail using the $Sendmail program.
  395.    * @access public
  396.    * @return bool
  397.    */
  398.   public function SendmailSend($header, $body) {
  399.     if ($this->Sender != '') {
  400.       $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  401.     } else {
  402.       $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  403.     }
  404.  
  405.     if(!@$mail = popen($sendmail, 'w')) {
  406.       $this->SetError($this->Lang('execute') . $this->Sendmail);
  407.       return false;
  408.     }
  409.  
  410.     fputs($mail, $header);
  411.     fputs($mail, $body);
  412.  
  413.     $result = pclose($mail);
  414.     if (version_compare(phpversion(), '4.2.3') == -1) {
  415.       $result = $result >> 8 & 0xFF;
  416.     }
  417.     if($result != 0) {
  418.       $this->SetError($this->Lang('execute') . $this->Sendmail);
  419.       return false;
  420.     }
  421.  
  422.     return true;
  423.   }
  424.  
  425.   /**
  426.    * Sends mail using the PHP mail() function.
  427.    * @access public
  428.    * @return bool
  429.    */
  430.   public function MailSend($header, $body) {
  431.  
  432.     $to = '';
  433.     for($i = 0; $i < count($this->to); $i++) {
  434.       if($i != 0) { $to .= ', '; }
  435.       $to .= $this->AddrFormat($this->to[$i]);
  436.     }
  437.  
  438.     $toArr = split(',', $to);
  439.  
  440.     $params = sprintf("-oi -f %s", $this->Sender);
  441.     if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
  442.       $old_from = ini_get('sendmail_from');
  443.       ini_set('sendmail_from', $this->Sender);
  444.       if ($this->SingleTo === true && count($toArr) > 1) {
  445.         foreach ($toArr as $key => $val) {
  446.           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  447.         }
  448.       } else {
  449.         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  450.       }
  451.     } else {
  452.       if ($this->SingleTo === true && count($toArr) > 1) {
  453.         foreach ($toArr as $key => $val) {
  454.           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  455.         }
  456.       } else {
  457.         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
  458.       }
  459.     }
  460.  
  461.     if (isset($old_from)) {
  462.       ini_set('sendmail_from', $old_from);
  463.     }
  464.  
  465.     if(!$rt) {
  466.       $this->SetError($this->Lang('instantiate'));
  467.       return false;
  468.     }
  469.  
  470.     return true;
  471.   }
  472.  
  473.   /**
  474.    * Sends mail via SMTP using PhpSMTP (Author:
  475.    * Chris Ryan).  Returns bool.  Returns false if there is a
  476.    * bad MAIL FROM, RCPT, or DATA input.
  477.    * @access public
  478.    * @return bool
  479.    */
  480.   public function SmtpSend($header, $body) {
  481.     include_once($this->PluginDir . 'class.smtp.php');
  482.     $error = '';
  483.     $bad_rcpt = array();
  484.  
  485.     if(!$this->SmtpConnect()) {
  486.       return false;
  487.     }
  488.  
  489.     $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  490.     if(!$this->smtp->Mail($smtp_from)) {
  491.       $error = $this->Lang('from_failed') . $smtp_from;
  492.       $this->SetError($error);
  493.       $this->smtp->Reset();
  494.       return false;
  495.     }
  496.  
  497.     /* Attempt to send attach all recipients */
  498.     for($i = 0; $i < count($this->to); $i++) {
  499.       if(!$this->smtp->Recipient($this->to[$i][0])) {
  500.         $bad_rcpt[] = $this->to[$i][0];
  501.       }
  502.     }
  503.     for($i = 0; $i < count($this->cc); $i++) {
  504.       if(!$this->smtp->Recipient($this->cc[$i][0])) {
  505.         $bad_rcpt[] = $this->cc[$i][0];
  506.       }
  507.     }
  508.     for($i = 0; $i < count($this->bcc); $i++) {
  509.       if(!$this->smtp->Recipient($this->bcc[$i][0])) {
  510.         $bad_rcpt[] = $this->bcc[$i][0];
  511.       }
  512.     }
  513.  
  514.     if(count($bad_rcpt) > 0) { // Create error message
  515.       for($i = 0; $i < count($bad_rcpt); $i++) {
  516.         if($i != 0) {
  517.           $error .= ', ';
  518.         }
  519.         $error .= $bad_rcpt[$i];
  520.       }
  521.       $error = $this->Lang('recipients_failed') . $error;
  522.       $this->SetError($error);
  523.       $this->smtp->Reset();
  524.       return false;
  525.     }
  526.  
  527.     if(!$this->smtp->Data($header . $body)) {
  528.       $this->SetError($this->Lang('data_not_accepted'));
  529.       $this->smtp->Reset();
  530.       return false;
  531.     }
  532.     if($this->SMTPKeepAlive == true) {
  533.       $this->smtp->Reset();
  534.     } else {
  535.       $this->SmtpClose();
  536.     }
  537.  
  538.     return true;
  539.   }
  540.  
  541.   /**
  542.    * Initiates a connection to an SMTP server.  Returns false if the
  543.    * operation failed.
  544.    * @access public
  545.    * @return bool
  546.    */
  547.   public function SmtpConnect() {
  548.     if($this->smtp == NULL) {
  549.       $this->smtp = new SMTP();
  550.     }
  551.  
  552.     $this->smtp->do_debug = $this->SMTPDebug;
  553.     $hosts = explode(';', $this->Host);
  554.     $index = 0;
  555.     $connection = ($this->smtp->Connected());
  556.  
  557.     /* Retry while there is no connection */
  558.     while($index < count($hosts) && $connection == false) {
  559.       $hostinfo = array();
  560.       if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
  561.         $host = $hostinfo[1];
  562.         $port = $hostinfo[2];
  563.       } else {
  564.         $host = $hosts[$index];
  565.         $port = $this->Port;
  566.       }
  567.  
  568.       $tls = ($this->SMTPSecure == 'tls');
  569.       $ssl = ($this->SMTPSecure == 'ssl');
  570.  
  571.       if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
  572.  
  573.         $hello = ($this->Helo != '' ? $this->Hello : $this->ServerHostname());
  574.         $this->smtp->Hello($hello);
  575.  
  576.         if($tls) {
  577.           if(!$this->smtp->StartTLS()) {
  578.             $this->SetError($this->Lang("tls"));
  579.             $this->smtp->Reset();
  580.             $connection = false;
  581.           }
  582.  
  583.           //We must resend HELLO after tls negociation
  584.           $this->smtp->Hello($hello);
  585.         }
  586.  
  587.         $connection = true;
  588.         if($this->SMTPAuth) {
  589.           if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
  590.             $this->SetError($this->Lang('authenticate'));
  591.             $this->smtp->Reset();
  592.             $connection = false;
  593.           }
  594.         }
  595.       }
  596.       $index++;
  597.     }
  598.     if(!$connection) {
  599.       $this->SetError($this->Lang('connect_host'));
  600.     }
  601.  
  602.     return $connection;
  603.   }
  604.  
  605.   /**
  606.    * Closes the active SMTP session if one exists.
  607.    * @return void
  608.    */
  609.   public function SmtpClose() {
  610.     if($this->smtp != NULL) {
  611.       if($this->smtp->Connected()) {
  612.         $this->smtp->Quit();
  613.         $this->smtp->Close();
  614.       }
  615.     }
  616.   }
  617.  
  618.   /**
  619.    * Sets the language for all class error messages.  Returns false
  620.    * if it cannot load the language file.  The default language type
  621.    * is English.
  622.    * @param string $lang_type Type of language (e.g. Portuguese: "br")
  623.    * @param string $lang_path Path to the language file directory
  624.    * @access public
  625.    * @return bool
  626.    */
  627.   function SetLanguage($lang_type = 'en', $lang_path = 'language/') {
  628.     if( !(@include $lang_path.'phpmailer.lang-'.$lang_type.'.php') ) {
  629.       $this->SetError('Could not load language file');
  630.       return false;
  631.     }
  632.     $this->language = $PHPMAILER_LANG;
  633.     return true;
  634.   }
  635.  
  636.   /////////////////////////////////////////////////
  637.   // METHODS, MESSAGE CREATION
  638.   /////////////////////////////////////////////////
  639.  
  640.   /**
  641.    * Creates recipient headers.
  642.    * @access public
  643.    * @return string
  644.    */
  645.   public function AddrAppend($type, $addr) {
  646.     $addr_str = $type . ': ';
  647.     $addr_str .= $this->AddrFormat($addr[0]);
  648.     if(count($addr) > 1) {
  649.       for($i = 1; $i < count($addr); $i++) {
  650.         $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
  651.       }
  652.     }
  653.     $addr_str .= $this->LE;
  654.  
  655.     return $addr_str;
  656.   }
  657.  
  658.   /**
  659.    * Formats an address correctly.
  660.    * @access public
  661.    * @return string
  662.    */
  663.   public function AddrFormat($addr) {
  664.     if(empty($addr[1])) {
  665.       $formatted = $this->SecureHeader($addr[0]);
  666.     } else {
  667.       $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  668.     }
  669.  
  670.     return $formatted;
  671.   }
  672.  
  673.   /**
  674.    * Wraps message for use with mailers that do not
  675.    * automatically perform wrapping and for quoted-printable.
  676.    * Original written by philippe.
  677.    * @access public
  678.    * @return string
  679.    */
  680.   public function WrapText($message, $length, $qp_mode = false) {
  681.     $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  682.     // If utf-8 encoding is used, we will need to make sure we don't
  683.     // split multibyte characters when we wrap
  684.     $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  685.  
  686.     $message = $this->FixEOL($message);
  687.     if (substr($message, -1) == $this->LE) {
  688.       $message = substr($message, 0, -1);
  689.     }
  690.  
  691.     $line = explode($this->LE, $message);
  692.     $message = '';
  693.     for ($i=0 ;$i < count($line); $i++) {
  694.       $line_part = explode(' ', $line[$i]);
  695.       $buf = '';
  696.       for ($e = 0; $e<count($line_part); $e++) {
  697.         $word = $line_part[$e];
  698.         if ($qp_mode and (strlen($word) > $length)) {
  699.           $space_left = $length - strlen($buf) - 1;
  700.           if ($e != 0) {
  701.             if ($space_left > 20) {
  702.               $len = $space_left;
  703.               if ($is_utf8) {
  704.                 $len = $this->UTF8CharBoundary($word, $len);
  705.               } elseif (substr($word, $len - 1, 1) == "=") {
  706.                 $len--;
  707.               } elseif (substr($word, $len - 2, 1) == "=") {
  708.                 $len -= 2;
  709.               }
  710.               $part = substr($word, 0, $len);
  711.               $word = substr($word, $len);
  712.               $buf .= ' ' . $part;
  713.               $message .= $buf . sprintf("=%s", $this->LE);
  714.             } else {
  715.               $message .= $buf . $soft_break;
  716.             }
  717.             $buf = '';
  718.           }
  719.           while (strlen($word) > 0) {
  720.             $len = $length;
  721.             if ($is_utf8) {
  722.               $len = $this->UTF8CharBoundary($word, $len);
  723.             } elseif (substr($word, $len - 1, 1) == "=") {
  724.               $len--;
  725.             } elseif (substr($word, $len - 2, 1) == "=") {
  726.               $len -= 2;
  727.             }
  728.             $part = substr($word, 0, $len);
  729.             $word = substr($word, $len);
  730.  
  731.             if (strlen($word) > 0) {
  732.               $message .= $part . sprintf("=%s", $this->LE);
  733.             } else {
  734.               $buf = $part;
  735.             }
  736.           }
  737.         } else {
  738.           $buf_o = $buf;
  739.           $buf .= ($e == 0) ? $word : (' ' . $word);
  740.  
  741.           if (strlen($buf) > $length and $buf_o != '') {
  742.             $message .= $buf_o . $soft_break;
  743.             $buf = $word;
  744.           }
  745.         }
  746.       }
  747.       $message .= $buf . $this->LE;
  748.     }
  749.  
  750.     return $message;
  751.   }
  752.  
  753.   /**
  754.    * Finds last character boundary prior to maxLength in a utf-8
  755.    * quoted (printable) encoded string.
  756.    * Original written by Colin Brown.
  757.    * @access public
  758.    * @param string $encodedText utf-8 QP text
  759.    * @param int    $maxLength   find last character boundary prior to this length
  760.    * @return int
  761.    */
  762.   public function UTF8CharBoundary($encodedText, $maxLength) {
  763.     $foundSplitPos = false;
  764.     $lookBack = 3;
  765.     while (!$foundSplitPos) {
  766.       $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  767.       $encodedCharPos = strpos($lastChunk, "=");
  768.       if ($encodedCharPos !== false) {
  769.         // Found start of encoded character byte within $lookBack block.
  770.         // Check the encoded byte value (the 2 chars after the '=')
  771.         $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  772.         $dec = hexdec($hex);
  773.         if ($dec < 128) { // Single byte character.
  774.           // If the encoded char was found at pos 0, it will fit
  775.           // otherwise reduce maxLength to start of the encoded char
  776.           $maxLength = ($encodedCharPos == 0) ? $maxLength :
  777.           $maxLength - ($lookBack - $encodedCharPos);
  778.           $foundSplitPos = true;
  779.         } elseif ($dec >= 192) { // First byte of a multi byte character
  780.           // Reduce maxLength to split at start of character
  781.           $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  782.           $foundSplitPos = true;
  783.         } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  784.           $lookBack += 3;
  785.         }
  786.       } else {
  787.         // No encoded character found
  788.         $foundSplitPos = true;
  789.       }
  790.     }
  791.     return $maxLength;
  792.   }
  793.  
  794.  
  795.   /**
  796.    * Set the body wrapping.
  797.    * @access public
  798.    * @return void
  799.    */
  800.   public function SetWordWrap() {
  801.     if($this->WordWrap < 1) {
  802.       return;
  803.     }
  804.  
  805.     switch($this->message_type) {
  806.       case 'alt':
  807.         /* fall through */
  808.       case 'alt_attachments':
  809.         $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  810.         break;
  811.       default:
  812.         $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  813.         break;
  814.     }
  815.   }
  816.  
  817.   /**
  818.    * Assembles message header.
  819.    * @access public
  820.    * @return string
  821.    */
  822.   public function CreateHeader() {
  823.     $result = '';
  824.  
  825.     /* Set the boundaries */
  826.     $uniq_id = md5(uniqid(time()));
  827.     $this->boundary[1] = 'b1_' . $uniq_id;
  828.     $this->boundary[2] = 'b2_' . $uniq_id;
  829.  
  830.     $result .= $this->HeaderLine('Date', $this->RFCDate());
  831.     if($this->Sender == '') {
  832.       $result .= $this->HeaderLine('Return-Path', trim($this->From));
  833.     } else {
  834.       $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  835.     }
  836.  
  837.     /* To be created automatically by mail() */
  838.     if($this->Mailer != 'mail') {
  839.       if(count($this->to) > 0) {
  840.         $result .= $this->AddrAppend('To', $this->to);
  841.       } elseif (count($this->cc) == 0) {
  842.         $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  843.       }
  844.       if(count($this->cc) > 0) {
  845.         $result .= $this->AddrAppend('Cc', $this->cc);
  846.       }
  847.     }
  848.  
  849.     $from = array();
  850.     $from[0][0] = trim($this->From);
  851.     $from[0][1] = $this->FromName;
  852.     $result .= $this->AddrAppend('From', $from);
  853.  
  854.     /* sendmail and mail() extract Cc from the header before sending */
  855.     if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
  856.       $result .= $this->AddrAppend('Cc', $this->cc);
  857.     }
  858.  
  859.     /* sendmail and mail() extract Bcc from the header before sending */
  860.     if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  861.       $result .= $this->AddrAppend('Bcc', $this->bcc);
  862.     }
  863.  
  864.     if(count($this->ReplyTo) > 0) {
  865.       $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
  866.     }
  867.  
  868.     /* mail() sets the subject itself */
  869.     if($this->Mailer != 'mail') {
  870.       $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  871.     }
  872.  
  873.     if($this->MessageID != '') {
  874.       $result .= $this->HeaderLine('Message-ID',$this->MessageID);
  875.     } else {
  876.       $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  877.     }
  878.     $result .= $this->HeaderLine('X-Priority', $this->Priority);
  879.     $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.codeworxtech.com) [version ' . $this->Version . ']');
  880.  
  881.     if($this->ConfirmReadingTo != '') {
  882.       $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  883.     }
  884.  
  885.     // Add custom headers
  886.     for($index = 0; $index < count($this->CustomHeader); $index++) {
  887.       $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  888.     }
  889.     if (!$this->sign_key_file) {
  890.       $result .= $this->HeaderLine('MIME-Version', '1.0');
  891.       $result .= $this->GetMailMIME();
  892.     }
  893.  
  894.     return $result;
  895.   }
  896.  
  897.   /**
  898.    * Returns the message MIME.
  899.    * @access public
  900.    * @return string
  901.    */
  902.   public function GetMailMIME() {
  903.     $result = '';
  904.     switch($this->message_type) {
  905.       case 'plain':
  906.         $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  907.         $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
  908.         break;
  909.       case 'attachments':
  910.         /* fall through */
  911.       case 'alt_attachments':
  912.         if($this->InlineImageExists()){
  913.           $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
  914.         } else {
  915.           $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  916.           $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  917.         }
  918.         break;
  919.       case 'alt':
  920.         $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  921.         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  922.         break;
  923.     }
  924.  
  925.     if($this->Mailer != 'mail') {
  926.       $result .= $this->LE.$this->LE;
  927.     }
  928.  
  929.     return $result;
  930.   }
  931.  
  932.   /**
  933.    * Assembles the message body.  Returns an empty string on failure.
  934.    * @access public
  935.    * @return string
  936.    */
  937.   public function CreateBody() {
  938.     $result = '';
  939.  
  940.     if ($this->sign_key_file) {
  941.       $result .= $this->GetMailMIME();
  942.     }
  943.  
  944.     $this->SetWordWrap();
  945.  
  946.     switch($this->message_type) {
  947.       case 'alt':
  948.         $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  949.         $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  950.         $result .= $this->LE.$this->LE;
  951.         $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  952.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  953.         $result .= $this->LE.$this->LE;
  954.         $result .= $this->EndBoundary($this->boundary[1]);
  955.         break;
  956.       case 'plain':
  957.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  958.         break;
  959.       case 'attachments':
  960.         $result .= $this->GetBoundary($this->boundary[1], '', '', '');
  961.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  962.         $result .= $this->LE;
  963.         $result .= $this->AttachAll();
  964.         break;
  965.       case 'alt_attachments':
  966.         $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  967.         $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
  968.         $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
  969.         $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  970.         $result .= $this->LE.$this->LE;
  971.         $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
  972.         $result .= $this->EncodeString($this->Body, $this->Encoding);
  973.         $result .= $this->LE.$this->LE;
  974.         $result .= $this->EndBoundary($this->boundary[2]);
  975.         $result .= $this->AttachAll();
  976.         break;
  977.     }
  978.  
  979.     if($this->IsError()) {
  980.       $result = '';
  981.     } else if ($this->sign_key_file) {
  982.       $file = tempnam("", "mail");
  983.       $fp = fopen($file, "w");
  984.       fwrite($fp, $result);
  985.       fclose($fp);
  986.       $signed = tempnam("", "signed");
  987.  
  988.       if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
  989.         $fp = fopen($signed, "r");
  990.         $result = '';
  991.         while(!feof($fp)){
  992.           $result = $result . fread($fp, 1024);
  993.         }
  994.         fclose($fp);
  995.       } else {
  996.         $this->SetError($this->Lang("signing").openssl_error_string());
  997.         $result = '';
  998.       }
  999.  
  1000.       unlink($file);
  1001.       unlink($signed);
  1002.     }
  1003.  
  1004.     return $result;
  1005.   }
  1006.  
  1007.   /**
  1008.    * Returns the start of a message boundary.
  1009.    * @access public
  1010.    */
  1011.   public function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  1012.     $result = '';
  1013.     if($charSet == '') {
  1014.       $charSet = $this->CharSet;
  1015.     }
  1016.     if($contentType == '') {
  1017.       $contentType = $this->ContentType;
  1018.     }
  1019.     if($encoding == '') {
  1020.       $encoding = $this->Encoding;
  1021.     }
  1022.     $result .= $this->TextLine('--' . $boundary);
  1023.     $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
  1024.     $result .= $this->LE;
  1025.     $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  1026.     $result .= $this->LE;
  1027.  
  1028.     return $result;
  1029.   }
  1030.  
  1031.   /**
  1032.    * Returns the end of a message boundary.
  1033.    * @access public
  1034.    */
  1035.   public function EndBoundary($boundary) {
  1036.     return $this->LE . '--' . $boundary . '--' . $this->LE;
  1037.   }
  1038.  
  1039.   /**
  1040.    * Sets the message type.
  1041.    * @access public
  1042.    * @return void
  1043.    */
  1044.   public function SetMessageType() {
  1045.     if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
  1046.       $this->message_type = 'plain';
  1047.     } else {
  1048.       if(count($this->attachment) > 0) {
  1049.         $this->message_type = 'attachments';
  1050.       }
  1051.       if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
  1052.         $this->message_type = 'alt';
  1053.       }
  1054.       if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
  1055.         $this->message_type = 'alt_attachments';
  1056.       }
  1057.     }
  1058.   }
  1059.  
  1060.   /* Returns a formatted header line.
  1061.    * @access public
  1062.    * @return string
  1063.    */
  1064.   public function HeaderLine($name, $value) {
  1065.     return $name . ': ' . $value . $this->LE;
  1066.   }
  1067.  
  1068.   /**
  1069.    * Returns a formatted mail line.
  1070.    * @access public
  1071.    * @return string
  1072.    */
  1073.   public function TextLine($value) {
  1074.     return $value . $this->LE;
  1075.   }
  1076.  
  1077.   /////////////////////////////////////////////////
  1078.   // CLASS METHODS, ATTACHMENTS
  1079.   /////////////////////////////////////////////////
  1080.  
  1081.   /**
  1082.    * Adds an attachment from a path on the filesystem.
  1083.    * Returns false if the file could not be found
  1084.    * or accessed.
  1085.    * @param string $path Path to the attachment.
  1086.    * @param string $name Overrides the attachment name.
  1087.    * @param string $encoding File encoding (see $Encoding).
  1088.    * @param string $type File extension (MIME) type.
  1089.    * @return bool
  1090.    */
  1091.   public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1092.     if(!@is_file($path)) {
  1093.       $this->SetError($this->Lang('file_access') . $path);
  1094.       return false;
  1095.     }
  1096.  
  1097.     $filename = basename($path);
  1098.     if($name == '') {
  1099.       $name = $filename;
  1100.     }
  1101.  
  1102.     $cur = count($this->attachment);
  1103.     $this->attachment[$cur][0] = $path;
  1104.     $this->attachment[$cur][1] = $filename;
  1105.     $this->attachment[$cur][2] = $name;
  1106.     $this->attachment[$cur][3] = $encoding;
  1107.     $this->attachment[$cur][4] = $type;
  1108.     $this->attachment[$cur][5] = false; // isStringAttachment
  1109.     $this->attachment[$cur][6] = 'attachment';
  1110.     $this->attachment[$cur][7] = 0;
  1111.  
  1112.     return true;
  1113.   }
  1114.  
  1115.   /**
  1116.    * Attaches all fs, string, and binary attachments to the message.
  1117.    * Returns an empty string on failure.
  1118.    * @access public
  1119.    * @return string
  1120.    */
  1121.   public function AttachAll() {
  1122.     /* Return text of body */
  1123.     $mime = array();
  1124.  
  1125.     /* Add all attachments */
  1126.     for($i = 0; $i < count($this->attachment); $i++) {
  1127.       /* Check for string attachment */
  1128.       $bString = $this->attachment[$i][5];
  1129.       if ($bString) {
  1130.         $string = $this->attachment[$i][0];
  1131.       } else {
  1132.         $path = $this->attachment[$i][0];
  1133.       }
  1134.  
  1135.       $filename    = $this->attachment[$i][1];
  1136.       $name        = $this->attachment[$i][2];
  1137.       $encoding    = $this->attachment[$i][3];
  1138.       $type        = $this->attachment[$i][4];
  1139.       $disposition = $this->attachment[$i][6];
  1140.       $cid         = $this->attachment[$i][7];
  1141.  
  1142.       $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  1143.       //$mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  1144.       $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
  1145.       $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  1146.  
  1147.       if($disposition == 'inline') {
  1148.         $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  1149.       }
  1150.  
  1151.       //$mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
  1152.       $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
  1153.  
  1154.       /* Encode as string attachment */
  1155.       if($bString) {
  1156.         $mime[] = $this->EncodeString($string, $encoding);
  1157.         if($this->IsError()) {
  1158.           return '';
  1159.         }
  1160.         $mime[] = $this->LE.$this->LE;
  1161.       } else {
  1162.         $mime[] = $this->EncodeFile($path, $encoding);
  1163.         if($this->IsError()) {
  1164.           return '';
  1165.         }
  1166.         $mime[] = $this->LE.$this->LE;
  1167.       }
  1168.     }
  1169.  
  1170.     $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  1171.  
  1172.     return join('', $mime);
  1173.   }
  1174.  
  1175.   /**
  1176.    * Encodes attachment in requested format.  Returns an
  1177.    * empty string on failure.
  1178.    * @access public
  1179.    * @return string
  1180.    */
  1181.   public function EncodeFile ($path, $encoding = 'base64') {
  1182.     if(!@$fd = fopen($path, 'rb')) {
  1183.       $this->SetError($this->Lang('file_open') . $path);
  1184.       return '';
  1185.     }
  1186.     if (function_exists('get_magic_quotes')) {
  1187.         function get_magic_quotes() {
  1188.             return false;
  1189.         }
  1190. }
  1191.     if (PHP_VERSION < 6) {
  1192.       $magic_quotes = get_magic_quotes_runtime();
  1193.       set_magic_quotes_runtime(0);
  1194.     }
  1195.     $file_buffer  = file_get_contents($path);
  1196.     $file_buffer  = $this->EncodeString($file_buffer, $encoding);
  1197.     fclose($fd);
  1198.     if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
  1199.     return $file_buffer;
  1200.   }
  1201.  
  1202.   /**
  1203.    * Encodes string to requested format. Returns an
  1204.    * empty string on failure.
  1205.    * @access public
  1206.    * @return string
  1207.    */
  1208.   public function EncodeString ($str, $encoding = 'base64') {
  1209.     $encoded = '';
  1210.     switch(strtolower($encoding)) {
  1211.       case 'base64':
  1212.         $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1213.         break;
  1214.       case '7bit':
  1215.       case '8bit':
  1216.         $encoded = $this->FixEOL($str);
  1217.         if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1218.           $encoded .= $this->LE;
  1219.         break;
  1220.       case 'binary':
  1221.         $encoded = $str;
  1222.         break;
  1223.       case 'quoted-printable':
  1224.         $encoded = $this->EncodeQP($str);
  1225.         break;
  1226.       default:
  1227.         $this->SetError($this->Lang('encoding') . $encoding);
  1228.         break;
  1229.     }
  1230.     return $encoded;
  1231.   }
  1232.  
  1233.   /**
  1234.    * Encode a header string to best of Q, B, quoted or none.
  1235.    * @access public
  1236.    * @return string
  1237.    */
  1238.   public function EncodeHeader ($str, $position = 'text') {
  1239.     $x = 0;
  1240.  
  1241.     switch (strtolower($position)) {
  1242.       case 'phrase':
  1243.         if (!preg_match('/[\200-\377]/', $str)) {
  1244.           /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
  1245.           $encoded = addcslashes($str, "\0..\37\177\\\"");
  1246.           if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  1247.             return ($encoded);
  1248.           } else {
  1249.             return ("\"$encoded\"");
  1250.           }
  1251.         }
  1252.         $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1253.         break;
  1254.       case 'comment':
  1255.         $x = preg_match_all('/[()"]/', $str, $matches);
  1256.         /* Fall-through */
  1257.       case 'text':
  1258.       default:
  1259.         $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1260.         break;
  1261.     }
  1262.  
  1263.     if ($x == 0) {
  1264.       return ($str);
  1265.     }
  1266.  
  1267.     $maxlen = 75 - 7 - strlen($this->CharSet);
  1268.     /* Try to select the encoding which should produce the shortest output */
  1269.     if (strlen($str)/3 < $x) {
  1270.       $encoding = 'B';
  1271.       if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
  1272.      // Use a custom function which correctly encodes and wraps long
  1273.      // multibyte strings without breaking lines within a character
  1274.         $encoded = $this->Base64EncodeWrapMB($str);
  1275.       } else {
  1276.         $encoded = base64_encode($str);
  1277.         $maxlen -= $maxlen % 4;
  1278.         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1279.       }
  1280.     } else {
  1281.       $encoding = 'Q';
  1282.       $encoded = $this->EncodeQ($str, $position);
  1283.       $encoded = $this->WrapText($encoded, $maxlen, true);
  1284.       $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
  1285.     }
  1286.  
  1287.     $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1288.     $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1289.  
  1290.     return $encoded;
  1291.   }
  1292.  
  1293.   /**
  1294.    * Checks if a string contains multibyte characters.
  1295.    * @access public
  1296.    * @param string $str multi-byte text to wrap encode
  1297.    * @return bool
  1298.    */
  1299.   public function HasMultiBytes($str) {
  1300.     if (function_exists('mb_strlen')) {
  1301.       return (strlen($str) > mb_strlen($str, $this->CharSet));
  1302.     } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  1303.       return False;
  1304.     }
  1305.   }
  1306.  
  1307.   /**
  1308.    * Correctly encodes and wraps long multibyte strings for mail headers
  1309.    * without breaking lines within a character.
  1310.    * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
  1311.    * @access public
  1312.    * @param string $str multi-byte text to wrap encode
  1313.    * @return string
  1314.    */
  1315.   public function Base64EncodeWrapMB($str) {
  1316.     $start = "=?".$this->CharSet."?B?";
  1317.     $end = "?=";
  1318.     $encoded = "";
  1319.  
  1320.     $mb_length = mb_strlen($str, $this->CharSet);
  1321.     // Each line must have length <= 75, including $start and $end
  1322.     $length = 75 - strlen($start) - strlen($end);
  1323.     // Average multi-byte ratio
  1324.     $ratio = $mb_length / strlen($str);
  1325.     // Base64 has a 4:3 ratio
  1326.     $offset = $avgLength = floor($length * $ratio * .75);
  1327.  
  1328.     for ($i = 0; $i < $mb_length; $i += $offset) {
  1329.       $lookBack = 0;
  1330.  
  1331.       do {
  1332.         $offset = $avgLength - $lookBack;
  1333.         $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  1334.         $chunk = base64_encode($chunk);
  1335.         $lookBack++;
  1336.       }
  1337.       while (strlen($chunk) > $length);
  1338.  
  1339.       $encoded .= $chunk . $this->LE;
  1340.     }
  1341.  
  1342.     // Chomp the last linefeed
  1343.     $encoded = substr($encoded, 0, -strlen($this->LE));
  1344.     return $encoded;
  1345.   }
  1346.  
  1347.   /**
  1348.   * Encode string to quoted-printable.
  1349.   * @access public
  1350.   * @param string $string the text to encode
  1351.   * @param integer $line_max Number of chars allowed on a line before wrapping
  1352.   * @return string
  1353.   */
  1354.   public function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
  1355.     $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  1356.     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
  1357.     $eol = "\r\n";
  1358.     $escape = '=';
  1359.     $output = '';
  1360.     while( list(, $line) = each($lines) ) {
  1361.       $linlen = strlen($line);
  1362.       $newline = '';
  1363.       for($i = 0; $i < $linlen; $i++) {
  1364.         $c = substr( $line, $i, 1 );
  1365.         $dec = ord( $c );
  1366.         if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
  1367.           $c = '=2E';
  1368.         }
  1369.         if ( $dec == 32 ) {
  1370.           if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
  1371.             $c = '=20';
  1372.           } else if ( $space_conv ) {
  1373.             $c = '=20';
  1374.           }
  1375.         } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
  1376.           $h2 = floor($dec/16);
  1377.           $h1 = floor($dec%16);
  1378.           $c = $escape.$hex[$h2].$hex[$h1];
  1379.         }
  1380.         if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
  1381.           $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
  1382.           $newline = '';
  1383.           // check if newline first character will be point or not
  1384.           if ( $dec == 46 ) {
  1385.             $c = '=2E';
  1386.           }
  1387.         }
  1388.         $newline .= $c;
  1389.       } // end of for
  1390.       $output .= $newline.$eol;
  1391.     } // end of while
  1392.     return trim($output);
  1393.   }
  1394.  
  1395.   /**
  1396.    * Encode string to q encoding.
  1397.    * @access public
  1398.    * @return string
  1399.    */
  1400.   public function EncodeQ ($str, $position = 'text') {
  1401.     /* There should not be any EOL in the string */
  1402.     $encoded = preg_replace("[\r\n]", '', $str);
  1403.  
  1404.     switch (strtolower($position)) {
  1405.       case 'phrase':
  1406.         $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1407.         break;
  1408.       case 'comment':
  1409.         $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1410.       case 'text':
  1411.       default:
  1412.         /* Replace every high ascii, control =, ? and _ characters */
  1413.         $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1414.               "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1415.         break;
  1416.     }
  1417.  
  1418.     /* Replace every spaces to _ (more readable than =20) */
  1419.     $encoded = str_replace(' ', '_', $encoded);
  1420.  
  1421.     return $encoded;
  1422.   }
  1423.  
  1424.   /**
  1425.    * Adds a string or binary attachment (non-filesystem) to the list.
  1426.    * This method can be used to attach ascii or binary data,
  1427.    * such as a BLOB record from a database.
  1428.    * @param string $string String attachment data.
  1429.    * @param string $filename Name of the attachment.
  1430.    * @param string $encoding File encoding (see $Encoding).
  1431.    * @param string $type File extension (MIME) type.
  1432.    * @return void
  1433.    */
  1434.   public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  1435.     /* Append to $attachment array */
  1436.     $cur = count($this->attachment);
  1437.     $this->attachment[$cur][0] = $string;
  1438.     $this->attachment[$cur][1] = $filename;
  1439.     $this->attachment[$cur][2] = $filename;
  1440.     $this->attachment[$cur][3] = $encoding;
  1441.     $this->attachment[$cur][4] = $type;
  1442.     $this->attachment[$cur][5] = true; // isString
  1443.     $this->attachment[$cur][6] = 'attachment';
  1444.     $this->attachment[$cur][7] = 0;
  1445.   }
  1446.  
  1447.   /**
  1448.    * Adds an embedded attachment.  This can include images, sounds, and
  1449.    * just about any other document.  Make sure to set the $type to an
  1450.    * image type.  For JPEG images use "image/jpeg" and for GIF images
  1451.    * use "image/gif".
  1452.    * @param string $path Path to the attachment.
  1453.    * @param string $cid Content ID of the attachment.  Use this to identify
  1454.    *        the Id for accessing the image in an HTML form.
  1455.    * @param string $name Overrides the attachment name.
  1456.    * @param string $encoding File encoding (see $Encoding).
  1457.    * @param string $type File extension (MIME) type.
  1458.    * @return bool
  1459.    */
  1460.   public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1461.  
  1462.     if(!@is_file($path)) {
  1463.       $this->SetError($this->Lang('file_access') . $path);
  1464.       return false;
  1465.     }
  1466.  
  1467.     $filename = basename($path);
  1468.     if($name == '') {
  1469.       $name = $filename;
  1470.     }
  1471.  
  1472.     /* Append to $attachment array */
  1473.     $cur = count($this->attachment);
  1474.     $this->attachment[$cur][0] = $path;
  1475.     $this->attachment[$cur][1] = $filename;
  1476.     $this->attachment[$cur][2] = $name;
  1477.     $this->attachment[$cur][3] = $encoding;
  1478.     $this->attachment[$cur][4] = $type;
  1479.     $this->attachment[$cur][5] = false;
  1480.     $this->attachment[$cur][6] = 'inline';
  1481.     $this->attachment[$cur][7] = $cid;
  1482.  
  1483.     return true;
  1484.   }
  1485.  
  1486.   /**
  1487.    * Returns true if an inline attachment is present.
  1488.    * @access public
  1489.    * @return bool
  1490.    */
  1491.   public function InlineImageExists() {
  1492.     $result = false;
  1493.     for($i = 0; $i < count($this->attachment); $i++) {
  1494.       if($this->attachment[$i][6] == 'inline') {
  1495.         $result = true;
  1496.         break;
  1497.       }
  1498.     }
  1499.  
  1500.     return $result;
  1501.   }
  1502.  
  1503.   /////////////////////////////////////////////////
  1504.   // CLASS METHODS, MESSAGE RESET
  1505.   /////////////////////////////////////////////////
  1506.  
  1507.   /**
  1508.    * Clears all recipients assigned in the TO array.  Returns void.
  1509.    * @return void
  1510.    */
  1511.   public function ClearAddresses() {
  1512.     $this->to = array();
  1513.   }
  1514.  
  1515.   /**
  1516.    * Clears all recipients assigned in the CC array.  Returns void.
  1517.    * @return void
  1518.    */
  1519.   public function ClearCCs() {
  1520.     $this->cc = array();
  1521.   }
  1522.  
  1523.   /**
  1524.    * Clears all recipients assigned in the BCC array.  Returns void.
  1525.    * @return void
  1526.    */
  1527.   public function ClearBCCs() {
  1528.     $this->bcc = array();
  1529.   }
  1530.  
  1531.   /**
  1532.    * Clears all recipients assigned in the ReplyTo array.  Returns void.
  1533.    * @return void
  1534.    */
  1535.   public function ClearReplyTos() {
  1536.     $this->ReplyTo = array();
  1537.   }
  1538.  
  1539.   /**
  1540.    * Clears all recipients assigned in the TO, CC and BCC
  1541.    * array.  Returns void.
  1542.    * @return void
  1543.    */
  1544.   public function ClearAllRecipients() {
  1545.     $this->to = array();
  1546.     $this->cc = array();
  1547.     $this->bcc = array();
  1548.   }
  1549.  
  1550.   /**
  1551.    * Clears all previously set filesystem, string, and binary
  1552.    * attachments.  Returns void.
  1553.    * @return void
  1554.    */
  1555.   public function ClearAttachments() {
  1556.     $this->attachment = array();
  1557.   }
  1558.  
  1559.   /**
  1560.    * Clears all custom headers.  Returns void.
  1561.    * @return void
  1562.    */
  1563.   public function ClearCustomHeaders() {
  1564.     $this->CustomHeader = array();
  1565.   }
  1566.  
  1567.   /////////////////////////////////////////////////
  1568.   // CLASS METHODS, MISCELLANEOUS
  1569.   /////////////////////////////////////////////////
  1570.  
  1571.   /**
  1572.    * Adds the error message to the error container.
  1573.    * Returns void.
  1574.    * @access private
  1575.    * @return void
  1576.    */
  1577.   private function SetError($msg) {
  1578.     $this->error_count++;
  1579.     $this->ErrorInfo = $msg;
  1580.   }
  1581.  
  1582.   /**
  1583.    * Returns the proper RFC 822 formatted date.
  1584.    * @access private
  1585.    * @return string
  1586.    */
  1587.   private static function RFCDate() {
  1588.     $tz = date('Z');
  1589.     $tzs = ($tz < 0) ? '-' : '+';
  1590.     $tz = abs($tz);
  1591.     $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  1592.     $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  1593.  
  1594.     return $result;
  1595.   }
  1596.  
  1597.   /**
  1598.    * Returns the server hostname or 'localhost.localdomain' if unknown.
  1599.    * @access private
  1600.    * @return string
  1601.    */
  1602.   private function ServerHostname() {
  1603.     if (!empty($this->Hostname)) {
  1604.       $result = $this->Hostname;
  1605.     } elseif (isset($_SERVER['SERVER_NAME'])) {
  1606.       $result = $_SERVER['SERVER_NAME'];
  1607.     } else {
  1608.       $result = "localhost.localdomain";
  1609.     }
  1610.  
  1611.     return $result;
  1612.   }
  1613.  
  1614.   /**
  1615.    * Returns a message in the appropriate language.
  1616.    * @access private
  1617.    * @return string
  1618.    */
  1619.   private function Lang($key) {
  1620.     if(count($this->language) < 1) {
  1621.       $this->SetLanguage('en'); // set the default language
  1622.     }
  1623.  
  1624.     if(isset($this->language[$key])) {
  1625.       return $this->language[$key];
  1626.     } else {
  1627.       return 'Language string failed to load: ' . $key;
  1628.     }
  1629.   }
  1630.  
  1631.   /**
  1632.    * Returns true if an error occurred.
  1633.    * @access public
  1634.    * @return bool
  1635.    */
  1636.   public function IsError() {
  1637.     return ($this->error_count > 0);
  1638.   }
  1639.  
  1640.   /**
  1641.    * Changes every end of line from CR or LF to CRLF.
  1642.    * @access private
  1643.    * @return string
  1644.    */
  1645.   private function FixEOL($str) {
  1646.     $str = str_replace("\r\n", "\n", $str);
  1647.     $str = str_replace("\r", "\n", $str);
  1648.     $str = str_replace("\n", $this->LE, $str);
  1649.     return $str;
  1650.   }
  1651.  
  1652.   /**
  1653.    * Adds a custom header.
  1654.    * @access public
  1655.    * @return void
  1656.    */
  1657.   public function AddCustomHeader($custom_header) {
  1658.     $this->CustomHeader[] = explode(':', $custom_header, 2);
  1659.   }
  1660.  
  1661.   /**
  1662.    * Evaluates the message and returns modifications for inline images and backgrounds
  1663.    * @access public
  1664.    * @return $message
  1665.    */
  1666.   public function MsgHTML($message,$basedir='') {
  1667.     preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  1668.     if(isset($images[2])) {
  1669.       foreach($images[2] as $i => $url) {
  1670.         // do not change urls for absolute images (thanks to corvuscorax)
  1671.         if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
  1672.           $filename = basename($url);
  1673.           $directory = dirname($url);
  1674.           ($directory == '.')?$directory='':'';
  1675.           $cid = 'cid:' . md5($filename);
  1676.           $fileParts = split("\.", $filename);
  1677.           $ext = $fileParts[1];
  1678.           $mimeType = $this->_mime_types($ext);
  1679.           if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
  1680.           if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
  1681.           $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
  1682.           if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
  1683.             $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  1684.           }
  1685.         }
  1686.       }
  1687.     }
  1688.     $this->IsHTML(true);
  1689.     $this->Body = $message;
  1690.     $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
  1691.     if ( !empty($textMsg) && empty($this->AltBody) ) {
  1692.       $this->AltBody = $textMsg;
  1693.     }
  1694.     if ( empty($this->AltBody) ) {
  1695.       $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
  1696.     }
  1697.   }
  1698.  
  1699.   /**
  1700.    * Gets the mime type of the embedded or inline image
  1701.    * @access public
  1702.    * @return mime type of ext
  1703.    */
  1704.   public function _mime_types($ext = '') {
  1705.     $mimes = array(
  1706.       'hqx'   =>  'application/mac-binhex40',
  1707.       'cpt'   =>  'application/mac-compactpro',
  1708.       'doc'   =>  'application/msword',
  1709.       'bin'   =>  'application/macbinary',
  1710.       'dms'   =>  'application/octet-stream',
  1711.       'lha'   =>  'application/octet-stream',
  1712.       'lzh'   =>  'application/octet-stream',
  1713.       'exe'   =>  'application/octet-stream',
  1714.       'class' =>  'application/octet-stream',
  1715.       'psd'   =>  'application/octet-stream',
  1716.       'so'    =>  'application/octet-stream',
  1717.       'sea'   =>  'application/octet-stream',
  1718.       'dll'   =>  'application/octet-stream',
  1719.       'oda'   =>  'application/oda',
  1720.       'pdf'   =>  'application/pdf',
  1721.       'ai'    =>  'application/postscript',
  1722.       'eps'   =>  'application/postscript',
  1723.       'ps'    =>  'application/postscript',
  1724.       'smi'   =>  'application/smil',
  1725.       'smil'  =>  'application/smil',
  1726.       'mif'   =>  'application/vnd.mif',
  1727.       'xls'   =>  'application/vnd.ms-excel',
  1728.       'ppt'   =>  'application/vnd.ms-powerpoint',
  1729.       'wbxml' =>  'application/vnd.wap.wbxml',
  1730.       'wmlc'  =>  'application/vnd.wap.wmlc',
  1731.       'dcr'   =>  'application/x-director',
  1732.       'dir'   =>  'application/x-director',
  1733.       'dxr'   =>  'application/x-director',
  1734.       'dvi'   =>  'application/x-dvi',
  1735.       'gtar'  =>  'application/x-gtar',
  1736.       'php'   =>  'application/x-httpd-php',
  1737.       'php4'  =>  'application/x-httpd-php',
  1738.       'php3'  =>  'application/x-httpd-php',
  1739.       'phtml' =>  'application/x-httpd-php',
  1740.       'phps'  =>  'application/x-httpd-php-source',
  1741.       'js'    =>  'application/x-javascript',
  1742.       'swf'   =>  'application/x-shockwave-flash',
  1743.       'sit'   =>  'application/x-stuffit',
  1744.       'tar'   =>  'application/x-tar',
  1745.       'tgz'   =>  'application/x-tar',
  1746.       'xhtml' =>  'application/xhtml+xml',
  1747.       'xht'   =>  'application/xhtml+xml',
  1748.       'zip'   =>  'application/zip',
  1749.       'mid'   =>  'audio/midi',
  1750.       'midi'  =>  'audio/midi',
  1751.       'mpga'  =>  'audio/mpeg',
  1752.       'mp2'   =>  'audio/mpeg',
  1753.       'mp3'   =>  'audio/mpeg',
  1754.       'aif'   =>  'audio/x-aiff',
  1755.       'aiff'  =>  'audio/x-aiff',
  1756.       'aifc'  =>  'audio/x-aiff',
  1757.       'ram'   =>  'audio/x-pn-realaudio',
  1758.       'rm'    =>  'audio/x-pn-realaudio',
  1759.       'rpm'   =>  'audio/x-pn-realaudio-plugin',
  1760.       'ra'    =>  'audio/x-realaudio',
  1761.       'rv'    =>  'video/vnd.rn-realvideo',
  1762.       'wav'   =>  'audio/x-wav',
  1763.       'bmp'   =>  'image/bmp',
  1764.       'gif'   =>  'image/gif',
  1765.       'jpeg'  =>  'image/jpeg',
  1766.       'jpg'   =>  'image/jpeg',
  1767.       'jpe'   =>  'image/jpeg',
  1768.       'png'   =>  'image/png',
  1769.       'tiff'  =>  'image/tiff',
  1770.       'tif'   =>  'image/tiff',
  1771.       'css'   =>  'text/css',
  1772.       'html'  =>  'text/html',
  1773.       'htm'   =>  'text/html',
  1774.       'shtml' =>  'text/html',
  1775.       'txt'   =>  'text/plain',
  1776.       'text'  =>  'text/plain',
  1777.       'log'   =>  'text/plain',
  1778.       'rtx'   =>  'text/richtext',
  1779.       'rtf'   =>  'text/rtf',
  1780.       'xml'   =>  'text/xml',
  1781.       'xsl'   =>  'text/xml',
  1782.       'mpeg'  =>  'video/mpeg',
  1783.       'mpg'   =>  'video/mpeg',
  1784.       'mpe'   =>  'video/mpeg',
  1785.       'qt'    =>  'video/quicktime',
  1786.       'mov'   =>  'video/quicktime',
  1787.       'avi'   =>  'video/x-msvideo',
  1788.       'movie' =>  'video/x-sgi-movie',
  1789.       'doc'   =>  'application/msword',
  1790.       'word'  =>  'application/msword',
  1791.       'xl'    =>  'application/excel',
  1792.       'eml'   =>  'message/rfc822'
  1793.     );
  1794.     return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
  1795.   }
  1796.  
  1797.   /**
  1798.    * Set (or reset) Class Objects (variables)
  1799.    *
  1800.    * Usage Example:
  1801.    * $page->set('X-Priority', '3');
  1802.    *
  1803.    * @access public
  1804.    * @param string $name Parameter Name
  1805.    * @param mixed $value Parameter Value
  1806.    * NOTE: will not work with arrays, there are no arrays to set/reset
  1807.    */
  1808.   public function set ( $name, $value = '' ) {
  1809.     if ( isset($this->$name) ) {
  1810.       $this->$name = $value;
  1811.     } else {
  1812.       $this->SetError('Cannot set or reset variable ' . $name);
  1813.       return false;
  1814.     }
  1815.   }
  1816.  
  1817.   /**
  1818.    * Read a file from a supplied filename and return it.
  1819.    *
  1820.    * @access public
  1821.    * @param string $filename Parameter File Name
  1822.    */
  1823.   public function getFile($filename) {
  1824.     $return = '';
  1825.     if ($fp = fopen($filename, 'rb')) {
  1826.       while (!feof($fp)) {
  1827.         $return .= fread($fp, 1024);
  1828.       }
  1829.       fclose($fp);
  1830.       return $return;
  1831.     } else {
  1832.       return false;
  1833.     }
  1834.   }
  1835.  
  1836.   /**
  1837.    * Strips newlines to prevent header injection.
  1838.    * @access public
  1839.    * @param string $str String
  1840.    * @return string
  1841.    */
  1842.   public function SecureHeader($str) {
  1843.     $str = trim($str);
  1844.     $str = str_replace("\r", "", $str);
  1845.     $str = str_replace("\n", "", $str);
  1846.     return $str;
  1847.   }
  1848.  
  1849.   /**
  1850.    * Set the private key file and password to sign the message.
  1851.    *
  1852.    * @access public
  1853.    * @param string $key_filename Parameter File Name
  1854.    * @param string $key_pass Password for private key
  1855.    */
  1856.   public function Sign($cert_filename, $key_filename, $key_pass) {
  1857.     $this->sign_cert_file = $cert_filename;
  1858.     $this->sign_key_file = $key_filename;
  1859.     $this->sign_key_pass = $key_pass;
  1860.   }
  1861. }
  1862.  
Jul 6 '10 #1
4 4786
you changed my title but i think it may be worse, i cant get my phone number to post via email please help.
Jul 6 '10 #2
zorgi
431 Expert 256MB
You didn't give us any idea of any errors but I think I found problem in your sendEmail.php

Expand|Select|Wrap|Line Numbers
  1.    $mail->Body = $phone;
  2.    $mail->Body = $comments;
  3.  
You basically assign variable $phone to class property Body and than overwrite it with variable $comments. It as this:

Expand|Select|Wrap|Line Numbers
  1. $a = "My name is ";
  2. $a = "Zorgi";
  3. echo $a; // echoes "Zorgi"
  4.  
But if you do this:

Expand|Select|Wrap|Line Numbers
  1. $a = "My name is ";
  2. $a .= "Zorgi";
  3. echo $a; // this echoes "My name is Zorgi"
  4.  
Hope this helps
Jul 6 '10 #3
i didnt get any errors, i just couldnt seem to get the phone number in the email in a suitable place. i understand what your saying i will try it out i think that should work.. thank you.
Jul 6 '10 #4
zorgi
431 Expert 256MB
@luke noob
Let us know if it worked and you welcome :)
Jul 6 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by John | last post: by
reply views Thread by kammaldeep | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.