Solved

PHP and PEAR mail

Posted on 2009-03-30
12
3,185 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
ID: 24022306
the Mail.php locaiton is missing

try
require_once include/PEAR/Mail.php;
0
 

Author Comment

by:nickl1
ID: 24022588
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
ID: 24023024
go to a dos prompt e type

> pear install Mail

0
 

Author Comment

by:nickl1
ID: 24024203
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
ID: 24026296
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
ID: 24027957
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
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.

 

Author Comment

by:nickl1
ID: 24028868
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
ID: 24029284
Well, now I guess that your first trouble is solved.
Try sending a simple email using another smtp.

0
 

Author Comment

by:nickl1
ID: 24030519
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
ID: 24031032
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
ID: 24031193
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
ID: 31564487
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

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
Load google maps api into wordpress 5 35
php refresh button on the browser 2 35
Whether to use true/false, yes/no or 0/1 11 50
Update from TABLE-A to TABLE-B 5 34
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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

930 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