Avatar billede Slettet bruger
23. juni 2003 - 15:56 Der er 62 kommentarer og
1 løsning

Attachment virker ikke i formmail

Hej jeg er igang med at lave en fommail, og den virker også ok for det meste, jeg kan bare ikke få min attachment til at virke, hvad skal jeg gøre for at få den til det?

kontakt.php
-------------------------

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<div align="center">
  <center>
<table border="1" width="350" height="350" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0">
  <tr>
    <td height="213" valign="top" bgcolor="#C0C0C0"> <form action="<?php echo $PHP_SELF; ?> " method="POST">
        </form>
        <div align="center"><b><font face="Verdana" size="1"><br>
          </font><font color="#FFFFFF" size="2" face="Arial">Dit navn:<br>
          </font>
          </b>
          <input type="text" class="but" name="navn" size="20">
          <br>
          <font face="Verdana" size="1"><br>
          </font>
          <font face="Arial"><b>
          <font color="#FFFFFF" size="2">Din email adresse:</font></b></font><b><font color="#FFFFFF" size="2" face="Arial"><br>
          </font></b>
          <input type="text" class="but" name="epost" size="20">
          <br>
          <font color="#00FF00" size="1" face="Verdana">
          <br>
          </font><b><font color="#FFFFFF" size="2" face="Arial">
          Besked:<br>
          </font></b><font color="#00FF00" size="1" face="Verdana">
          <textarea wrap="on" class="but" rows="10" cols="40" name="tekst"></textarea>
          <br>
          <br>

          </font><font color="#FFFFFF" size="1" face="Verdana">

Attachments <br>
          </font><font color="#00FF00" size="1" face="Verdana">
<input type="file" name="attachment" size="20"></font></div>
        <div align="center">&nbsp;</div>
        <div align="center"><font color="#00FF00" size="1" face="Verdana">
          &nbsp;<input type="submit" class="button" value="Send Besked" name="send">
          <font color="#011B35">__</font>
          <input type="reset" class="button" value="Slet Besked" name="reset">
          <br>
          <br>
          <font color="ffffff" size="1" face="Verdana">
          <?php

if ($send) {
    function tilbage($meddelelse) {
        echo  "$meddelelse\n";
        echo  "<form><input type=button value=\"<<< Tilbage\" onClick=history.back()></form>\n";
        echo  "</body></html>\n";
        exit;
    }

    if (!$navn) tilbage( "<BR><BR>Du har glemt at skrive dit navn...");
    if (!$tekst) tilbage( "Du har glemt at skrive noget beskedfeltet");
 
  $tekst = "$tekst ";
   
 
    mail( "jesper_christophersen@hotmail.com", "Tilmeldning - navn: $navn", $tekst, "From: $epost\nX-Mailer: http://$HTTP_HOST$REQUEST_URI");
echo  "Vi har modtaget din Tilmeldning\n";
}


?>
        </font> </div>
    </form></td>
  </tr>
</table>
</center>
</div>
</body>
</html>


kontakt_sendt.php
---------

<html>
<head>
<title>Besked sendt!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<? mail("privat@thomaslunde.dk", "Mail fra thomaslunde.dk - Emne: $emne", 
" 
Navn:
$navn 

Email:
$email 

Besked:
$skriv"); ?>
</body>
</html>
Avatar billede hoejrup Nybegynder
23. juni 2003 - 16:00 #1
Hvad skal der sendes med din mail?

/per
Avatar billede Slettet bruger
23. juni 2003 - 16:00 #2
billeder
Avatar billede hoejrup Nybegynder
23. juni 2003 - 16:01 #3
Du kan ikke attache billeder til en mail på den måde!

/per
Avatar billede Slettet bruger
23. juni 2003 - 16:02 #4
nej okay, men kan man slet ikke få sendt et billede med en formmail som denne?
Avatar billede hoejrup Nybegynder
23. juni 2003 - 16:11 #5
Selvfølgelig kan du sende billeder, men det er lidt mere kompliceret sag.

Eks. http://www.webmasterworld.com/forum88/1080.htm

/per
Avatar billede Slettet bruger
23. juni 2003 - 16:17 #6
nu er jeg ikke verdens bedste til php, jeg fatter faktisk hat af det, kunne du give et eksempel på hvordan jeg skal sætte den php kode ind i min? altså kun hvis du har tid/lyst
Avatar billede hoejrup Nybegynder
23. juni 2003 - 16:19 #7
Du kan også sende billederne via et færdigt php program.

Eks. http://phpmailer.sourceforge.net/

/per
Avatar billede Slettet bruger
23. juni 2003 - 16:21 #8
takker, kigger jeg på
Avatar billede hoejrup Nybegynder
23. juni 2003 - 16:33 #9
Du kan læse alt om attachment af uploaded filer her: http://php4you.kiev.ua/docs/print/php_attach.html

/per
Avatar billede hoejrup Nybegynder
23. juni 2003 - 16:36 #10
Velbekomme! :-)

Du bør læse det sidste link, hvor du næsten kan klippe koden ud.

/per
Avatar billede Slettet bruger
23. juni 2003 - 17:07 #11
lol lige meget hvor meget jeg kigger på det så er det bare sort for mig.
Avatar billede hoejrup Nybegynder
23. juni 2003 - 18:00 #12
Sort?

Du skal bare kopiere den sidste <?php ?> nederst på siden i linket: http://php4you.kiev.ua/docs/print/php_attach.html, og derefter rette det til din form.

/per
Avatar billede Slettet bruger
23. juni 2003 - 23:38 #13
Tak nu virker det!
Ja det var faktisk ik så indviklet inda.

Jesper
Avatar billede hoejrup Nybegynder
24. juni 2003 - 00:36 #14
Velbekomme! Det er faktisk let, men det tager lidt tid at flette det sammen. :-)

/per
Avatar billede Slettet bruger
24. juni 2003 - 00:48 #15
der var lige en ting som jeg gerne ville spørge dig om, hvad jeg skal skrive i mit name <input type='text' name='???'> for at lave et felt til, og om jeg skal skrive noget mere neden under, for jeg kan vel ik bare kalde name for alder, og så er det bare det.
Avatar billede hoejrup Nybegynder
24. juni 2003 - 00:54 #16
Du kan selv vælge indholdet af name, det er bare et variabel navn. Det variablen hedder noget med $ foran.

Eks. variablen $from i php stammer fra linien echo  "<input type='text' name='from'><br>\n";

/per
Avatar billede Slettet bruger
24. juni 2003 - 00:55 #17
okay takker
Avatar billede hoejrup Nybegynder
24. juni 2003 - 01:02 #18
Velbekomme!

/per
Avatar billede Slettet bruger
24. juni 2003 - 01:04 #19
hmm hvor skal jeg placere fx $form henne for at den bliver vist i mailen? og skal jeg skrive andet end bare $form?
Avatar billede hoejrup Nybegynder
24. juni 2003 - 01:15 #20
Den er allerede placeret i beskrivelsen i linket.

Hvis du vil have alderen med:

echo  "<input type='text' name='alder'><br>\n";


indsættes lige før $body =  "--$boundary .... i php:    $body =  "$body\n\nalder: $alder"

/per
Avatar billede Slettet bruger
24. juni 2003 - 01:34 #21
Syntes sq ik lige jeg kan få det til at virke. prøv lige at indesætte det i min kode. Skal lige siges at dette er det første php jeg har haft gang i ind til vidre, derfor jeg ik fatter så meget.

index.php
---------------------
<?php
# Now we'll make the form. When making forms that allow
# file uploads, it is important to remember to set the
# "enctype" attribute in the <form> tag to "multipart/form-data".
echo  "<form action='$PHP_SELF' enctype='multipart/form-data' method='post'>\n";
echo  "<input type='text' name='alder'><br>\n";
echo  "<input type='text' name='body'><br>\n";
echo  "<input type='file' name='attachment'><br>\n";
echo  "<input type='submit' name='send' value='Send'>\n";
echo  "</form>\n";

