PHPMailer with GMail and Windows Scheduler

Hi,

I have an internal Windows 2003 server which runs Apache and IIS side-by-side. I'm logged in as the administrator.
Up to last week, I had a Windows Scheduled Task which invoked a PHP file.
This PHP file used PHP's inbuilt "mail" command to send an email, using an internal mailserver.

I then changed the mailserver to Gmail and because it needed an SMTP login, I changed the "mail" command to PHPMailer which I'm very familiar with.

If I now open Internet Explorer and put in the URL of my PHP file, PHPMailer sends the email as expected. With SMTPDebug set to 1, no warnings are displayed.

If I now run the unchanged Windows Scheduler job (either manually or schedule it), the email is NOT sent and instead, a  command prompt window flashes up saying "unable to connect to server: Unable to find the socket transport "ssl"  - did you forget to enable it when you configured PHP? Could not connect to SMTP host."

If I run phpinfo() it shows the PHP.ini file that I modified last week. If I open this PHP.ini file, "openssl" is uncommented. Apache was restarted since that change was made last week.

Can anyone help me? Does PHPMailer not work with Windows Scheduler? Is the PHPMailer include not being recognised, even if I put the full path in the include?

Thanks in advance
kbitAsked:
Who is Participating?
 
Dushan De SilvaConnect With a Mentor Technology ArchitectCommented:
First create a php file based on the attached code snippet. save it as www.mywebsite.com/mail.php

1. save code snippet as "mail.php"
2. edit variables in << >>
      If using a free email host and info is unknown: http://www.emailaddressmanager.com/tips/mail-settings.html
3. upload to www.mywebsite.com
4. Download http://sourceforge.net/projects/phpmailer and place class.phpmailer.php in your php includes directory
5. navigate with a web browser to www.mywebsite.com/mail.php to make sure it sends

Next in Windows go to "Start | Control Panel | Scheduled Tasks".
1. Click the Add Scheduled Task button
2. Click Next
3. Select Internet explorer from the list
4. Select Perform this task Daily (well change it later)
5. Click Next
6. Enter your username and password of the computer
7. Select open advanced properties and click Finish

In advanced properties
1. Add "www.mywebsite.com/mail.php" after "C:\PROGRA~1\INTERN~1\iexplore.exe" in the "Run" Section
2. Click on the schedule tab and click advanced
3. Check "Repeat Task" and say every 30 minutes for 24 hours.
4. Click OK
5. Click OK
6. Enter Windows user name and password again

The website should pop up and send an email every 30 minutes now.

<?php
 
require("class.phpmailer.php");
 
$mail = new PHPMailer();
 
$mail->IsSMTP(); // send via SMTP
$mail->Host     = "<<smtpserver>>:<<stmpport>>"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "<<uname>>"; // SMTP username
$mail->Password = "<<pword>>"; // SMTP password
$mail->From = "<<email address from>>";
$mail->FromName = "<<email name from>>";
$mail->AddAddress("<<email address to>>"); 
$mail->AddReplyTo("<<email address from>>","<<email name from>>");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject  =  "Subject";
$mail->Body     =  "Body text";
$mail->AltBody  =  $mail->Body;
        
if ( $mail->Send() )
{
echo "Email sent successfully";
}
else
{
echo "Email failed";
}
 
?>

Open in new window

0
 
virmaiorCommented:
this sort of issue usually arises from a question of what user the scheduler is set to run as.
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
PHP thru Apache uses the 'php.ini' in the Apache folder.  PHP on the command line uses the 'php.ini' in the PHP folder or maybe in C:\Windows.  Usually.  Different files.
0
 
kbitAuthor Commented:
Thanks for the suggestions all. Dushan911, your suggestion looks very promising, just getting someone to test it in the next few hours but the job I quickly set up earlier looks great!
0
 
kbitAuthor Commented:
This worked nicely, just added a batch file to taskkill the explorer sessions. Thanks again for all your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.