[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3341
  • Last Modified:

PHP and PEAR mail

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
nickl1
Asked:
nickl1
  • 6
  • 4
  • 2
1 Solution
 
GawaiCommented:
the Mail.php locaiton is missing

try
require_once include/PEAR/Mail.php;
0
 
nickl1Author Commented:
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
 
NoiSCommented:
go to a dos prompt e type

> pear install Mail

0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
nickl1Author Commented:
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
 
GawaiCommented:
change this accordingly

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

see whats the result
0
 
NoiSCommented:
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
 
nickl1Author Commented:
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
 
NoiSCommented:
Well, now I guess that your first trouble is solved.
Try sending a simple email using another smtp.

0
 
nickl1Author Commented:
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
 
NoiSCommented:
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
 
nickl1Author Commented:
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
 
nickl1Author Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now