The php mail function sends an email with attachments)

Source: Internet
Author: User
Tags gpg php file

(Attachments can be included. <! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en"

The code is as follows: Copy code

Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Title> php mail function sends an email with attachments </title>
</Head>

<Body>
<? Php
// You might need to change this line, if you do not use
// The default ports, 80 for normal traffic and 443 for ssl
If ($ _ server ['server _ port']! = 443)
Echo '<p> <font color = red>
Warning: you have not connected to this page using ssl.
Your message cocould be read by others. </font> </p> ';
?>

<Form method = post action = "send_private_mail.php"> <br>
Your email address: <br>
<Input type = text name = from size = 38> <br>
Subject: <br>
<Input type = text name = title size = 38> <br>
Your message: <br>
<Textarea name = body cols = 30 rows = 10>
</Textarea> <br>
<Input type = submit value = "send! ">
</Form>
</Body>
</Html>

Send_private_mail.php file

The code is as follows: Copy code

<? Php
// Create short variable names
$ From = $ _ post ['from'];
$ Title = $ _ post ['title'];
$ Body = $ _ post ['body'];

$ To_email = 'Luke @ localhost ';

// Tell gpg where to find the key ring
// On this system, user nobody's home directory is/tmp/
Putenv ('gnupghome =/tmp/. Gnupg ');
 
// Create a unique file name
$ Infile = tempnam ('', 'pgp ');
$ Outfile = $ infile. '. asc ';

// Write the user's text to the file
$ Fp = fopen ($ infile, 'w ');
Fwrite ($ fp, $ body );
Fclose ($ fp );

// Set up our command
$ Command = "/usr/local/bin/gpg-\
-- Recipient 'Luke welling <luke@tangledweb.com.au> '\
-- Encrypt-o $ outfile $ infile ";

// Execute our gpg command
System ($ command, $ result );

// Delete the unencrypted temp file
Unlink ($ infile );

If ($ result = 0)
  {
$ Fp = fopen ($ outfile, 'r ');
If (! $ Fp | filesize ($ outfile) = 0)
    {
$ Result =-1;
    }
Else
    {
// Read the encrypted file
$ Contents = fread ($ fp, filesize ($ outfile ));
// Delete the encrypted temp file
Unlink ($ outfile );

Mail ($ to_email, $ title, $ contents, "from: $ from ");
Echo '<P> your message was encrypted and sent.
<P> thank you .';
    }
  }

If ($ result! = 0)
  {
Echo '<P> your message cocould not be encrypted, so has not been sent.
<P> sorry .';
  }
 

/*
 
*/
?>)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.