CarlosEduardo2409 Posted October 10, 2017 Report Posted October 10, 2017 Hello everyone, so I'm trying to make a module for the pilots to send suggestions of routes. But when I click to send it it does not send the email. My core/templates/routesubmit_mainform.php - MY BUTTON CODE <input type="submit" class="btn btn-primary btn-block btn-flat" name="submit" value='Submit Route'> My core/modules/RouteSubmit.php - MY SENDEMAIL CODE <?php class RouteSubmit extends CodonModule { public function index() { require_once CORE_LIB_PATH.'/recaptcha/recaptchalib.php'; $this->set('title', 'Add Schedule'); $this->set('allairlines', OperationsData::GetAllAirlines()); $this->set('allaircraft', OperationsData::GetAllAircraft()); $this->set('allairports', OperationsData::GetAllAirports()); //$this->set('airport_json_list', OperationsData::getAllAirportsJSON()); $this->set('flighttypes', Config::Get('FLIGHT_TYPES')); if(isset($_POST['submit'])) { $this->SendEmail(); } else { $this->ShowForm(); } $this->render('routesubmit/routesubmit_mainform'); } protected function ShowForm() { //Google reCaptcha //updated to Google noCaptcha 1/15 $this->set('sitekey', "MyCaptchaKey"); $this->set('lang', 'pt'); } public function SendEmail() { $name = $_POST['name']; $email = $_POST['email']; $depp = $_POST['depp']; $arr = $_POST['arr']; $route = $_POST['route']; $aircraft = $_POST['Aircraft']; $fl = $_POST['fl']; $dtime = $_POST['dtime']; $atime = $_POST['atime']; $ftime = $_POST['ftime']; $message = "From: $name \n Depp: $depp \n Arr: $arr \n Route: $route \n Aircraft: $aircraft \n Fl: $fl \n Dtime: $dtime \n Atime: $atime \n Ftime: $ftime \n"; $email_to = "MYEMAIL"; $subject = "Pilot Submitted Route"; $headers = "From: $email \r\n"; Util::SendEmail($email_to, $subject, $message, $mailheader); } } Quote
mischka Posted October 11, 2017 Report Posted October 11, 2017 in your send_email I see: $email = $_POST['email']; then later I see $email_to = "MYEMAIL"; which you then use to send the email I would delete the second line and rewrite the first one to $email_to = $_POST['email']; and see where that goes. Quote
Moderators servetas Posted October 11, 2017 Moderators Report Posted October 11, 2017 $email is the pilot's email. The pilot who is sending the route request. $email_to is where the route request is sent to. I do not believe that this is an issue. First of all, instead of using this: $_POST['email'] you will have to use this: $this->post->email You will have to do so with all the variables in the SendEmail and index function. Also, your form should include a captcha but I can see that there is not any captcha validation in the SendEmail function. I would suggest removing it from your form or validating in on the form submit. Personally, I would suggest you to add several random echo's in your code. As soon as you run your code, you will be able to understand (based on the echo's) which part of the code run and which part of the code did not run. Quote
CarlosEduardo2409 Posted October 11, 2017 Author Report Posted October 11, 2017 (edited) Did you mean like that? public function SendEmail() { $name = $this->post->name; $email_from = $this->post->email; $depp = $this->post->depp; $arr = $this->post->arr; $route = $this->post->route; $Aircraft = $this->post->Aircraft; $fl = $this->post->fl; $dtime = $this->post->dtime; $atime = $this->post->atime; $ftime = $this->post->ftime; $message = "From: $name \n Depp: $depp \n Arr: $arr \n Route: $route \n Aircraft: $aircraft \n Fl: $fl \n Dtime: $dtime \n Atime: $atime \n Ftime: $ftime \n"; $email = "MYEMAIL"; $subject = "Pilot Submitted Route"; $headers = "From: $email_from \r\n"; Util::SendEmail($email, $subject, $message, $headers); } If you want to see my entire code: https://github.com/carlosmfreitas2409/RouteSubmit Edited October 11, 2017 by CarlosEduardo2409 Quote
Moderators servetas Posted October 12, 2017 Moderators Report Posted October 12, 2017 Yes, did it work? Quote
CarlosEduardo2409 Posted October 12, 2017 Author Report Posted October 12, 2017 (edited) No, if you want to see my whole code, it's in the message above Edited October 12, 2017 by CarlosEduardo2409 Quote
Moderators servetas Posted October 12, 2017 Moderators Report Posted October 12, 2017 Try this as a good start: https://github.com/carlosmfreitas2409/RouteSubmit/compare/master...phpmods:patch-1 Quote
CarlosEduardo2409 Posted October 12, 2017 Author Report Posted October 12, 2017 Thank you, but I'll test it soon, I'm not on the computer now Quote
CarlosEduardo2409 Posted October 12, 2017 Author Report Posted October 12, 2017 (edited) - Edited October 15, 2017 by CarlosEduardo2409 Quote
CarlosEduardo2409 Posted October 15, 2017 Author Report Posted October 15, 2017 (edited) Now I fully updated the codes, and it's still not working, I looked in google, I did everything, but nothing ... (Using Gmail and PhpVMS 5.5 Simpilot) Code: https://github.com/carlosmfreitas2409/RouteSubmit Edited October 15, 2017 by CarlosEduardo2409 Quote
Members Vangelis Posted October 15, 2017 Members Report Posted October 15, 2017 I am also looking into it as it is not working on my server aswell Quote
CarlosEduardo2409 Posted October 15, 2017 Author Report Posted October 15, 2017 (edited) Can you tell me when it works? I'm trying to do everything I can to fix it, too. Thank you. If I do, I'll tell you... Sorry if I wrote something wrong, because I'm using google translate. I am Brazilian Edited October 15, 2017 by CarlosEduardo2409 Quote
Moderators servetas Posted October 18, 2017 Moderators Report Posted October 18, 2017 I have made a few changes: core/modules/RouteSubmit/RouteSubmit.php: First of all, the "RouteSubmit.php" file should be placed in a folder titled "RouteSubmit" under the modules section. Replaces its contents with the following: <?php class RouteSubmit extends CodonModule { public $title = "RouteSubmit Request"; public function index() { if (!Auth::LoggedIn()) { $this->set('error', 'You are not logged in.'); $this->show('core_error'); } else { $this->set('allairlines', OperationsData::GetAllAirlines()); $this->set('allaircraft', OperationsData::GetAllAircraft()); $this->set('allairports', OperationsData::GetAllAirports()); //$this->set('airport_json_list', OperationsData::getAllAirportsJSON()); $this->set('flighttypes', Config::Get('FLIGHT_TYPES')); $this->render('routesubmit/routesubmit_index'); } } public function submit() { if ($this->post->arr == '') { $this->set('error', 'You haven\'t specified a reason for your leaeve of absence.'); $this->render('routesubmit/routesubmit_error'); $this->render('routesubmit/routesubmit_index'); } else { $this->sendmail($data); } } protected function sendmail($data) { // Form arrays $name = $this->post->name; $from = $this->post->email; $depp = $this->post->depp; $arr = $this->post->arr; $route = $this->post->route; $aircraft = $this->post->Aircraft; $fl = $this->post->fl; $dtime = $this->post->dtime; $atime = $this->post->atime; $ftime = $this->post->ftime; // Send email to admin $subject_admin = SITE_NAME.' A pilot has submitted a Route Request'; $email_admin = 'your_email_or_ADMIN_EMAIL'; $message = "From: $name | $from \n Departure: $depp \n Arrival: $arr \n Route: $route \n Aircraft: $aircraft \n Flight level: $fl \n Departure time: $dtime \n Arrival time: $atime \n Flight time: $ftime \n Essa mensagem automatica, por favor não responder"; if ($_POST['submit']) { Util::SendEmail($email_admin, $subject_admin, $message); // Show the template $this->render('routesubmit/routesubmit_submitted'); } } } Also, put the template files within a "routesubmit" folder too within the core/templates folder. Also, update the routesubmit_index.php file with this: <?php if(!defined('IN_PHPVMS') && IN_PHPVMS !== true) { die(); } ?> <body class="hold-transition login-page" style="background-color: #222222;"> <form action="<?php echo url('/routesubmit/submit');?>" method="post"> <div class="login-box"> <div class="login-logo"> <a href="" style="color: white;">Route<b>Submit</b></a> </div> <!-- /.login-logo --> <div class="login-box-body"> <p class="login-box-msg" style="font-size: 13px;">Please complete this form to send your route.</p> <form method="post" action="<?php echo url('/routesubmit/submit');?>"> <div class="form-group" align="center"> <tr> <td><strong>Name:</strong></td> <td> <?php if(Auth::LoggedIn()) { echo Auth::$userinfo->firstname .' '.Auth::$userinfo->lastname; echo '<input type="hidden" name="name" value="'.Auth::$userinfo->firstname .' '.Auth::$userinfo->lastname.'" />'; } else { ?> <input type="text" name="name" value="" /> <?php } ?> </td> </tr> </div> <div class="form-group" align="center"> <tr> <td width="1%" nowrap><strong>Endereço de E-mail:</strong></td> <td> <?php if(Auth::LoggedIn()) { echo Auth::$userinfo->email; echo '<input type="hidden" name="name" value="'.Auth::$userinfo->email.'" />'; } else { ?> <input type="text" name="email" value="" /> <?php } ?> </td> </tr> </div> <div class="form-group"> <input type="text" name="depp" class="form-control" value="<?php echo Vars::POST('lastname');?>" placeholder="Departure ICAO"> <?php if($departure_error == true) echo '<p class="error">Please enter your departure ICAO</p>'; ?> </div> <div class="form-group"> <input type="text" name="arr" class="form-control" placeholder="Arrival ICAO"> <?php if($arrival_error == true) echo '<p class="error">Please enter your arrival ICAO</p>'; ?> </div> <div class="form-group"> <input type="text" name="route" class="form-control" placeholder="Route"> <?php if($route_error == true) echo '<p class="error">Please enter your route</p>'; ?> </div> <div class="form-group"> <select name="Aircraft" class="form-control"> <option value=" ">Select your aircraft</option> <option value="2">Airbus</option> <option>Airbus A318-111</option> <option>Airbus A319-111</option> <option>Airbus A320-211</option> <option>Airbus A321-211</option> <option value="2">Boeing</option> <option>Boeing 737-800/W</option> <option>Boeing 737-900/W</option> <option>Boeing 747-400</option> <option>Boeing 747-400F</option> <option>Boeing 747-800I</option> <option>Boeing 757-200</option> <option>Boeing 767-300</option> <option>Boeing 777-200LR</option> <option>Boeing 777-300ER</option> <option>Boeing 777-200F</option> <option value="3">De Havilland</option> <option>DHC-8-400</option> <option value="4">McDonnell Douglas</option> <option>MD-11</option> <option>MD-11F</option> </select> <?php if($aircraft_error == true) echo '<p class="error">Please enter your aircraft</p>'; ?> </div> <div class="form-group"> <input type="text" name="fl" class="form-control" placeholder="Flight level"> <?php if($flightlevel_error == true) echo '<p class="error">Please enter your flight level</p>'; ?> </div> <div class="form-group"> <input type="text" name="dtime" class="form-control" placeholder="Departure Time"> <?php if($departuretime_error == true) echo '<p class="error">Please enter your departure time</p>'; ?> </div> <div class="form-group"> <input type="text" name="atime" class="form-control" placeholder="Arrival Time"> <?php if($arrivaltime_error == true) echo '<p class="error">Please enter your arrival time</p>'; ?> </div> <div class="form-group"> <input type="text" name="ftime" class="form-control" placeholder="Flight Time"> <?php if($flighttime_error == true) echo '<p class="error">Please enter your flight time</p>'; ?> </div> <input type="hidden" name="loggedin" value="<?php echo (Auth::LoggedIn())?'true':'false'?>" /> <input id="submit" type="submit" class="btn btn-success" class="btn btn-primary btn-block btn-flat" name="submit" value='Submit Route'> </td> <!-- /.col --> </tr> </form> </div> <!-- /.login-box-body --> </div> <!-- /.login-box --> Copyright © <?php echo date(Y); ?> CCBS Virtual Airlines - All Rights Reserved <!-- iCheck --> <script src="<?php echo SITE_URL?>/lib/skins/crewcenter/plugins/iCheck/icheck.min.js"></script> <script> $(function () { $('input').iCheck({ checkboxClass: 'icheckbox_square-blue', radioClass: 'iradio_square-blue', increaseArea: '20%' // optional }); }); </script> It worked in my localhost server (do not comment the values ): Quote From: pilot_submitted_email | Departure: dsadsad Arrival: sadsadsa Route: dsad Aircraft: Flight level: dsadsa Departure time: dsa Arrival time: dsads Flight time: adsa Essa mensagem automatica, por favor não responder Let us know in case you have any issues. Quote
CarlosEduardo2409 Posted October 18, 2017 Author Report Posted October 18, 2017 1 hour ago, servetas said: I have made a few changes: core/modules/RouteSubmit/RouteSubmit.php: First of all, the "RouteSubmit.php" file should be placed in a folder titled "RouteSubmit" under the modules section. Replaces its contents with the following: <?php class RouteSubmit extends CodonModule { public $title = "RouteSubmit Request"; public function index() { if (!Auth::LoggedIn()) { $this->set('error', 'You are not logged in.'); $this->show('core_error'); } else { $this->set('allairlines', OperationsData::GetAllAirlines()); $this->set('allaircraft', OperationsData::GetAllAircraft()); $this->set('allairports', OperationsData::GetAllAirports()); //$this->set('airport_json_list', OperationsData::getAllAirportsJSON()); $this->set('flighttypes', Config::Get('FLIGHT_TYPES')); $this->render('routesubmit/routesubmit_index'); } } public function submit() { if ($this->post->arr == '') { $this->set('error', 'You haven\'t specified a reason for your leaeve of absence.'); $this->render('routesubmit/routesubmit_error'); $this->render('routesubmit/routesubmit_index'); } else { $this->sendmail($data); } } protected function sendmail($data) { // Form arrays $name = $this->post->name; $from = $this->post->email; $depp = $this->post->depp; $arr = $this->post->arr; $route = $this->post->route; $aircraft = $this->post->Aircraft; $fl = $this->post->fl; $dtime = $this->post->dtime; $atime = $this->post->atime; $ftime = $this->post->ftime; // Send email to admin $subject_admin = SITE_NAME.' A pilot has submitted a Route Request'; $email_admin = 'your_email_or_ADMIN_EMAIL'; $message = "From: $name | $from \n Departure: $depp \n Arrival: $arr \n Route: $route \n Aircraft: $aircraft \n Flight level: $fl \n Departure time: $dtime \n Arrival time: $atime \n Flight time: $ftime \n Essa mensagem automatica, por favor não responder"; if ($_POST['submit']) { Util::SendEmail($email_admin, $subject_admin, $message); // Show the template $this->render('routesubmit/routesubmit_submitted'); } } } Also, put the template files within a "routesubmit" folder too within the core/templates folder. Also, update the routesubmit_index.php file with this: <?php if(!defined('IN_PHPVMS') && IN_PHPVMS !== true) { die(); } ?> <body class="hold-transition login-page" style="background-color: #222222;"> <form action="<?php echo url('/routesubmit/submit');?>" method="post"> <div class="login-box"> <div class="login-logo"> <a href="" style="color: white;">Route<b>Submit</b></a> </div> <!-- /.login-logo --> <div class="login-box-body"> <p class="login-box-msg" style="font-size: 13px;">Please complete this form to send your route.</p> <form method="post" action="<?php echo url('/routesubmit/submit');?>"> <div class="form-group" align="center"> <tr> <td><strong>Name:</strong></td> <td> <?php if(Auth::LoggedIn()) { echo Auth::$userinfo->firstname .' '.Auth::$userinfo->lastname; echo '<input type="hidden" name="name" value="'.Auth::$userinfo->firstname .' '.Auth::$userinfo->lastname.'" />'; } else { ?> <input type="text" name="name" value="" /> <?php } ?> </td> </tr> </div> <div class="form-group" align="center"> <tr> <td width="1%" nowrap><strong>Endereço de E-mail:</strong></td> <td> <?php if(Auth::LoggedIn()) { echo Auth::$userinfo->email; echo '<input type="hidden" name="name" value="'.Auth::$userinfo->email.'" />'; } else { ?> <input type="text" name="email" value="" /> <?php } ?> </td> </tr> </div> <div class="form-group"> <input type="text" name="depp" class="form-control" value="<?php echo Vars::POST('lastname');?>" placeholder="Departure ICAO"> <?php if($departure_error == true) echo '<p class="error">Please enter your departure ICAO</p>'; ?> </div> <div class="form-group"> <input type="text" name="arr" class="form-control" placeholder="Arrival ICAO"> <?php if($arrival_error == true) echo '<p class="error">Please enter your arrival ICAO</p>'; ?> </div> <div class="form-group"> <input type="text" name="route" class="form-control" placeholder="Route"> <?php if($route_error == true) echo '<p class="error">Please enter your route</p>'; ?> </div> <div class="form-group"> <select name="Aircraft" class="form-control"> <option value=" ">Select your aircraft</option> <option value="2">Airbus</option> <option>Airbus A318-111</option> <option>Airbus A319-111</option> <option>Airbus A320-211</option> <option>Airbus A321-211</option> <option value="2">Boeing</option> <option>Boeing 737-800/W</option> <option>Boeing 737-900/W</option> <option>Boeing 747-400</option> <option>Boeing 747-400F</option> <option>Boeing 747-800I</option> <option>Boeing 757-200</option> <option>Boeing 767-300</option> <option>Boeing 777-200LR</option> <option>Boeing 777-300ER</option> <option>Boeing 777-200F</option> <option value="3">De Havilland</option> <option>DHC-8-400</option> <option value="4">McDonnell Douglas</option> <option>MD-11</option> <option>MD-11F</option> </select> <?php if($aircraft_error == true) echo '<p class="error">Please enter your aircraft</p>'; ?> </div> <div class="form-group"> <input type="text" name="fl" class="form-control" placeholder="Flight level"> <?php if($flightlevel_error == true) echo '<p class="error">Please enter your flight level</p>'; ?> </div> <div class="form-group"> <input type="text" name="dtime" class="form-control" placeholder="Departure Time"> <?php if($departuretime_error == true) echo '<p class="error">Please enter your departure time</p>'; ?> </div> <div class="form-group"> <input type="text" name="atime" class="form-control" placeholder="Arrival Time"> <?php if($arrivaltime_error == true) echo '<p class="error">Please enter your arrival time</p>'; ?> </div> <div class="form-group"> <input type="text" name="ftime" class="form-control" placeholder="Flight Time"> <?php if($flighttime_error == true) echo '<p class="error">Please enter your flight time</p>'; ?> </div> <input type="hidden" name="loggedin" value="<?php echo (Auth::LoggedIn())?'true':'false'?>" /> <input id="submit" type="submit" class="btn btn-success" class="btn btn-primary btn-block btn-flat" name="submit" value='Submit Route'> </td> <!-- /.col --> </tr> </form> </div> <!-- /.login-box-body --> </div> <!-- /.login-box --> Copyright © <?php echo date(Y); ?> CCBS Virtual Airlines - All Rights Reserved <!-- iCheck --> <script src="<?php echo SITE_URL?>/lib/skins/crewcenter/plugins/iCheck/icheck.min.js"></script> <script> $(function () { $('input').iCheck({ checkboxClass: 'icheckbox_square-blue', radioClass: 'iradio_square-blue', increaseArea: '20%' // optional Funcionou no meu servidor localhost (não comente os valores ): Deixe-nos saber se você tiver algum problema. It did not work for me. Quote
Moderators servetas Posted October 19, 2017 Moderators Report Posted October 19, 2017 Try to add echoes in several part of the code. Different echoes. After that, run the module and check when echoes stopped showing. That is the best I can suggest in order to troubleshoot the reason why it is not running correctly. Does your website generally sends emails without issues? Quote
CarlosEduardo2409 Posted October 19, 2017 Author Report Posted October 19, 2017 Yes, send, all emails that have been configured by phpVMS or addon's are sent Quote
CarlosEduardo2409 Posted October 21, 2017 Author Report Posted October 21, 2017 This is the my new code: core/modules/RouteSubmit/RouteSubmit.php <?php class RouteSubmit extends CodonModule { public $title = "RouteSubmit Request"; public function index() { if (!Auth::LoggedIn()) { $this->set('error', 'You are not logged in.'); $this->show('core_error'); } else { $this->set('allairlines', OperationsData::GetAllAirlines()); $this->set('allaircraft', OperationsData::GetAllAircraft()); $this->set('allairports', OperationsData::GetAllAirports()); //$this->set('airport_json_list', OperationsData::getAllAirportsJSON()); $this->set('flighttypes', Config::Get('FLIGHT_TYPES')); $this->render('routesubmit/routesubmit_index'); } } public function submit() { if(isset($_POST['submit'])) { if ($this->post->arr == '') { $this->set('error', 'You haven\'t specified a reason for your leaeve of absence.'); $this->render('routesubmit/routesubmit_error'); $this->render('routesubmit/routesubmit_index'); } else { $this->sendmail(); } } } protected function sendmail() { // Form arrays $name = $this->post->name; $from = $this->post->email; $depp = $this->post->depp; $arr = $this->post->arr; $route = $this->post->route; $aircraft = $this->post->Aircraft; $fl = $this->post->fl; $dtime = $this->post->dtime; $atime = $this->post->atime; $ftime = $this->post->ftime; // Send email to admin $subject = SITE_NAME.' A pilot has submitted a Route Request'; $email = 'carlosmfreitas05@gmail.com'; $message = 'From: $name | $from \n Departure: $depp \n Arrival: $arr \n Route: $route \n Aircraft: $aircraft \n Flight level: $fl \n Departure time: $dtime \n Arrival time: $atime \n Flight time: $ftime \n Esta mensagem é automatica, por favor não responder'; $headers = 'From:' . $from; Util::SendEmail($email, $subject, $message. $headers); // Show the template $this->render('routesubmit/routesubmit_submitted'); } } ?> Quote
Moderators servetas Posted October 21, 2017 Moderators Report Posted October 21, 2017 Did you try to add different echoes in your code in order to check where the code stops running? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.