troubleshooting Question

PHP Mail/mime.php

Avatar of steva
steva asked on
4 Comments1 Solution331 ViewsLast Modified:
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.

   // Constructing the email

$sender = ">";          // Your name and email address
$recipient = ">";       // 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


   // 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);
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros