Solved

PHPMailer with GMail and Windows Scheduler

Posted on 2011-02-22
5
1,115 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:kbit
5 Comments
 
LVL 17

Accepted Solution

by:
Dushan911 earned 400 total points
Comment Utility
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
 
LVL 20

Expert Comment

by:virmaior
Comment Utility
this sort of issue usually arises from a question of what user the scheduler is set to run as.
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
Comment Utility
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
 

Author Comment

by:kbit
Comment Utility
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
 

Author Comment

by:kbit
Comment Utility
This worked nicely, just added a batch file to taskkill the explorer sessions. Thanks again for all your help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now