/    Sign up×
Community /Pin to ProfileBookmark

php help general info

hi,
I have this form that uses phpmailer to send the input to an email and now I need to have it gpg’d before sending. it’s on iis. It’s beyond my level of expertise so I’m willing to pay a few bucks to have it fixed. How do I find help please?
thanks.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 25.2009 — [code=php]
function gpg_encrypt($txt, $owner, $flags=''){
$uniqueName = uniqid();// generate a unique name
$gpg = "gpg";// I've no idea what this will be on windows, sorry.

file_put_contents($uniqueName, $txt, FILE_TEXT);// save the current file

$output = shell_exec("$gpg -e -r $owner $uniqueName");// gpg encrypt it.


echo $output;// remove or leave, up to you. I'd use it for debug.


$gpged = file_get_contents($uniqueName.'.gpg', FILE_BINARY);
unlink($uniqueName);
unlink($uniqueName.'gpg');// delete the files we don't need

return $gpged;
}
[/code]
Copy linkTweet thisAlerts:
@jackmiauthorFeb 26.2009 — thank you. unless you see it you can't help me so here it is. windows does it a little different. I checked the gpg command line and it works fine. it creates the temp file in windows/temp folder. but when executed the script throws an error about $contents as not recognized. it seems to me it's in the gpg command line but I just don't know how to trouble shoot. I went through quite a few examples and before I give up I figured I'll give it a shot here.

thanks again for reading.

[code=html]
<html>
<head><title>gpg test page</title></head>
<body>
<form action="gpgtest.php" method="post">
Name<br>
<input name="name" type="text" size="20"><br>
Email<br>
<input name="email" type="text" size="20"><br>
Message<br>
<textarea name="message" cols="20" rows="2"></textarea>
<input name="submit" type="submit" value="submit">
</form>
</body>
</html>
[/code]


[code=php]
<?php

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

// This will send mail through the SMTP server with authentication.
require("class.phpmailer.php");

//get form details
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

//start phpmailer code (data that gets sent to my email address)
$response = "$namen$emailn$messagen";

//Tell gnupg where the key ring is. Home dir of user web server is running as.
putenv("GNUPGHOME=D:wwwtest");

//PGP user name or e-mail address that was used to generate the PGP keypair
$pgpuser = "**********";

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

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

//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
//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 file
//unlink($outfile);
}
}

//phpmailer code sends via outside smtp serve
$mail = new PHPMailer();
$mail->IsSMTP();
$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 = "**********"; // username smtp account
$mail->Password = "**********"; // password smtp account
$mail->From = $_POST['email'];
$mail->FromName = $_POST['name'];
$mail->AddAddress("**********"); //email it will go to
$mail->Subject = "gpg test";
$mail->Body = $response;
$mail->Body = $contents;

if(!$mail->Send()) {
echo "<p>Error!</p>";
echo "<p>".$mail->ErrorInfo."</p>";
} else {
echo "<p>Success!</p>";
}
$mail->ClearAddresses();
$mail->ClearAttachments();
?>
[/code]
Copy linkTweet thisAlerts:
@scragarFeb 26.2009 — You should be careful using 's and doubt quotes when you don't want the special effects can offer.

I would also echo out the results of your command, just incase that's where your error occurs.
Copy linkTweet thisAlerts:
@jackmiauthorFeb 28.2009 — I have now spent quite a few nights on this.


I enabled php.ini to show all errors and there was nothing. I tried not writing to a file and it basically does the same thing. Looks like the gpg command doesn't get exectued. the script used to complain: unable to fork - but I fixed it by giving permissions to iusr and iis. I've added correct paths and put gpg.exe in all appropriate folders. php code is fine I think. What am I missing? Is there a way to show or log all output either from php and/or cmd?

thank you for your time.
×

Success!

Help @jackmi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...