How do I send email to user (with pdf attachment) when a form is submitted?
Permalink
Hello,
I have a simple form (firstname, lastname, email). When the form is completed I'd like to send an email with an attached pdf to the entered email address.
I tried entering the code below into the controller.php but no email was sent as far as I can see.
Any ideas very much appreciated.
Thanks
P
I have a simple form (firstname, lastname, email). When the form is completed I'd like to send an email with an attached pdf to the entered email address.
I tried entering the code below into the controller.php but no email was sent as far as I can see.
Any ideas very much appreciated.
Thanks
P
public function action_send() { $bodyHTML = '<p>This is the body of the email.</p>'; $mh = Loader::helper('mail'); $mh->to('xxxxx@xxxxxxx.com'); $mh->from('my@companyemail.com'); $mh->setSubject(t('Test email')); $mh->setBodyHTML($bodyHTML); @$mh->sendMail(); }
Unfortunately, the core mail functiions cannot send attachments so the solution would be more involved. There are several good form Form add-ons in the marketplace that will do this (I think).
Hello mhawake,
Thanks.
I'll have a look around for an add on to do the job.
P
Thanks.
I'll have a look around for an add on to do the job.
P
Hello mhawke,
Is there any reason why the code above should not work for sending an email (without an attachment) to the person who has completed the form? I might just have to provide a link to the pdf in the email as I can't find a 5.7 add on that will do it for me.
Thanks
P
Is there any reason why the code above should not work for sending an email (without an attachment) to the person who has completed the form? I might just have to provide a link to the pdf in the email as I can't find a 5.7 add on that will do it for me.
Thanks
P
I may have spoken too soon regarding the ability to send attachments. Let me have a look under the hood and see what's there.
I just found this.
http://stackoverflow.com/questions/29949776/concrete5-5-7-using-fil...
Using this, I have an email sending on page load. Just need to get it to send on form submit. Is there a public function that I can use for this?
http://stackoverflow.com/questions/29949776/concrete5-5-7-using-fil...
Using this, I have an email sending on page load. Just need to get it to send on form submit. Is there a public function that I can use for this?
I may just send a download link with the email. But I'm having a few other problems with the fields.
At the moment I have a form in view.php that is completed by the user. Fields include Firstname, Surname, and Email. How do I...
1/ include the Firstname and Surname in the body of the email, and send the email to the Email field? I'm guessing here I need to use this->????
2/ include a link to the brochure url in the body? I can define and display the url of the brochure field using the following code, but I can't figure out how to include this in the Body of the email.
3/ send the email only when a successful form completion has been made and submitted? - I guess I need to use a public function like send() if something like that exists.
Here's the current code in controller.php
Thanks in advance
At the moment I have a form in view.php that is completed by the user. Fields include Firstname, Surname, and Email. How do I...
1/ include the Firstname and Surname in the body of the email, and send the email to the Email field? I'm guessing here I need to use this->????
2/ include a link to the brochure url in the body? I can define and display the url of the brochure field using the following code, but I can't figure out how to include this in the Body of the email.
$brochureurls = $tour->xpath('custom_fields/field[name="brochureurl"]/value'); foreach ($brochureurls as $brochureurl) { echo $brochureurl }
3/ send the email only when a successful form completion has been made and submitted? - I guess I need to use a public function like send() if something like that exists.
Here's the current code in controller.php
$mail = Loader::helper('mail'); $mail->setTesting(false); $mail->setSubject('test-subject'); $mail->setBody('Please download your brochure here - my link goes here'); $mail->to('user@email.com'); $mail->from('company@email.com'); $mail->sendMail();
Thanks in advance
I'm a bit confused. Where is the view.php file you speak of?
Have you given any thought to using an 'External Form' block? Many developers don't like using it because it's not tied into the concrete5 dashboard but I have successfully used it lots of times. There is a very rudimentary 'Test' form already in this block and you can look at the view and controller at /public_html/concrete/blocks/external_form/form.
Have you given any thought to using an 'External Form' block? Many developers don't like using it because it's not tied into the concrete5 dashboard but I have successfully used it lots of times. There is a very rudimentary 'Test' form already in this block and you can look at the view and controller at /public_html/concrete/blocks/external_form/form.