Sending mail

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
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Sending mail

Post by Ratzzak »

Hi guys,
I have been trying to send a mail thru php for a long time. I am always kicked off with errors, I tries both sendmail and phpmailer, but the farthest I could get was with this code

Code: Select all

 
class gMailer extends PHPMailer {
    /** CHANGE THESE AS REQUIRED **/
    public $From     = "rzphpmailer@gmail.com"; //PUT YOUR ADDRESS HERE
    public $FromName = "rzphpmailer";    //PUT YOUR NAME HERE
    public $Password = "***********";    //PUT YOUR PASSWORD HERE
    
    /** DO NOT CHANGE THESE **/
    public $Host     = "smtp.gmail.com";
    public $Mailer   = "smtp";                     
    public $WordWrap = 75;
    public $Port = "465";
    public $SMTPAuth = true;
    
    
    public function __construct($debug = false){
        $this->Sender = $this->From;
        $this->Username = $this->From;
        $this->SMTPDebug = $debug;
    }
}
 
$mail = new gMailer(false);    //change to true if you are having trouble
$mail->AddAddress('xxxxxxxxxxx@gmail.com', 'addressee name');
$mail->Body = "This is a test message";
$mail->Subject = "Test Message";
if ($mail->send()) {echo "mail sent";}
else{echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;};
 
I dont get an error and at the same time the mail is not sent
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Sending mail

Post by jackpf »

Just use mail().
Post Reply