Solved

Phpmailer test_gmail.php returning a blank page

Posted on 2008-10-11
10
783 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
  • 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
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 …

762 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

19 Experts available now in Live!

Get 1:1 Help Now