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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.