# If the user has pushed the "Send" button:
if ($send) {
    # Defining the boundary:
    $boundary = uniqid( "");

    # Making the headers:
    $headers =  "From: Strandparty@strandparty.dk
Content-type: multipart/mixed; boundary=\"$boundary\"";

    # Determining the MIME type of the uploaded file:
    if ($attachment_type) $mimeType = $attachment_type;
    # If the browser did not specify the MIME type of the uploaded
    # file, we'll just set the MIME type to "application/unknown".
    else $mimeType =  "application/unknown";

    # Determining the file name:
    $fileName = $attachment_name;

    # Opening the file:
    $fp = fopen($attachment,  "r");
    # Reading the entire file into a variable:
    $read = fread($fp, filesize($attachment));

    # OK, now we have a variable named $read
    # that contains the entire file as a text chunk.
    # Now we need to convert that text chunk into
    # something that the mail clients can read.
    # This means we'll have to encode it with base64.
    $read = base64_encode($read);

    # Now we've got a long text base64 encoded
    # text string. The next thing we need to do
    # is to convert that long string to
    # small pieces consisting of 76 characters
    # per line.
    $read = chunk_split($read);

    # Now we can create the mail body:
    $body =  "--$boundary
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit

$body

--$boundary
Content-type: $mimeType; name=$fileName
Content-disposition: attachment; filename=$fileName
Content-transfer-encoding: base64

$read

--$boundary--";

    # Mailing the whole thing:
    mail( "jesper_christophersen@hotmail.com", "Ny Bruger", $body, $headers);
}
?>
Avatar billede hoejrup Nybegynder
24. juni 2003 - 01:48 #22
<?php
# Now we'll make the form. When making forms that allow
# file uploads, it is important to remember to set the
# "enctype" attribute in the <form> tag to "multipart/form-data".
echo  "<form action='$PHP_SELF' enctype='multipart/form-data' method='post'>\n";
echo  "<input type='text' name='alder'><br>\n";
echo  "<input type='text' name='body'><br>\n";
echo  "<input type='file' name='attachment'><br>\n";
echo  "<input type='submit' name='send' value='Send'>\n";
echo  "</form>\n";
# If the user has pushed the "Send" button:
if ($send) {
    # Defining the boundary:
    $boundary = uniqid( "");
    # Making the headers:
    $headers =  "From: Strandparty@strandparty.dk
Content-type: multipart/mixed; boundary=\"$boundary\"";
    # Determining the MIME type of the uploaded file:
    if ($attachment_type) $mimeType = $attachment_type;
    # If the browser did not specify the MIME type of the uploaded
    # file, we'll just set the MIME type to "application/unknown".
    else $mimeType =  "application/unknown";
    # Determining the file name:
    $fileName = $attachment_name;
    # Opening the file:
    $fp = fopen($attachment,  "r");
    # Reading the entire file into a variable:
    $read = fread($fp, filesize($attachment));
    # OK, now we have a variable named $read
    # that contains the entire file as a text chunk.
    # Now we need to convert that text chunk into
    # something that the mail clients can read.
    # This means we'll have to encode it with base64.
    $read = base64_encode($read);
    # Now we've got a long text base64 encoded
    # text string. The next thing we need to do
    # is to convert that long string to
    # small pieces consisting of 76 characters
    # per line.
    $read = chunk_split($read);

    $body =  "$body\n\nalder: $alder"

    # Now we can create the mail body:
    $body =  "--$boundary
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit
$body
--$boundary
Content-type: $mimeType; name=$fileName
Content-disposition: attachment; filename=$fileName
Content-transfer-encoding: base64
$read
--$boundary--";
    # Mailing the whole thing:
    mail( "jesper_christophersen@hotmail.com", "Ny Bruger", $body, $headers);
}
?>

/per
Avatar billede Slettet bruger
24. juni 2003 - 01:57 #23
hmm det var det samme som jeg gjorde, men jeg får denne fejl.
"Parse error: parse error, unexpected T_VARIABLE in /customers/strandparty.dk/strandparty.dk/httpd.www/mailform/index.php on line 45"

index.php
-------------
<?php
# Now we'll make the form. When making forms that allow
# file uploads, it is important to remember to set the
# "enctype" attribute in the <form> tag to "multipart/form-data".
echo  "<form action='$PHP_SELF' enctype='multipart/form-data' method='post'>\n";
echo  "<input type='text' name='alder'><br>\n";
echo  "<input type='text' name='body'><br>\n";
echo  "<input type='file' name='attachment'><br>\n";
echo  "<input type='submit' name='send' value='Send'>\n";
echo  "</form>\n";
# If the user has pushed the "Send" button:
if ($send) {
    # Defining the boundary:
    $boundary = uniqid( "");
    # Making the headers:
    $headers =  "From: Strandparty@strandparty.dk
Content-type: multipart/mixed; boundary=\"$boundary\"";
    # Determining the MIME type of the uploaded file:
    if ($attachment_type) $mimeType = $attachment_type;
    # If the browser did not specify the MIME type of the uploaded
    # file, we'll just set the MIME type to "application/unknown".
    else $mimeType =  "application/unknown";
    # Determining the file name:
    $fileName = $attachment_name;
    # Opening the file:
    $fp = fopen($attachment,  "r");
    # Reading the entire file into a variable:
    $read = fread($fp, filesize($attachment));
    # OK, now we have a variable named $read
    # that contains the entire file as a text chunk.
    # Now we need to convert that text chunk into
    # something that the mail clients can read.
    # This means we'll have to encode it with base64.
    $read = base64_encode($read);
    # Now we've got a long text base64 encoded
    # text string. The next thing we need to do
    # is to convert that long string to
    # small pieces consisting of 76 characters
    # per line.
    $read = chunk_split($read);

    $body =  "$body\n\nalder: $alder"

    # Now we can create the mail body:
    $body =  "--$boundary          <---- linje 45
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit
$body
--$boundary
Content-type: $mimeType; name=$fileName
Content-disposition: attachment; filename=$fileName
Content-transfer-encoding: base64
$read
--$boundary--";
    # Mailing the whole thing:
    mail( "jesper_christophersen@hotmail.com", "Ny Bruger", $body, $headers);
}
?>
Avatar billede hoejrup Nybegynder
24. juni 2003 - 10:06 #24
Min metode kan ikke bruges, fordi der er tre forskellige mime typer:
En til tekst, en til billeder og en til html. Så det skal programmeres på
en lidt anden måde.

