7

I am trying to setup a php page to automatically send a verification email. I would like to use the gmail smtp servers, and everywhere I've looked suggests to use PHPMailer. I installed it and used the following example code:

ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once ("incl\PHPMailer\PHPMailerAutoload.php");

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "myemail@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom('myemail@gmail.com','Me');
$mail->AddAddress("ToAddress@gmail.com");
$mail->Subject = "Verify your email";
$mail->Body = "Thank you for signing up.  Please verify your email using the link below:";
$mail->IsHTML (true);

if($mail->Send()){
    echo "Success";
}else{
    echo "Error";
}

When trying to access the page via Firefox, the page will load for a few minutes, then give this error:

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

The server is Windows Server 2008 R2 Standard running IIS 7.5 and PHP Version 5.5.8. I can access all other pages without issues, but trying to call $mail->Send() seems to be timing out or something. I know this because I commented every line and slowly added pieces back in and $mail->Send() is the line that causes the behavior.

My Google abilities are failing me here as I simply cannot figure out how to make this work. Any ideas on what might be wrong?

Update

I opened the server log then tried loading the page again, but no new errors were added to the log. However, I noticed the following errors from today in System32\LogFiles\httperr1.log

2014-10-27 06:29:21 1.161.23.122 3148 212.83.145.123 80 HTTP/1.0 CONNECT mx2.mail2000.com.tw:25 400 - URL -  
2014-10-27 10:10:12 95.183.244.244 33553 212.83.145.123 80 HTTP/1.1 GET / 400 - Hostname -
2014-10-27 11:25:25 207.38.185.197 51157 212.83.145.123 80 HTTP/1.1 GET /tmUnblock.cgi 400 - Hostname -
2014-10-27 12:46:21 1.168.221.158 7952 212.83.145.123 80 - - - - - Timer_ConnectionIdle -

UPDATE 2

I am positive that my gmail account details are correct and have tested sending from it using Thunderbird on the server. When trying to sent without secured methods, as suggested in this comment I get this error:

MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated

My PHP Mailer version is 5.2.9 and I've now also tried the following:

  • Using \\ in file paths instead of \
    • No change
  • Including class.phpmailer.php instead of PHPMailerAutoload.php
    • Fatal error: Class 'SMTP' not found in C:\inetpub\wwwroot\incl\PHPMailer\class.phpmailer.php on line 1195
  • Using ssl over port 465
    • SMTP connect() failed
  • Sending with a hotmail address over port 25 with $mail->SMTPAuth = false;
    • MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated

Update 3

After reloading the problem page, I checked through the Event Viewer and saw a new entry in Windows Logs -> System:

PHP Error : syntax error, unexpected BOOL_TRUE in C:\PHP\php.ini on line 101

That line is:

php_flag display_errors on

Community
  • 1
  • 1
