Jump to content

PEAR Email Attachment w/ $gpg


sawade

Recommended Posts

I have no issues with this code if I take out the attachement section and include the info in the email body instead.  However, I want the info to be in an email attachment.  I do receive the email, but it is blank.  No attachment, no info being passed into the email at all.  Headers and everything else is fine as well.

:suicide:

Any ideas?

 

Thanks.

 

require_once "Mail/mail.php";
require_once "Mail/mime.php";
require_once "Crypt/GPG.php";
require_once "Constants.php";

if ($send_attachment_as == 'CSV') {
	//Creates CSV file
		$cr = "\n";
		$csvData = "Last" . ',' . $last_name . $cr;
		$csvData .= "First" . ',' . $first_name . $cr;
		$csvData .= "MI" . ',' . $middle_name . $cr;
		$csvData .= "Input would continue..." . ',' . $cr;

		//Open the file
		$filehandler = fopen("csvdemo.csv","a") or die("Can't write file.");
		fwrite($filehandler,$csvData);    // Write information to the file
		fclose($filehandler);  // Close the file

		$text = "Please see the attached document for a recently submitted Form.";

		$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  					<head>
    				<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

				</head>
				<body>

            		<p>Please see the attached document for a recently submitted Form.</p>

            		</body></html>';

		$file = 'csvdemo.csv';
		$crlf = "\n";

		$to = 'email address';

		$hdrs = array(
              'From'     => MAILER,
              'Subject'  => "CSV $date",
		  'Reply-to' => MAILER
              );
		  
		$smtp["host"] = SMTP_HOST;
		$smtp["port"] = SMTP_PORT;
		$smtp["auth"] = true;
		$smtp["username"] = SMTP_USERNAME;
		$smtp["password"] = SMTP_PASSWORD;

		$mime = new Mail_mime($crlf);

		$mime->setTXTBody($text);
		$mime->setHTMLBody($html);
		$mime->addAttachment($file, 'application/vnd.ms-excel');

		$body = $mime->get();
		$hdrs = $mime->headers($hdrs);

		// Encryption
		require_once "Constants.php";
		$data = $body;	

		$gpg = new Crypt_GPG();
		$gpg -> addEncryptkey(GPG_SECURE);
		$encrypted = $gpg -> encrypt($data);


		$mail = Mail::factory('smtp', $smtp);

		$mail->send($to, $hdrs, $encrypted)
			or die('Error while processing your submission.');

		//Delete Created File
		unlink($file);
}

Link to comment
Share on other sites

I have doubled and triple checked to make sure the encryption keys are working properly, and again I can get a regular email encryted, sent and decrypted.  But as soon I put the attachment code in and try it, I get a blank email that can't be decrypted... I am assuming it can't be decrypted because there is no info in the email to decrypt.

 

I have tried everything I can think of, and it always ends in the same result... a blank email.

 

Thanks.

Link to comment
Share on other sites

Have you tried doing some basic debugging by outputting the encrypted, testing that the file was created and contained data?

Have you tried removing the encryption part and seeing if that sends?

 

In all of the bumps you failed to tell if you have tried anything or just waited for a response. The reason you are getting lack of responses is the PEAR package, not many people want to install the exact setup just to test and see how to get your script to work, sorry. But for the most part you are going to have to just debug this old fashioned way with trial and error until you figure out what is wrong.

 

How I would approach this problem:

Take out all the complex stuff and create a script that simply sends a test.csv file (that is already created in the folder the script is in) and send that, with nothing else. If that sends fine, slowly add more items, if it does not you now know your problem lies with PEAR and can at least pin point why it is not sending properly.

 

But your first problem is testing that you can indeed send a file and receive it without all the extra stuff, if that is where the problem lies figure out how to fix it then add on from there.

Link to comment
Share on other sites

Yeah, everything works great until I input the encryption block...

 

$data = $body;	
$gpg = new Crypt_GPG();
$gpg -> addEncryptkey(GPGCONSTANT);
$encrypted = $gpg -> encrypt($data);

 

If I remove this the code works fine.

 

I am beginning to wonder if PEAR is not compatible with the encryption or if I need another PEAR componet that I haven't found yet.

 

Baffeling.

Link to comment
Share on other sites

Well after doing some reading (really hard to find much information on this) I have come to a conclusion that something in PEAR stops this or you are missing a needed step, which I do not know what it is.

 

How about sending the message un-encrypted and just encrypting the attachment? Or try encrypting the attachment before you attach it as well as the message, maybe you have to them both encrypted for it to work?

 

I do have to say I know nothing about this cause I never used the GPG encryption method, so yea. I am just grabbing at straws.

Link to comment
Share on other sites

Well after doing some reading (really hard to find much information on this) I have come to a conclusion that something in PEAR stops this or you are missing a needed step, which I do not know what it is.

 

How about sending the message un-encrypted and just encrypting the attachment? Or try encrypting the attachment before you attach it as well as the message, maybe you have to them both encrypted for it to work?

 

I do have to say I know nothing about this cause I never used the GPG encryption method, so yea. I am just grabbing at straws.

 

It is very hard finding info on this.  That is an idea though.  I will try to encryption the file and then attach it into the email.  I will post after I have tried that.

 

Thanks for the help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.