p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Sending mail using PHP


Message #1 by "Jon Shoreman" <Jon.Shoreman@b...> on Tue, 5 Feb 2002 19:57:11
I have the following command in my PHP code for sending mail:



xmail($To, $Subject, $Message);



How do I set the From and Reply-To sections of the e-mail?
Message #2 by "Nikolai Devereaux" <yomama@u...> on Tue, 5 Feb 2002 12:10:53 -0800

the manual tells you how:



http://www.php.net/manual/en/function.mail.php



you have to use the optional headers param to the function.



good luck,



nik





> -----Original Message-----

> From: Jon Shoreman [mailto:Jon.Shoreman@b...]

> Sent: Tuesday, February 05, 2002 7:57 PM

> To: beginning php

> Subject: [beginning_php] Sending mail using PHP

> 

> 

> I have the following command in my PHP code for sending mail:

> 

> xmail($To, $Subject, $Message);

> 

> How do I set the From and Reply-To sections of the e-mail?




> $subst('Email.Unsub').

Message #3 by "Hermawan Haryanto" <hermawan@h...> on Wed, 6 Feb 2002 03:36:15 +0700
Here is my sendmail script, maybe you can have something from this example.



Thanks

Hermawan Haryanto

hermawan@h...



<?php

class sendmail {

  var $receiver;

  var $sender;

  var $sender_name;

  var $subject;

  var $message;

  function sendmail($receiver,$sender,$sender_name,$subject,$message){

    $this->receiver=$this->recipient($receiver);

    $this->sender=$this->senders($sender,$sender_name);

    $this->subject=$subject;

    $this->message=$message;

  }

  function senders($sender){

    $senders.="From: $sender_name <$sender>\n";

    $senders.="Reply-To: $sender\n";

    $senders.="X-Mailer: script.webdev.kg";

    return $senders;

  }

  function recipient($receiver){

    if(is_array($receiver)){

      for($i=0;$i<count($receiver);$i++){

        $recipients.=$receiver[$i].", ";

      }

    }else{

      $recipients=$receiver.", ";

    }

    $recipients=substr($recipients,0,strlen($recipients)-2);

    return $recipients;

  }

  function sendit(){

    @xmail($this->receiver,$this->subject,$this->message,$this->sender);

  }

};



$receiver[]="hermawan@h...";

$sender_name="Hermawan Haryanto";

$sender="hermawan@h...";

$subject="Testing SendMail";

$message="Testing SendMail";

$sm = new sendmail($receiver,$sender,$sender_name,$subject,$message);

$sm->sendit();

?>

====

----- Original Message -----

From: "Jon Shoreman" <Jon.Shoreman@b...>

To: "beginning php" <beginning_php@p...>

Sent: Tuesday, February 05, 2002 7:57 PM

Subject: [beginning_php] Sending mail using PHP





> I have the following command in my PHP code for sending mail:

>

> xmail($To, $Subject, $Message);

>

> How do I set the From and Reply-To sections of the e-mail?




$subst('Email.Unsub').

>



Message #4 by "Nikolai Devereaux" <yomama@u...> on Tue, 5 Feb 2002 12:49:14 -0800

Is this even LEGAL???



...

>     $this->sender=$this->senders($sender,$sender_name);



>   function senders($sender){

>     $senders.="From: $sender_name <$sender>\n";

>     $senders.="Reply-To: $sender\n";

>     $senders.="X-Mailer: script.webdev.kg";

>     return $senders;

>   }



It seems you're passing two parameters to a function that accepts only ONE,

but then you use both of them anyway.



I'd be surprised if this works.. =)



Maybe you have error_reporting = ~E_ALL in php.ini?  >:)



Message #5 by "Hermawan Haryanto" <hermawan@h...> on Wed, 6 Feb 2002 04:03:21 +0700
Ups...sorry...

It is not LEGAL, but it's work

Please change it to :



functions senders($sender,$sender_name){

...



Thanks

Hermawan Haryanto

hermawan@h...





----- Original Message -----

From: "Nikolai Devereaux" <yomama@u...>

To: "beginning php" <beginning_php@p...>

Sent: Wednesday, February 06, 2002 3:49 AM

Subject: [beginning_php] Re: Sending mail using PHP





>

> Is this even LEGAL???

>

> ...

> >     $this->sender=$this->senders($sender,$sender_name);

>

> >   function senders($sender){

> >     $senders.="From: $sender_name <$sender>\n";

> >     $senders.="Reply-To: $sender\n";

> >     $senders.="X-Mailer: script.webdev.kg";

> >     return $senders;

> >   }

>

> It seems you're passing two parameters to a function that accepts only

ONE,

> but then you use both of them anyway.

>

> I'd be surprised if this works.. =)

>

> Maybe you have error_reporting = ~E_ALL in php.ini?  >:)

>

>




$subst('Email.Unsub').

>




  Return to Index