/per
Avatar billede hoejrup Nybegynder
24. juni 2003 - 10:11 #25
Du kan hente multitypemail koden her: http://codewalkers.com/seecode/219.html

/per
Avatar billede Slettet bruger
24. juni 2003 - 11:46 #26
Hmm når jeg bruger dene kode får jeg den samme fejl som, vedkommende som har skrevet neden under koden, altså den godkender ikke min email som en email.
Avatar billede Slettet bruger
24. juni 2003 - 11:51 #27
du kan lige selv prøve engang


http://www.strandparty.dk/mailform/index3.php
Avatar billede hoejrup Nybegynder
24. juni 2003 - 11:59 #28
Jeg får meddelsen:

I'm sorry, but the address 'min email adresse' is not valid.
Please click here to send another message.

/per
Avatar billede Slettet bruger
24. juni 2003 - 12:00 #29
ja, hvad kan der være galt i koden?
Avatar billede Slettet bruger
24. juni 2003 - 12:16 #30
hmm nej, jeg har fundet ud af at mailen bliver sendt alligevel selvom, man får den meddelse. så må jeg bare rediger lidt i teksten, for jeg skal alligevel have den til min faste mail, så der behøver ik email check på den
Avatar billede hoejrup Nybegynder
24. juni 2003 - 12:36 #31
Eller redigerer lidt i programmet. :-)

/per
Avatar billede Slettet bruger
24. juni 2003 - 20:05 #32
Hmm, hvad skal jeg nu rediger i for at lave en ekstra input box, som virker ligesom msg?

index.php
---------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<?php

function multitypemail($message,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)

  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com

  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );

    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;

    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);

    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);

    return $str;
  } // end safeHTML

  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }


  /* ************************** */
  /*    End local procedures    */
  /* ************************** */


  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }

  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }

  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";

  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }

  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";

  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";

  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".

  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n"; 

  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n"; 
  $email_message .= "--" . $alternative_boundary . "--\r\n";

  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below

    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";

  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";

  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }

  if(!$ok)
    $returnval=3;

  return $returnval;
}
// end function multitypemail
?>

<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));

  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);

  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>
Avatar billede hoejrup Nybegynder
24. juni 2003 - 20:25 #33
Jeg kan ikke lave en ekstra input box, hvis du ikke skriver hvad den skal bruges til.

/per
Avatar billede Slettet bruger
24. juni 2003 - 20:27 #34
nåå okay, der skal være en som hedder alder, msn ovs. bare lav en så jeg bare kan se hvordan man gør, så kan jeg vel selv lave resten af dem,
Avatar billede hoejrup Nybegynder
24. juni 2003 - 21:28 #35
Hvis du søger på $msg i scriptet, og søger på $message i funktionen.
Så kan du se hvilke punkter du skal have med i scriptet.

/per
Avatar billede Slettet bruger
24. juni 2003 - 21:57 #36
hmm, nu syntes jeg at jeg har fået tilrettet det så det skulle passe, men det virker stadig ikke.

index.php
----------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<?php

function multitypemail($message,$msn,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)

  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com

  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );

    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;

    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);

    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);

    return $str;
  } // end safeHTML

  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }


  /* ************************** */
  /*    End local procedures    */
  /* ************************** */


  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msn=safeHTML($msn);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$msn; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msn="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msn,ENT_QUOTES)."</BODY></HTML>";
    $msn=nl2br($msn); //turn all hard coded newlines into HTML breaks
  }

  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }

  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";

  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }

  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";

  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";

  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".

  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n"; 

  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n";
                    $msn . "\n\n";

  $email_message .= "--" . $alternative_boundary . "--\r\n";

  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below

    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";

  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";

  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }

  if(!$ok)
    $returnval=3;

  return $returnval;
}
// end function multitypemail
?>

<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));

  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);

  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>
Avatar billede Slettet bruger
24. juni 2003 - 21:58 #37
kan du se hvad jeg har gjort galt, eller slet ik har gjort?
Avatar billede hoejrup Nybegynder
24. juni 2003 - 22:13 #38
Jeg kigger på det i morgen, for jeg min hjerne er ved at være træt.

