Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong MIMEHeader Date #2978

Closed
pelloq1 opened this issue Nov 16, 2023 · 7 comments
Closed

wrong MIMEHeader Date #2978

pelloq1 opened this issue Nov 16, 2023 · 7 comments

Comments

@pelloq1
Copy link

pelloq1 commented Nov 16, 2023

I write an app that schedule email for later sending.

The php script do this when the user select the time to send :


$mail->Body     = $email_body ;
$mail-(> ... create the email)

$mail->preSend();

$blob = serialize($mail);

$query 		= "INSERT INTO wf_email_prog_cron (dt_send,serialised_email) VALUES ({$dt_send}, {$blob})";

And in my cron script I do :

$query	= "	SELECT * 	FROM wf_email_prog_cron 	WHERE time condition ... ";

... testing result
$mail = unserialize($v->serialised_email);
$result = $mail->postSend();

All work fine, the mail is sent to the scheduled date and time, but ... in the email header (and unfortunately in outlook) the original date and time are shown :

  • Date: Thu, 16 Nov 2023 12:34:16 +0000 --> when message is realy posted 2 days earlier.

It's not possible to change this before the $result = $mail->postSend();

Thanks you.
Cédric

@Synchro
Copy link
Member

Synchro commented Nov 16, 2023

I'd suggest not doing it this way – even if you manage to change it, it will break DKIM signatures. Save the properties of the message (recipients, body, subject), then build the message just before you send it (which you can do without changing your DB structure - just save these values in an array that you serialise and put in your serialise_email field, though I'd recommend using JSON instead of serialised PHP). That will solve the timestamp issue, and also reduce your storage requirements.

@Synchro Synchro closed this as completed Nov 16, 2023
@pelloq1
Copy link
Author

pelloq1 commented Nov 16, 2023

thanks, the problem is that I have multiple attachements ....

@Synchro
Copy link
Member

Synchro commented Nov 16, 2023

Keep the attachments and attach them later?

@pelloq1
Copy link
Author

pelloq1 commented Nov 16, 2023

this is not so confortable, because after the email is sent, the job is passed into a "a facturer / ready to invoice" folder on the server, and then the file can no more be reachable...

@Synchro
Copy link
Member

Synchro commented Nov 16, 2023

You could store the attachments in the database along with the other data – PHPMailer is happy to add attachments from in-memory strings. You're already effectively storing attachments in there anyway as part of the encoded email message.

@pelloq1
Copy link
Author

pelloq1 commented Nov 16, 2023

It was a very easy solution to store the full email. For me is complex to store an undefined number of file in the database.

I ll need to find another solution. Thanks you

@Synchro
Copy link
Member

Synchro commented Nov 16, 2023

It's not hard to store an arbitrary number of files in the DB – for example:

$fileData = [];
foreach ($files as $filename) {
    $fileData[] = [
        $filename => file_get_contents($filename);
    ];
}
$filestring = serialize($filedata);

Now you can store the string in the DB – just make sure you use a big enough field to store it all in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants