Solved

Phpmailer test_gmail.php returning a blank page

Posted on 2008-10-11
10
823 Views
Last Modified: 2010-04-21
Hi,

I'm using phpMailer_v2.2.1 to send an email using my gmail account. However I get no error messages and the email is not sent.

Using the mail function, i.e. test_mail.php (in the phpMailers example) worked perfectly fine.

Thanks for your help.
<?php
 
//error_reporting(E_ALL);
error_reporting(E_STRICT);
 
date_default_timezone_set('America/Toronto');
 
include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
 
$mail             = new PHPMailer();
 
$body             = $mail->getFile('contents.html');
$body             = eregi_replace("[\]",'',$body);
 
$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
 
$mail->Username   = "mygmail@gmail.com";  // GMAIL username
$mail->Password   = "mygmail";            // GMAIL password
 
$mail->AddReplyTo("sifu.chris@gmail.com","Chris Cass");
 
$mail->From       = "sifu.chris@gmail.com";
$mail->FromName   = "Chris Cass";
 
$mail->Subject    = "PHPMailer Test Subject via gmail";
 
//$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap
 
$mail->MsgHTML($body);//;
 
$mail->AddAddress("myemail@yahoo.com", "John Doe");
 
$mail->AddAttachment("images/phpmailer.gif");             // attachment
 
$mail->IsHTML(true); // send as HTML
 
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
 
?>

Open in new window

0
Comment
Question by:Rassac
[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
  • 3
  • 2
10 Comments
 
LVL 6

Expert Comment

by:hampus_b
ID: 22694201
And you don't get any errors if you change
//error_reporting(E_ALL);
error_reporting(E_STRICT);

to

error_reporting(E_ALL);
// error_reporting(E_STRICT);

and try again?
0
 
LVL 6

Expert Comment

by:hampus_b
ID: 22694213
(because I get tons of different messages/errors - but never ever a blank page...)
0
 

Author Comment

by:Rassac
ID: 22694279
Ooo yeee that changed everything hehe.

Here they go:


Warning: include(class.phpmailer.php) [function.include]: failed to open stream: No such file or directory in c:\Inetpub\wwwroot\phpMailer_v2.2.1\examples\test_gmail.php on line 8

Warning: include() [function.include]: Failed opening 'class.phpmailer.php' for inclusion (include_path='.;C:\php5\pear') in c:\Inetpub\wwwroot\phpMailer_v2.2.1\examples\test_gmail.php on line 8

Fatal error: Class 'PHPMailer' not found in c:\Inetpub\wwwroot\phpMailer_v2.2.1\examples\test_gmail.php on line 11
<?php
 
error_reporting(E_ALL);
//error_reporting(E_STRICT);
 
date_default_timezone_set('America/Toronto');
 
include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
 
$mail             = new PHPMailer();
 
$body             = $mail->getFile('contents.html');
$body             = eregi_replace("[\]",'',$body);
 
$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
 
$mail->Username   = "mygmail@gmail.com";  // GMAIL username
$mail->Password   = "mygmail";            // GMAIL password
 
$mail->AddReplyTo("mygmail@gmail.com","Joe");
 
$mail->From       = "mygmail@gmail.com";
$mail->FromName   = "Joe Doe";
 
$mail->Subject    = "PHPMailer Test Subject via gmail";
 
//$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap
 
$mail->MsgHTML($body);//;
 
$mail->AddAddress("myemail@yahoo.com", "John Doe");
 
$mail->AddAttachment("images/phpmailer.gif");             // attachment
 
$mail->IsHTML(true); // send as HTML
 
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
 
?>

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:jodibean28
ID: 22694301
Is your test_gmail.php file in a different folder than the test_mail.php?
0
 

Author Comment

by:Rassac
ID: 22694321
No in the same folder.
0
 
LVL 1

Accepted Solution

by:
jodibean28 earned 500 total points
ID: 22694348
the error is complaining that it doesn't know what phpmailer is...does the test_mail.php that DOES work have the same include?  
include("class.phpmailer.php");

0
 

Author Comment

by:Rassac
ID: 22694792
Yes they are examples that come with the package. I just changed the email adresses.
0
 
LVL 6

Expert Comment

by:hampus_b
ID: 22696824
0
 

Author Comment

by:Rassac
ID: 22696846
Hi,

I found the problem... the downloaded files had a slight bug. The included files had the incorrect path.

Thanks.
0
 

Author Closing Comment

by:Rassac
ID: 31505311
Thanks. :)
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 look for a specific file type in a local or remote server directory using PHP.

763 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