Solved

Phpmailer test_gmail.php returning a blank page

Posted on 2008-10-11
10
794 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
inserting while loop results 2 27
php email 2 24
File submission to SQL Server 1 35
PHP: concatenate query 12 28
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

947 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

17 Experts available now in Live!

Get 1:1 Help Now