PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 30, 2022

[FIXED] How do I set up Pear mail?

 August 30, 2022     email, pear, php, smtp     No comments   

Issue

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


Solution

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



Answered By - aurbano
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing