mail problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
puraskar
Forum Newbie
Posts: 9
Joined: Thu Oct 12, 2006 12:42 pm

mail problem

Post 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]
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

use php mailer or swiftmailer

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The property access is likely wrong. But the submission detection could easily be wrong too.
puraskar
Forum Newbie
Posts: 9
Joined: Thu Oct 12, 2006 12:42 pm

how to configure to show error

Post 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
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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.
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post 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);
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

... E_ALL | E_NOTICE...?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

E_ALL includes E_NOTICE already.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

E_STRICT is not included, along with some of the newer settings.
puraskar
Forum Newbie
Posts: 9
Joined: Thu Oct 12, 2006 12:42 pm

great

Post 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
Post Reply