David Starkey
  • 1,733
  • 3
  • 28
  • 46
  • Error 500 is meaningless by itself. You should find a meaningful error message in your web server logs. Either that, or set `display_errors` to true in your script or php.ini to make it visible. This is not specific to PHPMailer - it's true for any PHP fatal error. – Synchro Oct 27 '14 at 08:28
  • I tried adding `ini_set('display_errors', 1);` to the top of the script but it did not change the output. Updated question with some details from the log file. – David Starkey Oct 27 '14 at 15:09
  • If you're seeing 500 errors in your browser, but nothing is being logged, something is wrong with your web server config. The errors you've shown are 400 (bad request) errors. You should also try turning up error reporting: `error_reporting(E_ALL);` – Synchro Oct 27 '14 at 15:29
  • @Synchro I tried adding `ini_set('error_reporting', 'E_ALL');` on the page as well as `error_reporting = E_ALL` in php.ini but neither changed the error message. Can you point me in the right direction for how I can verify my server config? – David Starkey Oct 27 '14 at 15:38
  • `error_reporting` is a function - use exactly what I posted - what you put will cause a 500 error by itself! – Synchro Oct 27 '14 at 15:41
  • Replaced the `ini_set` with `error_reporting(E_ALL);` and there is no change in the output. – David Starkey Oct 27 '14 at 15:51
  • Well if that is the entirety of your script, the only thing in there that could cause a fatal error (the code works fine for me) is the `require_once` not finding the class. Try putting the absolute path to the autoloader in there, and check it really exists. – Synchro Oct 27 '14 at 15:56
  • @Synchro If I remove the `$mail->Send()` then the page loads fine (I assume failure to find the file would error at `require_once ("incl\PHPMailer\PHPMailerAutoload.php");` or `$mail = new PHPMailer();` lines. – David Starkey Oct 27 '14 at 16:06
  • That's true. In that case it may be that you're missing the openssl extension - check output from `phpinfo();` – Synchro Oct 27 '14 at 16:08
  • @Synchro Looks like that might be it: `OpenSSL support disabled (install ext/openssl)` but the php.ini has `extension=php_openssl.dll` enabled. I double checked that this is the same php.ini that is listed under `Loaded Configuration File` for `phpinfo()` output. I also copied the `php_openssl.dll` to the same location as php.exe but phpinfo keeps saying OpenSSL is disabled. – David Starkey Oct 27 '14 at 16:27
  • Can you confirm that you have done everything described in the [Notes](http://php.net/manual/en/openssl.installation.php) section...? That might resolve your SSL issue and make this work. – Robert Rossmann Jan 11 '15 at 11:04
  • `php_openssl.dll` should be present in the `ext` directory for it to work (e.g. `C:\Program Files\PHP\ext`). Also for OpenSSL you may wanna check if you have `libeay32.dll` and `ssleay32.dll` present somewhere in your Windows PATH (e.g. `C:\Windows\System32`) - some nasty problems could also arise concerning wrong versions of those. – Levite Jan 12 '15 at 09:40
  • @RobertRossmann I can confirm this, problem still persists. – David Starkey Jan 12 '15 at 15:20
  • @Levit `php_openssl.dll` exists in `C:\php\ext`. There is no PHP folder under `C:\Program Files`. Does there need to be? Neither `libeay32.dll` nor `ssleay32.dll` exist in `C:\Windows\System32`. Both exist in [3 other locations](http://i.stack.imgur.com/kaGfd.png) – David Starkey Jan 12 '15 at 15:34
  • It is fine to have it just under `C:\php\ext`, if you have php installed in `C:\php`. You might wanna check though, if `C:\php` is part of your windows path environment variable, because if not those two other files will not be found by the system. – Levite Jan 12 '15 at 16:13
  • @Levit `C:\php` is double-checked as the environment variable in path – David Starkey Jan 12 '15 at 17:12
  • Just another thought: Did you already try to send from an email address that does not require smtp authentication, so you know for sure that the problem lies there? – Levite Jan 13 '15 at 07:00
  • @Levit I have not tried sending from a non-SMTP address. I'm not sure how to set this up and my searching is not turning anything up. Do you have a link I can use as a guide? – David Starkey Jan 13 '15 at 15:27
  • Providers which allow unencrypted sending are getting fewer since google heavily criticised this, and published a list of those in mid 2014. But I think hotmail/live.com is one that still supports it, if you don't have an account there, you could register one, and then try with settings like `$mail->SMTPAuth = false; $mail->Port = 25;`. You could actually also try it right away with your gmail address - although not supported by gmail - it might at least give you a different error. – Levite Jan 14 '15 at 09:26
  • @Levit Tried changing it to your suggestion (commented out `$mail->SMTPSecure = "tls";` and `$mail->Host = "smtp.gmail.com";`) but gmail and hotmail both give this new error: `MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated` – David Starkey Jan 14 '15 at 16:56
  • Dear David your gmail acount ascess setup requested action and authenticated. – Buse Gönen Jan 14 '15 at 20:27
  • Well that looks pretty good! Seems like sending would probably work unauthenticated (just that google does not support it, what this new error just reflects). If there would have been still an internal server error, the problem would have been somewhere else, but now you can at least be pretty sure that this whole issue is SSL related (or at least authentication related). In short: We just have to figure out why the openssl module is not being loaded ... – Levite Jan 15 '15 at 07:44
  • This could be an IIS setup issue, but from your error log in System32\LogFiles\httperr1.log you get an HTTP Error 400. "The request hostname is invalid" try to check it in MX toolbox first to see if exists. http://mxtoolbox.com/SuperTool.aspx?action=mx%3amx2.mail2000.com.tw&run=toolpage –  Jan 17 '15 at 06:40
  • $mail->SMTPDebug = 2; $mail->Debugoutput = 'html'; add these lines after $mail->IsSMTP(); –  Jan 17 '15 at 09:26
  • I am not able to find the php error_log entries in the question. Kindly add the same. Try wrapping the send command with a try catch block, probably there might be some info. Regarding the last update, You don't need php_flag in php.ini. Please cross check – kranthi117 Jan 17 '15 at 18:45
  • @kranthi117 wrapping in a try-catch does not change anything. I'll try commenting out php_flag when I get back to a computer. – David Starkey Jan 17 '15 at 20:06
  • @PeterDarmisadding those 2 lines did not change output. As for the log, the machine that loads the page is given a 500 Internal server error. I will look into MX toolbox later since I'm unfamiliar with it and would rather not try to figure it out on my phone. – David Starkey Jan 17 '15 at 20:20
  • @kranthi117 Commenting out `php_flag display_errors on` and running `iisreset` the problem page now just outputs php source code (as do all the other pages) – David Starkey Jan 18 '15 at 18:12
  • @PeterDarmis MX Toolbox seems to be confirming that it exists. – David Starkey Jan 18 '15 at 18:14

8 Answers8

2

Looks like you're dealing with bunch of issues and here is a checklist: you're having issues with ssl, the actual mail software and credentials. It became an issue of 3 from one main issue and I'm guessing you don't either have your credentials typed in correctly or your open ssl isn't setup and you're also having issues using the mail software.

535 535 5.7.3 Authentication Unsuccessful means auth is unsuccessful, check your credentials username and password.

550 error code, it means that the receiving system could not deliver your email to the user to whom it was addressed because the mailbox is unavailable.

There are plenty of other solutions to resolve your issue. Why don't you try something more simple instead of using the autoload PHPMailerAutoload.php. Create a new file and place the code below, create a message body (test_message.html) and call it from the browser to test gmail smtp with the gmail credentials. This is a snippet from PHPMailer on how to use it with gmail smtp and it shouldn't go wrong if you have everything filled in correctly.

<?php
    require_once('../class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail             = new PHPMailer();

    $body             = file_get_contents('test_message.html');
    $body             = eregi_replace("[\]",'',$body);

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "mail.yourdomain.com"; // SMTP server
    $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                               // 1 = errors and messages
                                               // 2 = messages only
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "tls";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 587;                   // set the SMTP port for the GMAIL server
    $mail->Username   = "yourusername@gmail.com";  // GMAIL username
    $mail->Password   = "yourpassword";            // GMAIL password

    $mail->SetFrom('name@yourdomain.com', 'First Last');

    $mail->AddReplyTo("name@yourdomain.com","First Last");

    $mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail->MsgHTML($body);

    $address = "whoto@otherdomain.com";
    $mail->AddAddress($address, "John Doe");

    $mail->AddAttachment("images/phpmailer.gif");      // attachment
    $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message sent!";
    }
    ?>

If you're getting user auth error, then your credentials aren't typed in correctly. If that's not the issue, you'll get an ssl error if you're not using the right port.

If there are software issues with include, you should try something better.

I was debating this morning if I should should PHPMailer, ended up using Swiftmailer which worked right after I installed it with PHPComposer.

My Internal mail server is extremely picky and has ton of firewall settings and rules on hardware and software level and I was surprised it didn't give me any problems; the emails were being sent right away without any problems on port 587.

require_once 'vendor/swiftmailer/swiftmailer/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('mail.hellog***.com', 587)
  ->setUsername('apache@hellog***.com')
  ->setPassword('apa******')
  ;

This is what you need for gmail:

$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername($this->username)
  ->setPassword($this->password);

$this->mailer = Swift_Mailer::newInstance($transporter);

If none of what you like, you can try phpgmailer: https://github.com/GregDracoulis/LectureBank/tree/master/phpgmailer

here is an example on how to use it: http://www.vulgarisoverip.com/2006/10/13/update-send-email-with-php-and-gmail-hosted-for-your-domain/

this class is dedicated for gmail use.

If all your problems and issues relate to openSSL, you should follow the steps below:

1. Make sure the OpenSSL module DLL file is included in the PHP installation:

C:\user>dir \local\php\ext\php_openssl.dll

Directory of C:\local\php\ext

php_openssl.dll

2. Create the PHP configuration file, \local\php\php.ini, if it does not exist:

C:\user>copy \local\php\php.ini-production \local\php\php.ini

    1 file(s) copied.

3. Enable the OpenSSL module by editing the configuration file with a text editor. You need to remove the comment maker (;) on two configuration lines:

...

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

...
extension=php_openssl.dll

...

That’s it. You should be all set setting up openSSL on your Windows IIS WebServer. Follow these options and steps, it could be your issue.

unixmiah
  • 2,808
  • 1
  • 8
  • 25
  • I know my credentials are correct as I can log into the account from anywhere else and send and receive email, this includes Mozilla Thunderbird client on the server with the issues. I did not have `extension_dir = "ext"` uncommented, but after enabling it and running `iisreset` the output is the same. Trying to [install Swiftmailer](http://swiftmailer.org/download) gives error mentioned in **UPDATE 3**. PHPGMailer gives `Fatal error: Call to undefined method PHPGMailer::From()`. – David Starkey Jan 16 '15 at 21:09
  • what is your php version and how are you including these files? do you have the lib setup correctly in a directory where its accessible by your php script? – unixmiah Jan 16 '15 at 21:15
  • **PHP Version 5.5.8** and including using `require_once('incl\phpGMailer\class.phpgmailer.php');` which is where I put those 3 files. PHPMailer is same as in my question which I assume is working because the page is fine until the `$mail->Send();` – David Starkey Jan 16 '15 at 21:22
  • so you checked if you have openssl installed on your server? – unixmiah Jan 16 '15 at 21:24
  • `C:\php\ext\ ` contains `php_openssl.dll` and the folder `openssl` but `phpinfo()` states: `OpenSSL support | disabled (install ext/openssl)` – David Starkey Jan 16 '15 at 21:39
  • ahh, you need to load php_openssl.dll. just for now, in your code before you execute the mail script, use or put dl('php_openssl.dll'). dl — Loads a PHP extension at runtime – unixmiah Jan 16 '15 at 21:43
  • Adding that to the php page gives `Call to undefined function dl()` Apparently [this has been disabled since 5.3](http://stackoverflow.com/questions/16163525/call-to-undefined-function-dl) – David Starkey Jan 16 '15 at 22:15
1

This problem is slashes ( \ )

Edit

require_once ("incl\\PHPMailer\\PHPMailerAutoload.php");
Buse Gönen
  • 228
  • 1
  • 5
1

I have tried with you code, and i have only changed this line :

require_once ("incl\PHPMailer\PHPMailerAutoload.php");

by this one :

require_once ("incl\PHPMailer\class.phpmailer.php");

And it was worked successfully.
Also you should keep attention about your PHPMailer version and your PHP version.
Have you tried to send an email with not secured method ?
Are you sure that your google credentials are valid ?

UPDATED
From the command line of your server, what is the output of this command and how much time that it takes to respond

telnet smtp.gmail.com 587
Halayem Anis
  • 7,233
  • 2
  • 18
  • 39
  • Making your suggest change results in this error: `Fatal error: Class 'SMTP' not found in C:\inetpub\wwwroot\incl\PHPMailer\class.phpmailer.php on line 1195` As for your other questions, I will update my question with these details. – David Starkey Jan 14 '15 at 20:47
  • Response from telnet command: `200 mx.google.com ESMTP i15sm10941378wjq.22 - gsmtp` – David Starkey Jan 17 '15 at 20:25
1

I wonder if you are running into the same issue that this question ran into. Google actively frowns on people using Gmail as their own personal SMTP server.

http://www.labnol.org/internet/email/gmail-daily-limit-sending-bulk-email/2191/

Google also limits the number of email messages that you can send through your Gmail account in a day. If you exceed the daily quota, Google may temporarily disable your Gmail account without any warnings and you may have to wait for up to 24 hours before you can regain access to your Gmail mailbox.

I could see an error like that potentially producing a 500 error.

Community
  • 1
  • 1
Machavity
  • 28,730
  • 25
  • 78
  • 91
1

From the comments to the question, it seems pretty clear that this issue is OpenSSL related.

You mentioned that you already have extension=php_openssl.dll uncommented, but phpinfo() does show it not beeing loaded.

Some thoughts:

  • Have you restarted the webserver, after uncommenting the openssl php module in your php.ini?

    This is the really obvious one, but still worth mentioning. The php.ini is loaded on start-up, and not doing a service restart is simply a common mistake.

  • Check the value of Loaded Configuration File in phpinfo()

    If this is not the same location than the php.ini which you have edited, it also becomes clear why it has not been loaded. Also following lines from phpinfo() might be worth checking.

    • Configuration File (php.ini) Path
    • Loaded Configuration File
    • Scan this dir for additional .ini files

There are other things too which can be done like uninstalling and reinstalling OpenSSL, but it might be good to check these more obvious things first.

Further thoughts:

  • Checking the error logs

    For php the path can (again) be found in your phpinfo(). Look for the value of error_log and check the latest entries, right after you tried to reload your page.

    Also you may wanna check the log files of IIS. If you don't know the path look in the IIS Manager, select the computer on the left pane, and in the middle pane, go under "logging" in the IIS area. Usually these will point to something like C:\inetpub\logs\LogFiles or C:\Windows\System32\LogFiles with a subfolder like W3SVC[x] where [x] is the website ID. (Will be just 1 if you only have one page, otherwise check the top level websites folder in IIS Manager, view the lists of sites in the right hand pane, it's the App ID)

Levite
  • 15,387
  • 7
  • 47
  • 46
  • I remember running `iisreset` many times but just to be sure I made sure the line was uncommented and ran it again. No change. As for your second point: `Loaded Configuration File: C:\PHP\php.ini` This is the same as the one I've been editing. `Configuration File (php.ini) Path: C:\Windows` (which may be the issue?) `Scan this dir for additional .ini files: (none)` – David Starkey Jan 15 '15 at 16:05
  • @DavidStarkey: Since your `Loaded Configuration File` is the one you are editing, this should be fine (altough you can try around with copying it to the Windows path, etc. but it really should(!) have no bearing). `IISReset` also is correct to restart your web services. I added a third bullet point concerning error logs ... you may want to check this one. – Levite Jan 16 '15 at 07:25
  • `phpinfo()` for the log record is `error_log | no value | no value`. As for IIS error log, I don't seem to have the option... Added some details about the Event Viewer output to question. – David Starkey Jan 16 '15 at 16:38
  • Also, trying to set a location using `error_log = "C:\Windows\temp\php_errors.log"` does not change the output. – David Starkey Jan 16 '15 at 16:53
  • Wow this is really a tough one oO. Well, error logs would be extremly helpful, so let's tackle that first. Have you also checked those two locations mentioned above (`C:\inetpub\logs\...` and `C:\Windows\System32\LogFiles\W3SVC1`)? As for the php error log, have you also set `log_errors = On` and possibly `error_reporting = E_ALL` (but this one should not really matter, since you have it set in your php code at the very beginning as well). – Levite Jan 19 '15 at 08:05
  • @DavidStarkey: Hey, I just saw your last question update (3) that you already got an error in the EventViewer! In your php.ini it is supposed to be simply be `display_errors = on`!! What you have (`php_flag display_errors on`) is actually something you would put in a `.htaccess` file instead. Try to change that, and see if it loads your `php.ini` correctly. – Levite Jan 20 '15 at 07:12
  • Removing `php_flag display_errors on` and setting `display_errors = on` in the php.ini file makes it so all outputs are php source code, even after iis restart. Putting it back i while keeping the `display_errors = on` results in no change in output. I'm not familiar with server setup and I'm unable to find a .htaccess file on the server. I did find [this question](http://stackoverflow.com/q/1436171/1618257) related to this, though I quickly ended up beyond my understanding. – David Starkey Jan 20 '15 at 16:05
  • @DavidStarkey: Well it seems that up until now the ini has not been loaded completely because of the error in it. So the question is, what else is in there that might make an issue of things. Or alternatevly - if you see a lot of "warnings" etc. it might just be that you now really see all the errors, since we just enabled this (if it actually is not php sourcecode, but errors you see). Also you might wanna check the EventViewer again. Also try loading a "default-ish" php.ini (= rename yours, and put it in it's place), and see if that loads correctly (if yes, try to JUST enable openssl there). – Levite Jan 21 '15 at 08:06
  • When viewing the source of the delivered php page using Firefox, it displays exactly the php source code (no errors at all). This happens even after replacing php.ini with php.ini-development contents. Only after including `php_flag display_errors on` does the server run the php code instead of delivering file contents. – David Starkey Jan 21 '15 at 16:30
  • Well than it seems like whenever the `php.ini` is loaded correctly, it does no longer work. It needs an error line to even process php at all? oO To state an android log mode: "What a Terrible Failure" (aka `wtf`)! Well anyhow, you can at least check if it really is like that and change this line to something like `php_flag_bla dispbla yikes`... or just about anything else, just to confirm that it needs an error there, and not actually this line (no clue why this should be, but is the only thing I can think of right now, other than that you could just try a recommended `php.ini` from the net). – Levite Jan 22 '15 at 07:07
  • Changing the `php_flag` line to your suggestion resulted in php source code being output. If it needs an error, it needs that specific line to cause the error. Changing the php.ini file to [this example](https://github.com/php/php-src/blob/master/php.ini-development) also gives php source output. – David Starkey Jan 22 '15 at 15:37
  • Really interesting! Have you checked the EventViewer again, to see if it logs a specific error when outputting the source code? Other than that you might try a different variant of php.ini still, like the production one from the same page for example: https://github.com/php/php-src/blob/master/php.ini-production – Levite Jan 22 '15 at 15:46
  • Changing to the production version also resulted in php source output. However, when running `iisreset` and looking in Event Viewer, I noticed this under the System Windows Log: `No usable TLS server certificate for SMTP virtual server instance '1' could be found. TLS will be disabled for this virtual-server.` – David Starkey Jan 22 '15 at 16:06
  • Well that at least is something we can work with! Have you already googled the issue? Following thread deals with the issue and how to get rid of it: https://social.technet.microsoft.com/Forums/windowsserver/en-US/7f531c81-a5a7-45fa-9f22-e2aa440770d7/tls-certificate-issue While this might not be the full solution for the source-code output, it might be one step towards getting the encryption problems out of the way. – Levite Jan 23 '15 at 07:10
  • Well I quickly got in over my head there... I'll have to take some time to look more into this. I tried following the instructions but ended up not getting the TLS checkbox for the SMTP server. – David Starkey Jan 23 '15 at 16:26
1

Setting Up and Configuring IIS

Start by going to the ServerManager on you Server. Most often this is the server you’ll be running your php website on. Go to Add features in the Features summary section. Check SMTP Services in the Add Features Wizard and hit install. Now wait for the installation to finish. Open IIS6 (or IIS7) Manager under Administrative Tools -> Internet Information Services 6.0 in the Start Menu, the configuration of SMTP makes use of the management console from IIS6. Under [SMTP Virtual Server], click your right mouse button and select properties from the context menu. Go to the Access Tab and hit the Relay button.Add a new entry to the list by clicking the Add button and enter 127.0.0.1 (or your web server's IP) in the single computer entry field. Hit Ok two times to apply the new settings.

Configuring Php

To make Php send emails you need to make some configurations. Basically there are two options. In case you’re only going to use the SMTP server in a single project and do not want it to interfere with other projects, you can set the configuration from within your php code by adding the following lines anywhere before sending the email:

ini_set('SMTP','localhost' ); 
ini_set('sendmail_from', 'administrator@YourWebsite.com');

Another way, to make global use of these settings, add the next lines to your php.ini file.

[mail function]
SMTP = localhost
sendmail_from = me@example.com

Make sure you restart your server after making these changes, to be sure they’re loaded.

This solution is provided here http://geekswithblogs.net/tkokke/archive/2009/05/31/sending-email-from-php-on-windows-using-iis.aspx on how to set up IIS and php and was provided as answer to this question 500 error when trying to use the MAIL function

Community
  • 1
  • 1
  • The solution is part of this answer http://stackoverflow.com/questions/15231214/500-error-when-trying-to-use-the-mail-function, so if this is correct maybe it should be marked as duplicate question. –  Jan 17 '15 at 10:07
  • Trying this, I keep getting `mail(): SMTP server response: 550 5.7.3 Requested action aborted; user not authenticated` – David Starkey Jan 18 '15 at 18:40
0

Try to use SSL encryption with a port 465:

$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
user3806621
  • 281
  • 1
  • 6
  • That fails the `if( $mail->Send() )` check. – David Starkey Oct 27 '14 at 03:17
  • This is an extraction from Gmail documentation how to configure external email clients for SMTP: Outgoing Mail (SMTP) Server - requires TLS or SSL: smtp.gmail.com; Use Authentication: Yes; Port for TLS/STARTTLS: 587; Port for SSL: 465 – user3806621 Oct 27 '14 at 03:25
  • That's great, but it's still not working for me. Is there a link you can point to for this that might go into more detail? – David Starkey Oct 27 '14 at 03:32
  • I advise temporarily to setup a test gmail account in Outlook or Thunderbird to test SMTP settings. At least it does work in my MS Outlook 2007 using SSL with 465 port. If same error, perhaps you have to check firewall or local ISP. – user3806621 Oct 27 '14 at 03:43
  • I can open the Thunderbird client on the server and send an email using the gmail account with no problems. – David Starkey Oct 27 '14 at 03:51
  • Try another version of PHPMailer v.5.2.4: https://code.google.com/a/apache-extras.org/p/phpmailer/downloads/detail?name=PHPMailer_5.2.4.zip – user3806621 Oct 27 '14 at 04:01
  • Using that version, I get this error: `Warning: stream_socket_enable_crypto(): this stream does not support SSL/crypto in [filepath]\class.smtp.php on line 248` – David Starkey Oct 27 '14 at 04:06
  • 1
    Please don't use old versions. Gmail should use tls on 587, as per the PHPMailer documentation and examples. ssl on 465 is to be avoided. – Synchro Oct 27 '14 at 08:25
  • @Synchro: Both very good points (old versions & avoid 465)! But for testing purposes / error finding, these are both falid temporary(!) options. And the error he got from trying this (`stream does not support SSL/crypto`) is a better hint to what's the real problem here, than probably any of the other answers so far. Still you are very right to point out that those things are not for production environment! – Levite Jan 22 '15 at 07:41
0

Warning: require_once(mailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in....

This is the way I had my file routed

Before: require_once "mailer/PHPMailerAutoload.php";

After: require_once "../mailer/PHPMailerAutoload.php";

...Same process you would normally do to link an img as background using css.

Diligent Key Presser
  • 3,703
  • 4
  • 23
  • 33
roman
  • 1