php mail function to send e-mail (can be attached)

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags content echo e-mail file function html http mail

<"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 to send e-mail (can be attached) </ 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 could 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

<? 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 -a
--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: $ fromn");
echo '<h1> message sent </ h1>
<p> your message was encrypted and sent.
<p> thank you. ';
}
}

if ($ result! = 0)
{
echo '<h1> error: </ h1>
<p> your message could not be encrypted, so has not been sent.
<p> sorry. ';
}

/ *
This is a function using php mail sent mail, but also support the sending of attachments Oh.
* /
?>)

Related Article

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.