Solved

Phpmailer test_gmail.php returning a blank page

Posted on 2008-10-11
10
848 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 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 …

615 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