Page 1 of 1

mail problem

Posted: Sat Jul 28, 2007 3:14 pm
by puraskar
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi 

I'm not receiving any email from the code below, can anyone suggest me whats wrong with this?

Code: Select all

class mailer
{
  function mailer($sendername, $mailfrom, $mailsubject, $mailmessage, $mailto, $mailcc="",  $mailbcc="") 
  //constructor
  {
   $this->$mailfrom=$sendername . "<$mailfrom>";
   $this->$mailsubject=$mailsubject;
   $this->$message=$mailmessage;
      
   if(is_array($mailto) && sizeof($mailto))
   {
     $this->$mailto= join($mailto,",");
   }
    else
   {
      $this->mailto=$mailto;
   }
   
   if(is_array($mailcc) && sizeof($mailcc))
   {
      $this->mailcc=join($mailcc,","); 
   }
   else
   {
      $this->mailbcc=$mailbcc;
   }

  } //end of emailer constructor
  
 function sendemail()
 {
   $this->headers="From: ". $this->mailfrom;
   if($this->mailcc)
   $this->headers.="Cc: ".$this->mailcc;
   if($this->mailbcc)
   $this->headers.="Bcc: ".$this->mailbcc;
     return mail($this->mailto, $this->mailsubject,$this->message, $this->headers);
 } //end of send mail function 
 } //end of class



if($_POST["submitted"]==1)   //it works utphere.
   {
    $objmailer = new mailer("EWS","correct@mailaddress.com","Test mail",$_POST["txtmessage"],$_POST["txtmailto"],"correct@mail2.com","correct@mail3.com");
    $objmailer->sendemail();
  }

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

use php mailer or swiftmailer

Posted: Sat Jul 28, 2007 4:28 pm
by yacahuma
why dont you try to use phpmailer or swiftmailer .Dont reinvent the wheel.

http://www.swiftmailer.org/

http://phpmailer.sourceforge.net

I personaly use phpmailer( have not use swiftmailer). What I like about it is the debug mode where you see everything that is going on. It make since easy when
trying to find out why is not working

Posted: Sat Jul 28, 2007 5:22 pm
by feyd
The property access is likely wrong. But the submission detection could easily be wrong too.

how to configure to show error

Posted: Sun Jul 29, 2007 3:10 am
by puraskar
thanks for that for both.

the post recognition is correct though its temporary.

would be great to know what's wrong in function calling.

my real problem is: this doesn't show an error. why PHP doesn't show any error? insted of showing an error, it just ingore the page. shows a blank page if there is any error.

about phpmailer.... yes. that could be another option. thanks for that.

many thanks

Posted: Sun Jul 29, 2007 3:22 am
by miro_igov
Wrong

Code: Select all

$this->$message=$mailmessage;
Correct

Code: Select all

$this->message=$mailmessage;
Displaying blank page with no errors means that you have disabled display_errors in your php.ini file.

Posted: Sun Jul 29, 2007 3:22 am
by phpdevuk
many php hosts and configs have errors turned off to suppress these messages in the production environment, try adding a line at the top of your php page or in your constructor like the following;

Code: Select all

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ini_set("display_errors",1);

Posted: Sun Jul 29, 2007 8:29 am
by superdezign
... E_ALL | E_NOTICE...?

Posted: Sun Jul 29, 2007 8:30 am
by feyd
E_ALL includes E_NOTICE already.

Posted: Sun Jul 29, 2007 8:55 am
by superdezign
feyd wrote:E_ALL includes E_NOTICE already.
I thought E_ALL was missing one of them. Was it E_WARNING?

Edit: I doubt it's E_WARNING...

Posted: Sun Jul 29, 2007 9:21 am
by feyd
E_STRICT is not included, along with some of the newer settings.

great

Posted: Sun Jul 29, 2007 10:16 am
by puraskar
great,

every help was equally helpful.

as well as the problem was also in header section which was not letting the system to send an email.

It was a great help.

thanks