/per
Avatar billede Slettet bruger
24. juni 2003 - 23:34 #39
Det er bare helt iorden du ;-)
Avatar billede hoejrup Nybegynder
25. juni 2003 - 20:24 #40
Her er nogle rettelser: Navnet i funktionen skal være forskellig fra variabel navne i funktionskaldet, men
positionen skal være den samme.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<?php
function multitypemail($message,$msn1,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$msn1        - indtast din msn
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)
  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com
  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );
    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;
    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);
    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);
    return $str;
  } // end safeHTML
  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }
  /* ************************** */
  /*    End local procedures    */
  /* ************************** */
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msn1=safeHTML($msn1);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$msn1; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msn1="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msn1,ENT_QUOTES)."</BODY></HTML>";
    $msn1=nl2br($msn1); //turn all hard coded newlines into HTML breaks
  }
  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }
  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";
  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }
  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";
  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n"; 
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n";
                    $msn1 . "\n\n";
  $email_message .= "--" . $alternative_boundary . "--\r\n";
  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below
    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";
  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";
  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }
  if(!$ok)
    $returnval=3;
  return $returnval;
}
// end function multitypemail
?>
<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));
  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);
  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>

/per
Avatar billede Slettet bruger
25. juni 2003 - 21:13 #41
Hmm er du sikker på at der ik mangler et eller andet? den sender stadig kun den ene af de 2 beskeder afsted til e-mailen.
Avatar billede dotcom1 Nybegynder
25. juni 2003 - 22:06 #42
Hvad med en form, der allerede virker? :) http://www.skyminds.net/source/ Det er den der hedder "Mail-it Now! Upload2Server."
Avatar billede Slettet bruger
25. juni 2003 - 22:28 #43
Takker, nu kan jeg få det hele til at virke :-)
Avatar billede dotcom1 Nybegynder
25. juni 2003 - 22:32 #44
Velbekomme - hvis det altså var møntet på mig... :)
Avatar billede Slettet bruger
25. juni 2003 - 22:33 #45
yeps..
Avatar billede hoejrup Nybegynder
25. juni 2003 - 23:12 #46
Jeg fandt en lille fejl

Det burde virke nu

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<?php
function multitypemail($message,$msn1,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$msn1        - indtast din msn
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)
  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com
  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );
    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;
    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);
    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);
    return $str;
  } // end safeHTML
  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }
  /* ************************** */
  /*    End local procedures    */
  /* ************************** */
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msnn=safeHTML($msnn);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessagee=$msnn; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msnn="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msnn,ENT_QUOTES)."</BODY></HTML>";
    $msnn=nl2br($msnn); //turn all hard coded newlines into HTML breaks
  }
  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }
  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";
  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }
  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";
  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n"; 
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n";
                    $txtmessagee . "\n\n";
  $email_message .= "--" . $alternative_boundary . "--\r\n";
  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below
    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";
  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";
  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }
  if(!$ok)
    $returnval=3;
  return $returnval;
}
// end function multitypemail
?>
<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));
  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);
  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>

/per
Avatar billede Slettet bruger
25. juni 2003 - 23:16 #47
kan stadig ik få den til at virke per, den laver stadig kun 1 medd.
Avatar billede hoejrup Nybegynder
25. juni 2003 - 23:18 #48
Jeg opdagede endnu en fejl

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<?php
function multitypemail($message,$msn1,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$msnn      - indtast din msn
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)
  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com
  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );
    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;
    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);
    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);
    return $str;
  } // end safeHTML
  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }
  /* ************************** */
  /*    End local procedures    */
  /* ************************** */
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msnn=safeHTML($msnn);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessagee=$msnn; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msnn="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msnn,ENT_QUOTES)."</BODY></HTML>";
    $msnn=nl2br($msnn); //turn all hard coded newlines into HTML breaks
  }
  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }
  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";
  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }
  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";
  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n"; 
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" .
                    $txtmessagee . "\n\n";
  $email_message .= "--" . $alternative_boundary . "--\r\n";
  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below
    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";
  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";
  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }
  if(!$ok)
    $returnval=3;
  return $returnval;
}
// end function multitypemail
?>
<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));
  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);
  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>

/per
Avatar billede Slettet bruger
25. juni 2003 - 23:20 #49
Nu er der ingen af dem som virker :-(
Avatar billede hoejrup Nybegynder
26. juni 2003 - 00:18 #50
Jeps jeg havde også lavet det forkert.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<?php
function multitypemail($message,$msnn,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$msnn        - indtast din msn
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)
  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com
  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );
    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;
    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);
    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);
    return $str;
  } // end safeHTML
  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }
  /* ************************** */
  /*    End local procedures    */
  /* ************************** */
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessagee="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msnn=safeHTML($msnn);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessagee=$msnn; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msnn="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msnn,ENT_QUOTES)."</BODY></HTML>";
    $msnn=nl2br($msnn); //turn all hard coded newlines into HTML breaks
  }
  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }
  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";
  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }
  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";
  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n";
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n";
  // add HTML alternative part of message
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    $txtmessagee\r\n\r\n";
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $msnn . "\n\n";
  $email_message .= "--" . $alternative_boundary . "--\r\n";
  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below
    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";
  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";
  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }
  if(!$ok)
    $returnval=3;
  return $returnval;
}
// end function multitypemail
?>
<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));
  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);
  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>

/per
Avatar billede Slettet bruger
26. juni 2003 - 00:25 #51
nu får jeg bare denne fejl medd. når jeg åbner siden

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /customers/strandparty.dk/strandparty.dk/httpd.www/mailform/index.php on line 155

Parse error: parse error, unexpected T_STRING in /customers/strandparty.dk/strandparty.dk/httpd.www/mailform/index.php on line 155
Avatar billede hoejrup Nybegynder
26. juni 2003 - 07:33 #52
Ok! Det vil sige at man ikke kan bruge min metode.

Prøv med denne

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<?php
function multitypemail($message,$msnn,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$msnn        - indtast din msn
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)
  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com
  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );
    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;
    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);
    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);
    return $str;
  } // end safeHTML
  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }
  /* ************************** */
  /*    End local procedures    */
  /* ************************** */
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessagee="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msnn=safeHTML($msnn);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessagee=$msnn; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msnn="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msnn,ENT_QUOTES)."</BODY></HTML>";
    $msnn=nl2br($msnn); //turn all hard coded newlines into HTML breaks
  }
  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }
  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";
  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }
  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";
  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n" . $txtmessagee\r\n\r\n";
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n" . $msnn . "\n\n";
  $email_message .= "--" . $alternative_boundary . "--\r\n";
  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below
    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";
  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";
  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }
  if(!$ok)
    $returnval=3;
  return $returnval;
}
// end function multitypemail
?>
<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));
  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);
  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>

/per
Avatar billede Slettet bruger
26. juni 2003 - 12:09 #53
Nu får jeg denne fejl
---------------

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /customers/strandparty.dk/strandparty.dk/httpd.www/mailform/index.php on line 143

Parse error: parse error, unexpected T_STRING in /customers/strandparty.dk/strandparty.dk/httpd.www/mailform/index.php on line 143
Avatar billede hoejrup Nybegynder
26. juni 2003 - 12:27 #54
Ok der manglede en "

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<?php
function multitypemail($message,$msnn,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$msnn        - indtast din msn
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)
  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com
  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );
    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;
    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);
    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);
    return $str;
  } // end safeHTML
  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }
  /* ************************** */
  /*    End local procedures    */
  /* ************************** */
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessagee="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msnn=safeHTML($msnn);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessagee=$msnn; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msnn="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msnn,ENT_QUOTES)."</BODY></HTML>";
    $msnn=nl2br($msnn); //turn all hard coded newlines into HTML breaks
  }
  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }
  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";
  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }
  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";
  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n" . "$txtmessagee\r\n\r\n";
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n" . $msnn . "\n\n";
  $email_message .= "--" . $alternative_boundary . "--\r\n";
  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below
    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";
  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";
  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }
  if(!$ok)
    $returnval=3;
  return $returnval;
}
// end function multitypemail
?>
<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));
  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);
  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>

/per
Avatar billede Slettet bruger
26. juni 2003 - 12:31 #55
Kanon der var den
Avatar billede hoejrup Nybegynder
26. juni 2003 - 12:34 #56
Virker den nu?

/per
Avatar billede Slettet bruger
26. juni 2003 - 12:36 #57
yeps, det gør den. takker, nu sidder jeg bare og roder lide med opstillingen af hvordan e-mailen skal se ud men det kan jeg godt selv :-)
Avatar billede hoejrup Nybegynder
26. juni 2003 - 12:41 #58
Ok! Jeg burde næsten have point for det :-)

Så kan du også bruge den gamle, hvis jeg retter "

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<?php
function multitypemail($message,$msnn,$ishtml,$subject,$toname,$toemail,$fromname,$fromemail,$attachmentloc,$attfilename,$cc,$ccname,$bcc,$bccname) {
  //$message      - text or html message to be sent
  //$msnn        - indtast din msn
  //$ishtml        - flag set to true if $message is HTML, otherwise set to false
  //$subject      - subject line of email
  //$toname        - name of person receiving email (use only if sending to a single person)
  //$toemail      - email address of recipient (separate multiple addresses by a comma, use ! as first character to send to each receipient separately
  //$fromname      - name of person sending email
  //$fromemail    - email address of sender
  //$attachmentloc - path and filename of attachment (on the server), or empty string for no attachment
  //$attfilename  - filename and extension only
  //$cc            - email address of person to courtesy copy (or empty string)
  //$cc            - name of person to courtesy copy (or empty string)
  //$bcc          - email address of person to blind courtesy copy (or empty string)
  //$bcc          - address of person to blind courtesy copy (or empty string)
  $returnval=0;    // returns integer, zero for success (okay, its a bit naff but at least it says something!)
  global $HTTP_HOST; // name of host used for a base-reference, e.g. www.myhost.com
  /* ************************** */
  /*  Begin local procedures  */
  /* ************************** */
  //strip out all non-safe HTML directives and any PHP & ASP directives
  function safeHTML($str)
  {
    $approvedtags = array(
      "p"=>2,  // 2 means accept all qualifiers: <foo bar>
      "b"=>1,  // 1 means accept the tag only: <foo>
      "i"=>1,  // note, recommend not allowing <img> as these can be used to call cgi-perl routines
      "a"=>2,
      "em"=>1,
      "br"=>1,
      "strong"=>1,
      "blockquote"=>1,
      "tt"=>1,
      "hr"=>1,
      "li"=>1,
      "ol"=>1,
      "ul"=>1
      );
    $str = stripslashes($str);
    $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
    $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
      "<a href=%22/2/%22>", $str);
    $tmp = "";
    while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
    {
      $i = strpos($str,$reg[0]);
      $l = strlen($reg[0]);
      if ($reg[1][0] == "/")
        $tag = strtolower(substr($reg[1],1));
      else
        $tag = strtolower($reg[1]);
      if ($a = $approvedtags[$tag])
        if ($reg[1][0] == "/")
          $tag = "</$tag>";
        elseif ($a == 1)
          $tag = "<$tag>";
        else
          $tag = "<$tag " . $reg[2] . ">";
      else
        $tag = "";
      $tmp .= substr($str,0,$i) . $tag;
      $str = substr($str,$i+$l);
    }
    $str = $tmp . $str;
    // Squash PHP tags unconditionally
    $str = ereg_replace("<\?php","",$str);
    $str = ereg_replace("<\?","",$str);
    // Squash ASP tags unconditionally
    $str = ereg_replace("</a><%","",$str);
    return $str;
  } // end safeHTML
  // check if email address is valid
  function validate_email($val)
  {
    if($val != "") {
      $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
      if(preg_match($pattern, $val))
        return true;
      else
        return false;
    }
    else
      return false;
    }
  /* ************************** */
  /*    End local procedures    */
  /* ************************** */
  if ($ishtml) {
    $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $message=safeHTML($message);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessage=$message; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $message="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($message,ENT_QUOTES)."</BODY></HTML>";
    $message=nl2br($message); //turn all hard coded newlines into HTML breaks
  }
 
  if ($ishtml) {
    $txtmessagee="This is a multi-part HTML-based message. Please use an HTML compliant email client.";
    $msnn=safeHTML($msnn);
  }
  else {
    // if its raw text, create a simple HTML version of it for HTML compatible email clients
    $txtmessagee=$msnn; // save rawtext version
    //next line translates text into HTML using the PHP built-in function 'htmlentities'
    $msnn="<HTML><HEAD><TITLE>MultiMail Message</TITLE></HEAD><BODY>".htmlentities($msnn,ENT_QUOTES)."</BODY></HTML>";
    $msnn=nl2br($msnn); //turn all hard coded newlines into HTML breaks
  }
  // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses
  if ($to[0]=="!") {
    $sendsep=1;
    $to=substr($to,1); }
  // build message headers
  // note use of \r\n (not just \n) in headers as this will work on all emailers
  $headers .= "From: $fromname <"."$fromemail".">\r\n";
  if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; }
  if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; }
  // create a MIME boundary strings
  $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "=====";
  // add MIME data to the message headers
  $headers .= "MIME-Version:1.0\r\n";
  $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n".
              "Content-Transfer-Encoding: 7bit\r\n".
              "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";
  // start building a MIME message
  // first part is always the message body
  // encode an alternative section for raw text & HTML
  $email_message = "--" . $mime_boundary . "\r\n".
                  "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n".
                  "--".$related_boundary."\r\n".
                  "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n".
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessage\r\n\r\n";
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $message . "\n\n";
  // add HTML alternative part of message
  // add raw text alternative as 7-bit text
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n".
                    "Content-Transfer-Encoding: 7bit\r\n\r\n".
                    "$txtmessagee\r\n\r\n";
  // add HTML alternative part of message
  $email_message .= "--" . $alternative_boundary . "\r\n".
                    "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . 
                    "Content-Base: $HTTP_HOST\r\n" .
                    "Content-Transfer-Encoding: 7bit\r\n\r\n" . 
                    $msnn . "\n\n";
  $email_message .= "--" . $alternative_boundary . "--\r\n";
  if ($attachmentloc!='' && filesize("$attachmentloc")>0) {
    $file = fopen("$attachmentloc",'rb'); 
    $data = fread($file,filesize("$attachmentloc")); 
    fclose($file); 
    $data = chunk_split(base64_encode($data));  // note same as transfer coding in line below
    // add the MIME data
    $email_message .= "--" . $related_boundary . "\r\n".
                      "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n".
                      "Content-Transfer-Encoding: base64\r\n".
                      "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n".
                      $data . "\r\n".
                      "\r\n--$related_boundary--\r\n";
  }
  $email_message .= "--" . $mime_boundary . "--\r\n";
  if (!validate_email($from_email)) $returnval=1;
  $formattedto = "$toname <".$toemail.">";
  // send out the message
  if ($sendsep) {
    $allto = split(",", $to);
    for($x=0; $x<sizeof($allto); $x++) {
      if($allto[$x] == "") continue;
      if (!validate_email($allto[$x])) $returnval=2;
      $ok = mail($allto[$x], $subject, $email_message, $headers);
    }
  }
  else {
    if (!validate_email($toemail)) $returnval=2;
    $ok = mail($formattedto, $subject, $email_message, $headers);
  }
  if(!$ok)
    $returnval=3;
  return $returnval;
}
// end function multitypemail
?>
<!-- Here is some very simple HTML just to drive the interface to the multi-mailer -->
<head>
<title>Multi-emailer</title>
</head>
<body>
<?php
if (!$sent) // note, assumes PHP setup so that all form variables passed as global variables (normal setup)
  print "<h1>Please enter the following info</h1><div class='font-family:verdana' align=center>".
        "<form method=post name=mailform action=$PHP_SELF ENCTYPE='multipart/form-data'>". // note ENCTYPE - without this browser won't upload file to server just pass its name
        "<table cellpadding=0 cellspacing=0 border=0><tbody>".
        "<tr><td>From addr</td><td><input name=from_addr></td></tr>".
        "<tr><td>Msn:</td><td><input name=msn></td></tr>".
        "<tr><td>From name</td><td><input name=from_name></td></tr>".
        "<tr><td>Message is in HTML? (select for yes)</td><td><input type=checkbox name=htmlformat></td></tr>".
        "<tr><td>Message</td><td><textarea name=msg></textarea></td></tr>".
        "<tr><td>Attach file</td><td><input type=file name=attach></td></tr>".
        "<tr><td>Send you a courtesy copy?</td><td><input type=checkbox name=cc_me></td></tr>".
        "<tr><td>Send you a blind courtesy copy?</td><td><input type=checkbox name=bcc_me></td></tr>".
        "</tbody></table>".
        "<input type=hidden name=sent value=1>".
        "<input type=hidden name=localfilename>".
        "<input type=button value='Send email' onclick='document.mailform.localfilename.value=document.mailform.attach.value;document.mailform.submit();return true'>".
        "</form></div>";
