Welcome Guest, Not a member yet? Register   Sign In
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


Messages In This Thread
MailerPHP - by dreamweaver - 08-14-2018, 03:06 AM
RE: MailerPHP - by Pertti - 08-14-2018, 05:16 AM
RE: MailerPHP - by dreamweaver - 08-14-2018, 01:01 PM
RE: MailerPHP - by kaitenz - 08-14-2018, 11:07 PM
RE: MailerPHP - by Pertti - 08-15-2018, 12:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB