Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHPMailer with GMail and Windows Scheduler

Posted on 2011-02-22
5
Medium Priority
?
1,233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 17

Accepted Solution

by:
Dushan De Silva earned 1600 total points
ID: 34957440
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
ID: 34957452
this sort of issue usually arises from a question of what user the scheduler is set to run as.
0
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 400 total points
ID: 34958079
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
ID: 34958505
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
ID: 34959984
This worked nicely, just added a batch file to taskkill the explorer sessions. Thanks again for all your help
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

596 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