Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP and PEAR mail

Posted on 2009-03-30
12
Medium Priority
?
3,271 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses

824 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