Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Thanked 0 Times in 0 Posts

    form gpg'd to send via phpmailer mess

    I have no knowledge of php.

    I'm trying to gpg a form and send it attached or in an email body. I use php mailer to send. smtp doesn't work on my server(w2k3, iis6)

    when executing the script I was getting an error: 'unable to fork' but I solved it by giving appropriate permissions.

    a txt file gets created in windows/temp folder but then it may not get processed because I don't know how to check it or it simply doesn't get attached so it gets erased.

    gpg is correctly installed. the key files are in the defined folders and gpg is in the path. the folders have permissions.

    there is a line that executes the gpg command and it should give me the '$result' but if I try to attach it, php complains about an error

    Can someone PLEASE clean it up?

    <TITLE>PGP Encryption</TITLE>

    <FORM method="POST" action="11sendpgp.php">

    <p>Your Name:<br>
    <INPUT type="text" name="T1" size=25></p>

    <p>Your E-Mail Address:<br>
    <INPUT type="text" name="email" size=25></p>

    <p>Your Message:<br>
    <TEXTAREA name="message" cols=35 rows=5></TEXTAREA></p>
    <input type=hidden name="recipient" value="30">

    <p><INPUT type="submit" value="Send Message" name="B1"></p>


    //show all php error messaages
    ini_set('display_errors', 1);
    ini_set('log_errors', 1);
    ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

    // This will send mail through the SMTP server with authentication.
    require("class.phpmailer.php"); // be sure to change this to your location!

    //replace this with your PGP user name or e-mail address that you used to generate the PGP keypair
    $pgpuser = "test@test.net";

    $testemail = "test@test.net";
    $emailsubject = "Encrypted Information";

    //this is the email submit from form
    $emailfrom = "From:". $_POST['email'];

    //form message
    $body = $_POST['message'];

    //Tell gnupg where the key ring is. Home dir of user web server is running as.
    // change this to the correct path of your web space /kunden/homepages/41/dxxxxxx/htdocs/.gnupg

    //create a unique file name
    $infile = tempnam("/tmp", "PGP.asc");
    $outfile = $infile.".asc";

    //write form variables to email
    $fp = fopen($infile, "w");
    fwrite($fp, $body);

    //set up the gnupg command. Note: Remember to put e-mail address on the gpg keyring.
    $command = "gpg.exe -a --always-trust --batch --no-secmem-warning -e -r $pgpuser -o $outfile $infile";

    //execute the gnupg command
    system($command, $result);

    //delete the unencrypted temp file

    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 file

    //send the email
    /////// these lines should be deleted as the 'mail' via regular smtp doesn't work on my server
    //mail ($testemail, $emailsubject, $contents, $emailfrom);

    print "<html>Thank you!! Your encrypted e-mail has been sent. </html> ";
    if($result!=0) {
    print "<html>There was a problem processing the information.";

    $response = "$emailsubject $emailfrom ";

    //mail("$response, $headers);
    $mail = new PHPMailer();
    //sending via smtpauth.earthlink.net - works great
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->SMTPSecure = "tsl"; // sets the prefix to the servier
    $mail->Host = "smtpauth.earthlink.net"; // sets earthlink as the SMTP server
    $mail->Port = 587; // set the SMTP port
    $mail->Username = "test@test.net"; // username
    $mail->Password = "test"; // password
    $mail->From = $_POST['email'];
    $mail->FromName = $_POST['email'];
    $mail->Subject = "email test";
    $mail->Body = $response;
    $mail->Body = $body;
    $mail->Body = $result;
    $mail->Body = $command;

    echo "<p>We are sorry, there was an error in sending mail, please try again at a later time.</p>";
    echo "<p>".$mail->ErrorInfo."</p>";
    echo "<p><br><br>Thank you.<br></p>";


  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Thanked 637 Times in 625 Posts
    First read this:

    Please wrap PHP codes using the [PHP][/PHP] tag

    Then you should realize that this forum is for helping people with specific PHP questions and issues. If you want someone just to "clean it up" you'll want to have a mod move your thread to the appropriate Web Projects forum (depending on the size of the job).



    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts