|
Posted by Matthew Weier O'Phinney on 02/21/05 22:03
* Brett Patterson <brett2@umbc.edu>:
> Hello all. I am new to using PEAR, but not so much to PHP. I was looking
> for a little help.
>
> I'm trying to get my contact script to work with the PEAR::Mail extension.
> So I followed the "tutorial" on pear.php.net about using the object =&
> Mail::factory() and then the object::send() method to send the email. So
> after doing that, I get the following code:
>
> Main.php
>
> $recips = $Recip.'; ';
> $recips .= $Email;
> require_once('config.php');
This could cause errors. It looks like, from below, the name of the file
is 'Config.php'. require/include arguments are CaSe Sensitive -- the
lowercase 'c' would mean it wouldn't be found and loaded.
> $headers['From'] = $Name." <".$Email.">";
> $headers['Subject'] = $Subject;
> $headers['To'] = $Recip;
> $headers['Cc'] = $Email;
An easier way to do the above would be:
$headers = array(
'From' => "$name <$Email>",
'Subject' => $Subject,
'To' => $Recip,
'Cc' => $Email
);
> require_once('Mail.php');
> $mail_object =& Mail::factory($method, $params);
> $mail_object->send($recips, $headers, $message);
> if($mail_object != 'TRUE'){
Okay, here's your error. Try the following:
$sent = $mail_object->send($recips, $headers, $message);
if (PEAR::isError($sent)) {
// Do something with the error
}
The send() method returns either 'true' or a PEAR_Error -- with true
meaning only that the message has been successfully passed on to the
mail transport agent. PEAR::isError() is a static method of the PEAR
package used for testing for errors. NOTE: the $mail_object retains its
state after the send method -- it is still a PEAR::Mail object -- which
evaluates to true ALWAYS -- which is why your code would fail at this
point.
> require_once('PEAR.php');
> $error = PEAR_Error::toString();
> echo "<b>".$error."</b>";
> $_REQUEST['pageid'] = '23';
> }
> else{
> $_REQUEST['pageid'] = '22';
> }
>
>
>
> Config.php
>
> $method = 'smtp';
> //$params['sendmail_path'] = "/usr/sbin/sendmail";
> $params['host'] = "localhost";
> $params['port'] = "25";
> $params['auth'] = "TRUE";
> $params['username'] = "ridgeswi";
> $params['password'] = "**********";
> The email is not sent to either recipient, and I don't get an error, or if I
> do, it has no values:
>
> i.e. [: message="" code=0 mode= level= prefix="" info=""]
>
>
>
> Anyone see anything wrong? Is it perhaps that I'm using tabs instead of
> spaces for indentation or what? Thanks for the help.
PHP evaluates tabs and spaces as simply whitespace; these would not make
a difference.
--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:matthew@garden.org | http://vermontbotanical.org
Navigation:
[Reply to this message]
|