0

I just downloaded phpmailer from github and uploaded to shared hosting. I made file called mailer.php and added this code (example from git-page):

When I start this (open file) Nothing is echoed and no mails are received. If i try to echo anything like any text after this code it won't do it but if I put it before it will echo it out.

I looked up Here but nothing from answers works here...

<?php
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'mail.mydomain.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'email';                 // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465; //shared hosting ssl port

    //Recipients
    $mail->setFrom('email@mydomain.com', 'Site Title');
    $mail->addAddress('myGmail@gmail.com', 'Soma name');             // Name is optional
    $mail->addReplyTo('email@mydomain.com', 'Info');
    //$mail->addCC('cc@example.com');
    //$mail->addBCC('bcc@example.com');

    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    $mail->isHTML(true);
    $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;
}
?>
  • try to debug the code. or make log file. which help more that where it fails. – Nitin Goyal Mar 10 '18 at 11:57
  • Possible duplicate of [How to get useful error messages in PHP?](https://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) – Synchro Mar 10 '18 at 12:58
  • @StupidKid try `$mail->SMTPDebug = 3;` or `4` it would show authentication or any other low level issue if any – Viney Mar 11 '18 at 05:12
  • Its different on their website and on github, I downloaded from website and it works fine... –  Mar 11 '18 at 11:54

0 Answers0