mail function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eng.sharif@gmail.com

    #1

    mail function


    hi group


    how i can send mail and attachement in php with "mail function "

    $s = mail($to,$subje ct,$cont, $headers);


    can anyone help

    thanx

  • Shelly

    #2
    Re: mail function


    <eng.sharif@gma il.comwrote in message
    news:1172914240 .167747.62430@6 4g2000cwx.googl egroups.com...
    >
    hi group
    >
    >
    how i can send mail and attachement in php with "mail function "
    >
    $s = mail($to,$subje ct,$cont, $headers);
    >
    >
    can anyone help
    >
    thanx
    >
    Here is a function that I got from someone here:


    function mail_attachment ($from , $to, $subject, $message, $attachment){
    $fileatt = $attachment; // Path to the file
    $fileatt_type = "applicatio n/octet-stream"; // File Type
    $start= strrpos($attach ment, '/') == -1 ? strrpos($attach ment, '//') :
    strrpos($attach ment, '/')+1;
    // Filename that will be used for the file as the attachment
    $fileatt_name = substr($attachm ent, $start, strlen($attachm ent));
    $email_from = $from; // Who the email is from
    $email_subject = $subject; // The Subject of the email
    $email_txt = $message; // Message that the email has in it

    $email_to = $to; // Who the email is to

    $headers = "From: ".$email_fr om;

    $file = fopen($fileatt, 'rb');
    $data = fread($file,fil esize($fileatt) );
    fclose($file);
    //$msg_txt="\n\nM ail created using free code from 4word systems :
    http://4wordsystems.co m";

    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Bo undary_x{$semi_ rand}x";

    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mi me_boundary}\"" ;

    //$email_txt .= $msg_txt;

    $email_message .= "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary }\n" .
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $email_txt . "\n\n";

    $data = chunk_split(bas e64_encode($dat a));

    $email_message .= "--{$mime_boundary }\n" .
    "Content-Type: {$fileatt_type} ;\n" .
    " name=\"{$fileat t_name}\"\n" .
    //"Content-Disposition: attachment;\n" .
    //" filename=\"{$fi leatt_name}\"\n " .
    "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n" .
    "--{$mime_boundary }--\n";


    $ok = @mail($email_to , $email_subject, $email_message, $headers);
    //echo "Mail sent to " . $email_to . "<br>";

    if($ok) {
    } else {
    die("Sorry but the email could not be sent. Please go back and try
    again!");
    }
    }

    Shelly


    Comment

    • Jerry Stuckle

      #3
      Re: mail function

      eng.sharif@gmai l.com wrote:
      hi group
      >
      >
      how i can send mail and attachement in php with "mail function "
      >
      $s = mail($to,$subje ct,$cont, $headers);
      >
      >
      can anyone help
      >
      thanx
      >
      Check out phpmailer <http://phpmailer.sourc eforge.net/>. It will make
      your life much easier :-)

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      Working...