Jump to content

ryanC

Members
  • Posts

    97
  • Joined

  • Last visited

Everything posted by ryanC

  1. Hi, I am getting close to finishing the form I've been working on. My goal is to have users upload an image in the form, and have that image be sent along with the rest of the email content. Taking code from a suggested thread, I am able to get the user uploaded image into my assets folder (which is in the code below). So I can at least receive the image... but I would like for that image to be sent in the content of the email instead. Would I be able to modify my code to do that? The section of the script that sends the image to the assets folder starts with //image upload begin: <?php $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); $email .= $_REQUEST['email']; if (isset($_POST['submit']) and ($_POST['email']) and ($_POST['comments']) ) { //image upload begin $upload_path = $config->paths->assets . "files/useruploads/"; $user_image = new WireUpload('user_image'); // References the name of the field in the HTML form that uploads the photo $user_image->setMaxFiles(5); $user_image->setOverwrite(false); $user_image->setDestinationPath($upload_path); $user_image->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); // execute upload and check for errors $files = $user_image->execute(); //image upload end $to = 'me@email.com'; $subject = 'Feedback from my site'; $message = 'Name: ' . $sanitizer->text($input->post->name) . "\r\n\r\n"; $message .='Email: ' . $sanitizer->email($input->post->email) . "\r\n\r\n"; $comments = $sanitizer->entities($sanitizer->textarea($input->post->comments)); $message .= 'Comments: ' . $comments; $success = $email; $success .=$message; $mail = wireMail(); $mail->to($to)->from('me@email.com'); $mail->subject($subject); $mail->body($message); $mail->send(); } else { header("location: error-page"); exit; } ?> <form id="option3form" action="./" method="post" enctype="multipart/form-data" target="_blank"> <label for="name">Name: </label> <input type="text" name="name" id="name"> <label for="email">Email: </label> <input type="email" name="email" id="email"><br /><br /> <label for="comments">Comments: </label> <textarea name="comments" id="comments"></textarea><br /><br /> <p>Click the "Choose File" button below to upload your image.</p> <input type="file" name="user_image" /> <input type="submit" name="submit" value="Submit"> </form> Thanks!
  2. Thanks szabesz, for the code and the link. I've noticed the Gmails are coming in regularly again, so I guess that part is out of my hands. I've gotten the form working and sending emails, thanks to the help from you guys so I'm going to mark this as solved. I will probably be back asking more about wireMail at some point, but that would be for a different thread.
  3. Hi, thanks for all the help in this thread. I have been reading the links and have made some good progress. I have been able to receive the email I was trying to get two ways. I will explain what I did in case it helps someone else, and then my follow up questions will be at the end. First I tried to use the complete form from: https://processwire.com/talk/topic/407-processing-contact-forms/ But was running into ‘forbidden’ errors. So I did some searching and was able to get my original php mail code to work by just placing the script outside of the processwire install: @adrian said: That worked right away, but I still wanted to do it all within Processwire itself. Even though I wasn’t able to get around the forbidden errors, I was able to follow along enough to adapt my own form to receive the email. 1: created a template that contained the html form content, and had the form post to itself (action=“./“). 2: at the top of the template I included a link to the form script: <?php if($input->post->submit) { include("./includes/form-script.php"); } else { // output contact form } ?> 3: created a blank page based on the template in step 1. Form posts to itself, submit button pulls the form script from a separate include file, email sent, mission accomplished. This is the code I am using that DOES work: <?php $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); if (isset($_POST['submit'])) { $to = 'myemail@.com'; $subject = 'Feedback from my site'; $message = 'Name: ' . $sanitizer->text($input->post->name) . "\r\n\r\n"; $message .='Email: ' . $sanitizer->email($input->post->email) . "\r\n\r\n"; $message .='Comments: ' .$sanitizer->text($input->post->comments); $success = $email; //if $success gives you a “Thank you” message $mail = wireMail(); $mail->to($to); $mail->subject($subject); $mail->body($message); $mail->send(); } ?> Question 1: placing the form script outside of processwire in order to get the email was pretty easy, how secure is that approach? Question 2: My code above is a hybrid of the posts from this thread. Do I have it set up correctly, and in a secure way? I am still getting my head around wireMail and sanitization. Question 3: I am using MAMP, and my account is gmail. My emails are not coming in until 15-25 minutes later, is it likely this is just on Gmail's end? I am still going to try to use some of the forms that have been provided from others but this is where I’m at right now. Thanks!
  4. Thanks sbazesz, that link looks extremely helpful, exactly the type of thing I'm looking for. I will see about integrating it, if I have more specific questions about that I will probably have some follow-up questions. I'm starting to get a better feel for Processwire in general, when I first started my test site I wanted to give up, now I have multiple templates, have hanna running, a search form, all that good stuff. So I'm sure I will get this down too.
  5. Well this started by me following along with an online tutorial, https://learning.linkedin.com/blog/tech-tips/send-email-from-a-web-form-with-php The code below is the working example of the form, that I have running on my desktop/htdocs (real email in my desktop version). Processwire not involved yet: <?php $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); if($email) { $headers .="\r\nReply-To: $email"; } $headers = "From: me@email.com\r\n"; $headers .= 'Content-Type: text/plain; charset=utf-8'; if (isset($_POST['submit'])) { $to = 'me@email.com'; $subject = 'Feedback from my site'; $message = 'Name: ' . $_POST['name'] . "\r\n\r\n"; $message .='Email: ' . $_POST['email'] . "\r\n\r\n"; $message .='Comments: ' .$_POST['comments']; $success = mail($to, $subject, $message, $headers, '-me@email.com'); } ?> ( $email I believe was there to make sure validation went through, along with $headers. ) So the goal was to take the above code and get it to work in Processwire, which started the thread. The final result is the code you just tested, which has the wireMail stuff added to it, which has come from this thread. So now I'm full circle trying to adapt the above code into something Processwire can use. Regarding the pages, the HTML Form itself is a page that is based on my main template. When I hit submit, it goes to a page called "form-response-1", which is based on a new template called "form-response-template.php". This is literally the entire template for "form-response-template.php" <?php $myPath = $config->urls->templates;?> <?php $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); if (isset($_POST['submit'])) { $to = 'me@email.com'; $subject = 'Feedback from my site'; $message = 'Name: ' . $_POST['name'] . "\r\n\r\n"; $message .='Email: ' . $_POST['email'] . "\r\n\r\n"; $message .='Comments: ' .$_POST['comments']; $mail = wireMail(); $mail->to($to)->from('me@email.com'); // all calls can be chained $mail->subject($subject); $mail->body($message); $mail->send(); } ?> <!DOCTYPE HTML> <html> <head> <base href="<?= $myPath ?>" /> <title><?php echo $page->title; ?></title> </head> <body> <h1>Information Received.</h1> <p>Thank you.</p> <!--orig--> <?php if (isset($success) && $success) { ?> <h1>Thank You</h1> Your message has been sent. <?php } else { ?> <h1>Not Received</h1> <p>Sorry, there was a problem sending your message.</p> <?php } ?> <main> <?php echo $page->page_content; ?> </main> </body> </html> That's about the extent of what I am understanding regarding all of this. I really appreciate your help here. Edit-I should add that when I hit "submit", the form result page does come up in my browser, so that part of the sequence works.
  6. <div class="formWrap"> <h1>Simple Email Form 1</h1> <p><em>Most basic form possible to get email response in processwire</em></p> <form id="simpleForm1" action="http://localhost:8888/signage-B/form-response-1" method="post" target="_blank"> <label for="name">Name:</label> <input type="text" name="name" id="name"> <label for="email">Email:</label> <input type="email" name="email" id="email"><br /><br /> <label for="comments">Comments:</label> <textarea name="comments" id="comments"></textarea> <div class="submission-test"> <input type="submit" name="submit" value="submit"> </div> </form> </div> <?php $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); if (isset($_POST['submit'])) { $to = 'me@email.com'; $subject = 'Feedback from my site'; $message = 'Name: ' . $_POST['name'] . "\r\n\r\n"; $message .='Email: ' . $_POST['email'] . "\r\n\r\n"; $message .='Comments: ' .$_POST['comments']; $mail = wireMail(); $mail->to($to)->from('me@email.com'); // all calls can be chained $mail->subject($subject); $mail->body($message); $mail->send(); } ?> Ok, updated code... is " $mail->send(); " affected by the other things being called "submit"? Also, after doing the updates I no longer see "Input POST" in the request info area. It was there before, but all I see is "Input GET" now.
  7. That's right, I had it as submit first but was experimenting with making it "send", but didn't update the "isset" part. Is it better to use send or submit, or does it make a difference?
  8. sure, this is for the results page: <?php $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); if (isset($_POST['submit'])) { $to = 'me@email.com'; $subject = 'Feedback from my site'; $message = 'Name: ' . $_POST['name'] . "\r\n\r\n"; $message .='Email: ' . $_POST['email'] . "\r\n\r\n"; $message .='Comments: ' .$_POST['comments']; $mail = wireMail(); $mail->to($to)->from('me@email.com'); // all calls can be chained $mail->subject($subject); $mail->body($message); $mail->send(); } ?> form page: <div class="formWrap"> <h1>Simple Email Form 1</h1> <p><em>Most basic form possible to get email response in processwire</em></p> <form id="simpleForm1" action="http://localhost:8888/signage-B/form-response-1" method="post" target="_blank"> <label for="name">Name:</label> <input type="text" name="name" id="name"> <label for="email">Email:</label> <input type="email" name="email" id="email"><br /><br /> <label for="comments">Comments:</label> <textarea name="comments" id="comments"></textarea> <div class="submission-test"> <input type="submit" name="send" value="Submit"> </div> </form> </div>
  9. So I guess now it's either the PHP for my form, or the SMTP settings.
  10. WireMail SMTP, I have entires for: localhost, SMTP hostname, SMTP Port, SMTP user, SMTP password, Use SSL, SMTP Certificate... I'm assuming Sender Email Address is my own? That is in there also... so with those settings I get "Success! SMTP Settings appear to work correctly"
  11. It is on Front End now, so everything you did with the update was successful. I do have WireMailSMTP installed, and after entering Gmail settings it said it the settings were correct. Let me open up the module..
  12. Ok... looks like we were successful here. I didn't submit but now we are up to date. Site is not live yet, and I don't have SessionHandlerDB installed.
  13. Oops, I missed a step! I didn't "submit" when I selected Backend. Now I see the AJAX bar. That extra code was just the console showing me page names, I'm sure it's supposed to do that.
  14. Something new happened though when I hit "run" for the email test. The console has a bunch of code there now, I didn't see that before. Actually I guess that's the default behavior for the Page view, earlier I was on the module page itself.
  15. Ok... PHP 5.610. Updated to Tracy 4.6.29... Have selected backend... Looking at all my pages and it's still just the TRACY bar by itself.
  16. Ok, I disabled the snippet runner panel, the errors are gone but no AJAX bar or sent email yet. This is a screenshot of everything I have:
  17. Hi Adrian, no AJAX bar, so far I've only seen the green mail interceptor panel. I'm attaching a screenshot of what I have now:
  18. Thanks szabesz! I appreciate your help, I'm still learning stuff I wouldn't have known otherwise here.
  19. Hi--I have the sticky button selected here, same result... Do I need to deselect the other options?
  20. Ok I have TracyDebugger going, have the Mail Interceptor up, entered the code with my email address and it says "No Emails Sent".
  21. Thanks szabesz--I will give Tracy DeBugger a shot, and see if emails are working at all.
×
×
  • Create New...