简体   繁体   中英

How do I set up Pear mail?

I'm trying to set up php mail with pear. I've been trying and researching for the past 4 hours without success.

I'm using this 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 = "ssl://mail.example.com";
 $port = "465";
 $username = "smtp_username";
 $password = "smtp_password";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     '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>");
  }
 ?>

And the 'require_once "Mail.php"' is giving this error:

Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in /home/creatif2/public_html/mail.php on line 3 Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.:php/') in /home/creatif2/public_html/mail.php on line 3

Pear and Pear Mail is installed

Auth_SASL 1.0.6 Update Reinstall Uninstall Show Docs Mail 1.2.0 Update Reinstall Uninstall Show Docs Net_SMTP 1.6.1 Update Reinstall Uninstall Show Docs Net_Socket 1.0.10 Update Reinstall Uninstall Show Docs

And I'm quite baffled about it. I think my problem is setting the include path but I'm not getting anywhere with it.

The packages are located within the php folder - (eg home/my_user/php/Mail.php, I'm using Justhost).

The current configuration is .:/usr/lib/php:/usr/local/lib/php

Can someone please explain to me how to reference the Mail.php file properly? Been stuck here the whole morning and afternoon.

Thanks

I had the same problem when trying to send email. You have to install the Pear Mail package with all the dependencies, I couldnt install until reinstall reinstalled the the PEAR Package Manager see http://pear.php.net/manual/en/installation.getting.php I'm sure this will help

Your problem is that you are not using the correct path in the include. Assuming your include path starts in the document root, you should use:

require_once "/home/my_user/php/Mail.php";

Although it might take you some testing to find the correct path for the require

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM