Solved

Phpmailer test_gmail.php returning a blank page

Posted on 2008-10-11
10
806 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 dynamically set the form action using jQuery.

785 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