Solved

PHP and PEAR mail

Posted on 2009-03-30
12
3,180 Views
Last Modified: 2012-05-06
Since, PHP's mail() function will not allow the use of a usernames/password combination, I began experimenting with PEAR.

I installed PEAR on my Windows system I using c:\php5\go-pear

To see what is currently installed under PEAR, I was able to use "pear list".

However, when I run the following code:

<!-- ---------------------------------------------------------- //-->

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

//$host = "mail.example.com";
$username = "me@example.com";
$password = "mypass";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

<!-- ---------------------------------------------------------- //-->

I receive the following error message:
HP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'Mail.php' (include_path='.;C:\\php5\\pear') in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Chapter04\\mailTest2.php on line 4
0
Comment
Question by:nickl1
  • 6
  • 4
  • 2
12 Comments
 
LVL 20

Expert Comment

by:Gawai
Comment Utility
the Mail.php locaiton is missing

try
require_once include/PEAR/Mail.php;
0
 

Author Comment

by:nickl1
Comment Utility
I tried your suggestion and received the following: Failed opening required 'include/PEAR/Mail.php' (include_path='.;C:\\php5\\pear') in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Chapter04\\mailTest2.php on line 4

If I do a search on Mail.php, I can't find the file.

However, I do have:
mime.php
mimeDecode.php
mimePart.php
0
 
LVL 11

Expert Comment

by:NoiS
Comment Utility
go to a dos prompt e type

> pear install Mail

0
 

Author Comment

by:nickl1
Comment Utility
I entered the DOS command you specified (C:\PHP5\PEAR>pear install mail) and I received the following:
------------------------------------------------------------------------------------------------
Did not download dependencies: pear/Net_SMTP, use --alldeps or --onlyreqdeps to download automatically
pear/Mail can optionally use package "pear/Net_SMTP" (version >= 1.1.0)
downloading Mail-1.1.14.tgz ...
Starting to download Mail-1.1.14.tgz (17,537 bytes)
......done: 17,537 bytes
install ok: channel://pear.php.net/Mail-1.1.14
------------------------------------------------------------------------------------------------
I now have the following in my PEAR\Mail directory:
mail.php
mime.php
mimeDecode.php
mimePart.php
null.php
RFC822.php
sendmail.php
smtp.php
------------------------------------------------------------------------------------------------
Howerver, if I attempt to run my original post, in the Apache error.log file I recieved:

[Mon Mar 30 18:13:56 2009] [error] [client 127.0.0.1] PHP Warning:  include_once(Net/SMTP.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in C:\\PHP5\\PEAR\\Mail\\smtp.php on line 206
[Mon Mar 30 18:13:56 2009] [error] [client 127.0.0.1] PHP Warning:  include_once() [<a href='function.include'>function.include</a>]: Failed opening 'Net/SMTP.php' for inclusion (include_path='.;C:\\php5\\pear') in C:\\PHP5\\PEAR\\Mail\\smtp.php on line 206
[Mon Mar 30 18:13:56 2009] [error] [client 127.0.0.1] PHP Fatal error:  Class 'Net_SMTP' not found in C:\\PHP5\\PEAR\\Mail\\smtp.php on line 210
0
 
LVL 20

Expert Comment

by:Gawai
Comment Utility
change this accordingly

require_once path/to/Mail.php; // or in small letter mail.php

see whats the result
0
 
LVL 11

Expert Comment

by:NoiS
Comment Utility
Now you have the class mail and need the class net_SMTP

run
> pear install net_SMTP

Justo add your pear dir to the path or use the complete path to pear/mail.php to your script.

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.

 

Author Comment

by:nickl1
Comment Utility
I ran "pear install net_SMTP" and received the following:
------------------------------------------------------------------
C:\PHP5\PEAR>pear install net_smtp
Did not download optional dependencies: pear/Auth_SASL, use --alldeps to download automatically
pear/Net_SMTP can optionally use package "pear/Auth_SASL"
downloading Net_SMTP-1.3.2.tgz ...
Starting to download Net_SMTP-1.3.2.tgz (10,247 bytes)
.....done: 10,247 bytes
downloading Net_Socket-1.0.9.tgz ...
Starting to download Net_Socket-1.0.9.tgz (5,173 bytes)
...done: 5,173 bytes
install ok: channel://pear.php.net/Net_Socket-1.0.9
install ok: channel://pear.php.net/Net_SMTP-1.3.2
------------------------------------------------------------------

When I ran the "pear list", I receive the following:

INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
=========================================
PACKAGE          VERSION STATE
Archive_Tar      1.3.2   stable
Console_Getopt   1.2.3   stable
Mail             1.1.14  stable
Mail_Mime        1.5.2   stable
Mail_mimeDecode  1.5.0   stable
Net_SMTP         1.3.2   stable
Net_Socket       1.0.9   stable
PEAR             1.7.2   stable
Structures_Graph 1.0.2   stable
----------------------------------------------------------

When I run the original code posted, it still isn't working. Also, now when I check the error log in Apache, I don't see any errors.
0
 
LVL 11

Expert Comment

by:NoiS
Comment Utility
Well, now I guess that your first trouble is solved.
Try sending a simple email using another smtp.

0
 

Author Comment

by:nickl1
Comment Utility
I tried sending to another SMTP and I still get an "HTTP 500 Internal Server Error", but nothing is showing up in the Apache error log.
0
 
LVL 11

Accepted Solution

by:
NoiS earned 300 total points
Comment Utility
Seems that you have some kind of connection trouble.
You need

Another thing

Try using only the email address instead name<email>

$from = "sender@example.com";
$to = "recipient@example.com";

If you running on windows these is a problem
0
 

Author Comment

by:nickl1
Comment Utility
I tried what you suggested, but I get the same message "HTTP 500 Internal Server Error" and nothing is still showing up in the Apache error log.
0
 

Author Closing Comment

by:nickl1
Comment Utility
My question was never answed and I can't ask another question without:

1). Awarding someone points.
2). Filling out this additonal comment.

You should provide a way to simply delete the question if nobody is even in the ballpark!!!!!!!!!
0

Featured Post

What Security Threats Are You Missing?

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.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
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 …

771 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

11 Experts available now in Live!

Get 1:1 Help Now