else {
  if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;}
  elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;}
  if ($htmlformat=='on') $htmlon=1;
  else $htmlon=0;
  $i=strrpos($localfilename,"\\");
  if (!$i) $i=strrpos($localfilename,"/");
  $attfilename=substr($localfilename,($i+1));
  if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them
  $result=multitypemail($msg,$msn,$htmlon, "Strandparty.dk - Nyt Medlem", "Jesper", "jesper_christophersen@hotmail.com",$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name);
  if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid.";
  elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid.";
  elseif ($result==3) print "I'm sorry, but the email was not sent.";
  else print "Email sent successfully.<br>";
  print "<br><br>Please click <a href=$PHP_SELF?sent=0>here</a> to send another message.";
}
?>
</body>
</html>

/per
Avatar billede Slettet bruger
26. juni 2003 - 12:43 #59
Hmm, jeg opretter et nyt spørgsmål som hedder "point til per" nu
Avatar billede hoejrup Nybegynder
26. juni 2003 - 12:48 #60
Hvordan virker den sidste metode?

/per
Avatar billede Slettet bruger
26. juni 2003 - 12:49 #61
hmm den virker fint, den virker ligesom den med den orginale besked. hvis det var det du tænkte på
Avatar billede hoejrup Nybegynder
26. juni 2003 - 12:53 #62
Det lyder rigtig godt, så kan du selv tilføje resten. :-)

/per
Avatar billede Slettet bruger
26. juni 2003 - 12:54 #63
Yepper, er allerede i fuld sving ;-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester