Click to See Complete Forum and Search --> : sending e-mail via php...issues


pulleys
12-10-2007, 12:14 PM
Hello,

I need to send e-mail via php script. The mail server requires smtp authentication. I am using the pear package to do this but I am having some problems. I receive this error when I try to execute the script:

Call to undefined method PEAR_Error::send()

Pear is installed on the server. How do I get this working? Any particular server settings I need to consider? Thanks for the help.


<?php
require_once "Mail.php";

$from = "myname <myname@myname.com>";
$to = "yourname <yourname@yourname.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.myhost.com";
$username = "user";
$password = "password";

$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>");
}
?>

blakefrance
12-10-2007, 03:43 PM
Do you specifically know why you need to use SMTP at all to process this email. PHP mail() function should work perfectly if your server uses PHP. Some situations this might not be the case. Try this script:

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>

That script is very very raw. And would allow for spam. But it does use the php mail() function to work. It works fine for me.

Blake France
Western Kentucky Web Design (http://www.westkydesigns.com)

mrtblt
07-05-2008, 03:43 PM
I also try to switch to PEAR mail from php mail(). But what i dont understand is


require_once "Mail.php";


What is this and where should i get this file if i have to have such a file?

Sheldon
07-06-2008, 07:13 AM
I also try to switch to PEAR mail from php mail(). But what i dont understand is


require_once "Mail.php";


What is this and where should i get this file if i have to have such a file?


require_once is similar to include
http://php.net/require_once
http://php.net/include

mail.php? I guess holds your mail functions?


Call to undefined method PEAR_Error::send()Are you sue the PEAR Mail Library is installed ?

mrtblt
07-06-2008, 10:01 AM
Of course i know what is "require_once" or "include"

But what i wanted to as was something else. This "mail.php" is a certain file which i have to download from somewhere?

To utilize pear mail function, do i need that certain "mail.php"?

comp_nerd26
10-14-2011, 09:09 AM
the Mail.php file is included in the pear install package