Mailing in php

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

Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Mailing in php

Post by Ratzzak »

How could i mail using php?
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Mailing in php

Post by Griven »

Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Mailing in php

Post by Ratzzak »

This is the error thrown everytime i try wh the mail function. should i do some configuration changes? Whats going wrong?

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\test\test.php on line 2
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Mailing in php

Post by Griven »

In your php.ini file, you can specify the address of an SMTP server that will send email out for you. You may be able to put the address of your ISP's SMTP server in there.

It would look something like this when you're done.

Code: Select all

[mail function]
; Setup for Windows systems
SMTP = smtp.my.isp.net
sendmail_from = me@myserver.com
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Mailing in php

Post by Ratzzak »

Thanx for the reply.

But I am currently trying in my system(localhost). So I have mentioned smtp = localhost in my ini file.
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Mailing in php

Post by Ratzzak »

Somebody help me out guys. I have been :banghead: for a while
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Mailing in php

Post by jackpf »

Do you have an SMTP server installed?
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: Mailing in php

Post by turbolemon »

That would only work if you were running an SMTP server on your local machine. Assuming that you don't, if you have an external SMTP provider, for example a Gmail account or your ISP, you could probably test using those details.
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Mailing in php

Post by Ratzzak »

Valid point. :lol:
But nope. I thought apache acts as one. :cry: :?:
What am i supposed to do,install a smtp server? IF so, any good suggestions.
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Mailing in php

Post by Ratzzak »

I tried using gmail.

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;};
 
This neither gave me an error nor send me a mail
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Mailing in php

Post by jackpf »

I'm unfamiliar with phpmailer...

But you could try turning on error reporting. You are including the main phpmailer script right?
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Mailing in php

Post by Ratzzak »

It was throwing me an error till i had the host as ssl://smtp.gmail.com. But i after i changed the host to smtp.gmail.com. It stopped prompting me with error but i couldn't receive a mail.
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: Mailing in php

Post by turbolemon »

With the earlier php warning posted by OP, I think error reporting is on.

Code: Select all

$mail = new gMailer(false);    //change to true if you are having trouble
Try changing the false to true - no idea what it does, but it might be interesting to see the result as you seem to be having "trouble".

Try echoing before and after the $mail->send() call. This may determine whether there is an issue with the phpmailer class silently failing. Some may call this shotgun debugging, but it's quick and effective ;).
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Mailing in php

Post by Ratzzak »

I tried echoing before and after $mail->send(). Only the content be4 the call has been printed.
Mike2009
Forum Newbie
Posts: 7
Joined: Fri Sep 25, 2009 3:17 am

Re: Mailing in php

Post by Mike2009 »

I understand you run your script at your own computer. I myself use XAMPP on my desktop computer for testing. It's a complete easy to install package of the php-parser, MySQL-db, Apache webserver and much more such as a mail programm called Mercury Mail which should enable you to run a mail server yourself. This might be what you need.
Post Reply