Page 1 of 2

Mailing in php

Posted: Fri Sep 25, 2009 12:54 am
by Ratzzak
How could i mail using php?

Re: Mailing in php

Posted: Fri Sep 25, 2009 12:56 am
by Griven

Re: Mailing in php

Posted: Fri Sep 25, 2009 1:02 am
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

Re: Mailing in php

Posted: Fri Sep 25, 2009 1:19 am
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

Re: Mailing in php

Posted: Fri Sep 25, 2009 2:17 am
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.

Re: Mailing in php

Posted: Fri Sep 25, 2009 4:00 am
by Ratzzak
Somebody help me out guys. I have been :banghead: for a while

Re: Mailing in php

Posted: Fri Sep 25, 2009 4:32 am
by jackpf
Do you have an SMTP server installed?

Re: Mailing in php

Posted: Fri Sep 25, 2009 4:33 am
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.

Re: Mailing in php

Posted: Fri Sep 25, 2009 4:35 am
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.

Re: Mailing in php

Posted: Fri Sep 25, 2009 4:40 am
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

Re: Mailing in php

Posted: Fri Sep 25, 2009 4:54 am
by jackpf
I'm unfamiliar with phpmailer...

But you could try turning on error reporting. You are including the main phpmailer script right?

Re: Mailing in php

Posted: Fri Sep 25, 2009 5:03 am
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.

Re: Mailing in php

Posted: Fri Sep 25, 2009 5:09 am
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 ;).

Re: Mailing in php

Posted: Fri Sep 25, 2009 5:43 am
by Ratzzak
I tried echoing before and after $mail->send(). Only the content be4 the call has been printed.

Re: Mailing in php

Posted: Fri Sep 25, 2009 8:35 am
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.