Closed daddyfix closed 4 years ago
[ SOLVED ]
Modify the sendFormEmail function.
Change the reference from $params['attachments'] to $form->process['attachments']) Lines 120 and 121
protected function sendFormEmail($form, $params, $vars)
{
// Build message
$message = $this->email->buildMessage($params, $vars);
if (isset($form->process['attachments'])) {
$filesToAttach = (array)$form->process['attachments'];
if ($filesToAttach) foreach ($filesToAttach as $fileToAttach) {
$filesValues = $form->value($fileToAttach);
if ($filesValues) foreach($filesValues as $fileValues) {
if (isset($fileValues['file'])) {
$filename = $fileValues['file'];
} else {
$filename = ROOT_DIR . $fileValues['path'];
}
try {
$message->attach(\Swift_Attachment::fromPath($filename));
} catch (\Exception $e) {
// Log any issues
$this->grav['log']->error($e->getMessage());
}
}
}
}
// Get CID if embed image -- Added by Michael Connors May 5 2020 PiMedia
if (isset($form->process['embedimages'])) {
$filesToAttach = (array)$form->process['embedimages'];
if ($filesToAttach) foreach ($filesToAttach as $fileToAttach) {
$filename = __DIR__ . $fileToAttach;
try {
$cid = $message->embed(\Swift_Image::fromPath($filename));
$temp = $message->getBody();
$pattern=array();
$pattern[0]='/\"cid:.*?\"/';
$pattern[1]='/\"\[CID\]\"/';
$replacements=array();
$replacements[0] = $replacements[1] = '"'.$cid.'"';
$adjustedBody = preg_replace($pattern, $replacements, $temp);
if (strcmp($temp, $adjustedBody) !== 0) {
$message->setBody($adjustedBody);
}
} catch (\Exception $e) {
// Log any issues
$this->grav['log']->error($e->getMessage());
}
//}
}
}
else {
$this->grav['log']->info('embedimages value is not set');
}
// Send e-mail
$this->email->send($message);
}
'destination' CANNOT be outside user/data/ path
my_file:
name: my_file
label: 'Documents'
type: file
autofocus: false
destination: user/data/uploads
accept:
- application/pdf
- application/x-pdf
- image/png
- text/plain
I don't like to respond to a closed ticket, but I did everything from this procedure and I still don't have an attachment to my email, I just still get an email with this content:
Form label name
- filename
- file_format
- file_size
- file_destination
Grav v1.7.18
Does anyone know the reason?
It doesn't look like the attachment is even added to the outgoing email (from the email log)
Attached Files are uploaded to the server after submit: [ VERIFIED ] Grav Email Logs: [ ON ] Grav Plugin: Email v3.0.8 Grav Plugin: Form v4.0.8 Email Sent: [ YES ]
Could You Please point me in ANY direction, Im stumped.
Grav Email Log
++ Starting Swift_SmtpTransport << 220 smtp.gmail.com ESMTP o94sm407806qtd.34 - gsmtp >> EHLO careercoachplus.ca << 250-smtp.gmail.com at your service, [XX.XX.XX.XX] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 >> STARTTLS << 220 2.0.0 Ready to start TLS >> EHLO careercoachplus.ca << 250-smtp.gmail.com at your service, [XX.XX.XX.XX] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 >> AUTH LOGIN << 334 VXNlcm5hbWU6 >> cGltZWRvvpYS5jYUBnbWFpbC5jb20= << 334 UGFzc3dvcmQ6 >> cmVubzI2NDc= << 235 2.7.0 Accepted ++ Swift_SmtpTransport started >> MAIL FROM:<mygmail@gmail.com> >> RCPT TO:<somerecipeint@gmail.com> >> RCPT TO:<somerecipient@gmail.com> >> DATA << 250 2.1.0 OK o94sm407806qtd.34 - gsmtp << 250 2.1.5 OK o94sm407806qtd.34 - gsmtp << 250 2.1.5 OK o94sm407806qtd.34 - gsmtp << 354 Go ahead o94sm407806qtd.34 - gsmtp >> . << 250 2.0.0 OK 1588735833 o94sm407806qtd.34
form.md
System.yaml
Form.html.twig