• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MailerPHP

#1
Hi, I got a small problem where if I run the run.php which I created in the composer MailerPHP folder with the simple code to send an email, which works find, but the problem comes when it I am trying to run the code from a form.

Here is the form code, the html is in the root directory of the folder. The run is in the mailer/run.php. 

         <form name="sentMessage" id="contactForm" action="mailer/run.php">
           <div class="control-group">
             <div class="form-group floating-label-form-group controls">
               <label>Name</label>
               <input value="Josh" type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
               <p class="help-block text-danger"></p>
             </div>
           </div>
           <div class="control-group">
             <div class="form-group floating-label-form-group controls">
               <label>Email Address</label>
               <input value="[email protected]" type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
               <p class="help-block text-danger"></p>
             </div>
           </div>
           <div class="control-group">
             <div class="form-group col-xs-12 floating-label-form-group controls">
               <label>Phone Number</label>
               <input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
               <p class="help-block text-danger"></p>
             </div>
           </div>
           <div class="control-group">
             <div class="form-group floating-label-form-group controls">
               <label>Message</label>
               <textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
               <p class="help-block text-danger"></p>
             </div>
           </div>
           <br>
           <div id="success"></div>
           <div class="form-group">
             <button type="submit" class="btn btn-primary" id="sendMessageButton">Send</button>
           </div>
         </form>




<?php

   // Import PHPMailer classes into the global namespace
   // These must be at the top of your script, not inside a function
   use PHPMailer\PHPMailer\PHPMailer;
   use PHPMailer\PHPMailer\Exception;

   //Load Composer's autoloader
   require 'vendor/autoload.php';

   $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
   
   $mail->SMTPOptions = array(
       'ssl' => array(
           'verify_peer' => false,
           'verify_peer_name' => false,
           'allow_self_signed' => true
       )
   );

   try {
       //Server settings
       $mail->SMTPDebug = 2;                                 // Enable verbose debug output
       $mail->isSMTP();                                      // Set mailer to use SMTP
       $mail->Host = 'smtp.gmail.com';                         // Specify main and backup SMTP servers
       $mail->SMTPAuth = true;                               // Enable SMTP authentication
       $mail->Username = '[email protected]';                 // SMTP username
       $mail->Password = 'dafdfsdfasdfdf';                           // SMTP password
       $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
       $mail->Port = 587;                                    // TCP port to connect to

       //Recipients
       $mail->setFrom('[email protected]', 'Mailer');
       $mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
       $mail->addAddress('[email protected]');               // Name is optional
       $mail->addReplyTo('[email protected]', 'Information');
       $mail->addCC('[email protected]');
       $mail->addBCC('[email protected]');

       //Content
       $mail->isHTML(true);                                  // Set email format to HTML
       $mail->Subject = 'Here is the subject';
       $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
       $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

       $mail->send();
       echo 'Message has been sent';
   } catch (Exception $e) {
       echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
   }

?>
Reply

#2
When you say there's a problem - you should be a bit more specific describing how this issue manifests.
Reply

#3
(08-14-2018, 05:16 AM)Pertti Wrote: When you say there's a problem - you should be a bit more specific describing how this issue manifests.

So if I go through the local host and run run.php which runs the phpmailer, everything works fine, but I want the code to run when the submit button is pressed. For some strange reason, this is not running the code, why, I do not know.
Reply

#4
(08-14-2018, 01:01 PM)dreamweaver Wrote: So if I go through the local host and run run.php which runs the phpmailer, everything works fine, but I want the code to run when the submit button is pressed. For some strange reason, this is not running the code, why, I do not know.

Have you tried submitting it with AJAX?
Reply

#5
(08-14-2018, 01:01 PM)dreamweaver Wrote: For some strange reason, this is not running the code, why, I do not know.

Is there an error message it displays?

Also, if you check the source code, is the URL what it should be? Sometimes you can have little niggles in there and it's not posting to right URL.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.