steva
asked on
PHP Mail/mime.php
I'm sending mail with an attachment and am a bit confused over what the return value is from the last line of the code below. If this is actually the PEAR class that's being used the PEAR manual says it's a BOOLEAN if true or a PEAR error object if not true. But this doesn't seem to be what it is. If there's no error I get back something that passes both if($return == "1") and if($return == 1) so I'm not sure if it's a string or an integer. If I force an error in the mail (leave out the '@' in the from email) I get back a string that complains about the from address, but this also passes the two if statements above. So what's the correct way to check for an error from the mail->send() call?
Thanks for any help.
Steve
Thanks for any help.
Steve
<?
include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "me@mybusiness.net>"; // Your name and email address
$recipient = "customer@hisdomain.net>"; // The Recipients name and email address
$subject = "Thank You"; // Subject for the email
$text = 'This is a text message.'; // Text version of the email
$crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
// Add the attachment
$file = "Hello World!"; // actual content of the attachment
$file_name = "Hello text.txt"; // Name of the attachment
$content_type = "text/plain"; // Content type of the attachment
$mime->addAttachment ($file, $content_type, $file_name, 0); // Add the attachment to the email
$body = $mime->get();
$headers = $mime->headers($headers);
// Send the email
$mail =& Mail::factory('mail');
$return = $mail->send($recipient, $headers, $body);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ray. That was the information I needed. gettype() shows that the return is a BOOLEAN when the call succeeds and an OBJECT when if fails. So I guess I need to check the return with is_bool($return) to see if the call succeeded.
Thanks for the points! Best, ~Ray
PHP is a loosely typed language, so many things evaluate the same when tested with == instead of ===