1

I am trying to configure PHPMailer in order to have it working ona Windows IIS server using php scripts.

The application I have is written in PHP so we expected we could easily use PHPMailer to send emails.

Well, that doesn't work.

We have tried configuring it as SMTP, but we still get error in configuration.

Here it is our script:

date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 1;
//$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "account@gmail.com";
$mail->Password = "gmailPWD";
$mail->setFrom('info@website.com', 'The Website');

$mail->addAddress($to, '');     
$mail->Subject = $subject;
$mail->msgHTML($message);


if (!$mail->send()) {
    $errors =  "Errori Mailer: " . $mail->ErrorInfo;
} else {
    $errors =  "<h5>Sent!</h5>";
}

Any clue? How can that be used on windows server?

Thank you

EDIT

So, it was a problem of Gmail and its security settings. I followed this post: https://stackoverflow.com/a/25175234/1873501 and everything went smooth!

I just wanted to share it.

Community
  • 1
  • 1
Aptivus
  • 433
  • 1
  • 8
  • 24
  • 2
    What is the error you are getting? The underlying server, IIS, Apache or otherwise, does not matter in this case since you appear to be attempting to use gmail.com as your relay. Have you double checked what you are doing with the example on the Worx page? http://phpmailer.worxware.com/?pg=examplebgmail – Dave Feb 15 '16 at 20:37
  • I have followed the example step by step. It seems it does not authenticate me, even if I use my gmail mailbox and my password correctly as stated in that example. Are there any configurations that needs to be done gmail side? Thank you. – Aptivus Feb 16 '16 at 05:11
  • 1
    Don't use the worxware examples, they are years out of date. Use the examples from github. Read [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). – Synchro Feb 16 '16 at 07:45
  • Thnk you @Synchro. That's a very good guide! I'll follow the hints and see what happens. – Aptivus Feb 16 '16 at 11:27

2 Answers2

1

You've downloaded and extracted the class I am assuming. Maybe you're not autoloading? Make sure you include:

require '/path/to/PHPMailerAutoload.php';

It should be fine on IIS/Windows Server. See some of the examples here in the documentation (and in the examples folder): https://github.com/PHPMailer/PHPMailer

Also, if you are getting any errors make sure you list them so we know how to help you further.

Kyle Burkett
  • 1,375
  • 12
  • 28
  • Thank you Kyle. I am autoloading as you suggest. The error is in the authentication of the gmail smtp. It seems I cannot authenticate correctly. Might it be because I have to configure something else on the gmail settings? – Aptivus Feb 16 '16 at 05:15
  • @Aptivus check out this link for another user experiencing a similar authentication issue http://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer – Kyle Burkett Feb 16 '16 at 20:20
0
function sendMail($request) {
    require 'PHPMailerAutoload.php';

    $mail = new PHPMailer;

    $mail->SMTPDebug = 4;

    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'yourmail@gmail.com;
    $mail->Password = 'yourgamilPass';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;

    $mail->setFrom('yourgmail@gmail.com', 'Title');
    $mail->addAddress(emailsendingto@gmail.com);   
    $mail->addReplyTo('yourgmail@gmail.com');

    $mail->isHTML(true);                               

    $mail->Subject = '$the subject of the e-mail';

    $mail->Body = 'The body of the email';

    $mail->AltBody = 'Alternative'; // this is mostly sent to your own mail

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
}
Niclausel
  • 139
  • 1
  • 3