0

I'm studying the Swift Mailer, and wondered if there is someone in here
that is familiar enough with the way it works, that you could give me a little
guidance.

I have a form that I created that allows someone to enter their information
as required, and that works just fine. Once submitted, it generates an email
that is sent to the company, and a copy is sent to the person submitting it.

Currently I am using mail() in a mailing function that I have that isn't related
to Swift Mailer.

I need to give the submitter the opportunity to include 3 documents
(scans of ID Info) by searching their computer for them.

I'm not sure of how to manage this.

Do they upload the documents to the server and then I pick them up
from there to attach to the email?
And if so, would that be a separate process, or can it be done all at the
same time when they submit the form?

If you can't tell, I'm just a little lost on this, which brings me back to the
Swift Mailer. It appears to have just about everything included in it so
it should be easier to accomplish, but just looking for practical experience
with it before I start that venture.

Any feedback would be greatly appreciated.

Thanks in advance,
Douglas

Edited by pritaeas: Moved to PHP

3
Contributors
11
Replies
47
Views
2 Years
Discussion Span
Last Post by diafol
Featured Replies
  • 1
    jkon 491   2 Years Ago

    Lets suppose that the variable name that you keep in session is example . e.g. `$_SESSION["example"] = "something"` . You use it after `session_start()` by `$_SESSION["example"]` , in your case `->setSubject($_SESSION["example"])` . What did you tried and not worked ? Read More

0

OK, I've come to the conclusion that the documents to be attached to an outbound email don't need to even touch the server...

learning one step at a time.

So, I'm back to Swift Mailer.

I have it uploaded to my server and am past the point of doing the require once to utilize it in the script...

Here is the example provided in the Swift Mailer Docs

// Create the message
$message = Swift_Message::newInstance()

  // Give the message a subject
  ->setSubject('Your subject')

  // Set the From address with an associative array
  ->setFrom(array('john@doe.com' => 'John Doe'))

  // Set the To addresses with an associative array
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))

  // Give it a body
  ->setBody('Here is the message itself')

  // And optionally an alternative body
  ->addPart('<q>Here is the message itself</q>', 'text/html')

  // Optionally add any attachments
  ->attach(Swift_Attachment::fromPath('my-document.pdf'))
  ;

and I'm trying to test the basics of it, but here is my question:

I have all of the information - from / to / subject / body / etc already in Session variables.

How do I go about utilizing those session variables in this sample?

Hope that doesn't sound to dumb, but that is where I'm at.

Any help would be appreciated.

0

I'm sort of stabbing in the dark here because I am not understanding something I guess...

I tried replacing this
// Give the message a subject
->setSubject('Your subject')

with this:
// Give the message a subject
->setSubject($_SESSION['email_subject'])

As well as the same structure for each of the other fields,
but I got all sorts of exception errors thrown by swift mailer.

Edited by showman13

0

From what I read. You place the path of the file you want to send in the attach() method as a parameter. This can be an existing file on your server or if allowed by your server, a file on another server.

Usually, the mail form you create will contain file inputs. The enctype attribute for this form must be set to:

<form enctype="multipart/form-data" ...>

The file(s) are uplaoded as temporary files to your server. You have the option of storing them in say an '/uploads' folder etc or not, as the case may be. Say for example that you have saved it, then you can pass on that path to your SwiftMail routine.

 ->attach(Swift_Attachment::fromPath($uploadFile1))
0

Hey Diafol, Thanks for the response.

I'm beginning to develop an understanding of that process, but the one thing that seems to be standing in my way is an understanding of how to do this...

if this is what I need to do:
// Give the message a subject
->setSubject('Your subject')

how do I make that assignment if the 'Your subject' is currently stored in a session variable as opposed to being hard coded as it shows.?
->setSubject(' session variable? ')

0

thanks for the response jkon, but I have no clue what the link you suggested I read has to do with the actual question I asked.

I know how to use session variables... I use them all the time.

what I don't know is how to do the object assignment with the value that is contained in the session variable.

1

Lets suppose that the variable name that you keep in session is example . e.g. $_SESSION["example"] = "something" . You use it after session_start() by $_SESSION["example"] , in your case ->setSubject($_SESSION["example"]) . What did you tried and not worked ?

Edited by jkon: inline code

Votes + Comments
The double quote around the variable name was the key... thanks
0

I tried replacing this
// Give the message a subject
->setSubject('Your subject')

with this:
// Give the message a subject
->setSubject($_SESSION['email_subject'])

As well as the same structure for each of the other fields,
but I got all sorts of exception errors thrown by swift mailer.

0

Good Morning Diafol...

I'm guessing that the print_r($_SESSION) is intended to see that I have values in the session variables, etc.

I have a little utility script that I use during development that when I turn it on, it displays all the session and request variables and their values on the bottom of each displayed page...

The values are there and all are correct.

After hours of banging my head against the wall, I think I finally got lucky and realized that JKON's example was using "double" quotes instead of 'single' quotes around the session variable name ->setSubject($_SESSION["example"])

I've always used single quotes so I never gave it a thought. But in desperation, I changed them all to double quotes, and that part of the problem went away... No more exception errors from swift mailer.

I don't understand it, but there it is.

That took me through to the next challenge to address, which I've been working on, but doesn't really fall within the scope of this thread, so if I can't figure it out soon, I may start another one. I do always try to find the answers first, to a point of frustration before coming here to ask for help.

Thanks for your feedback

And Thank you to JKON for the response that ultimately got me past that issue.
If someone could explain why it worked, I would certainly appreciate it and it might stick with me better, with that lesson.

Wish Me Luck...
Douglas

0

OK, I can't see how double quotes or single quotes should make a difference, and I0 can't see where jkon suggests you do so. But if it works, great.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.