?
Solved

PHP and PEAR mail

Posted on 2009-03-30
12
Medium Priority
?
3,234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
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 count occurrences of each item in an array.
Suggested Courses

800 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