php email form question...
Results 1 to 8 of 8

Thread: php email form question...

  1. #1
    AFLAAACKKK!!
    Join Date
    Apr 2004
    Posts
    1,065

    php email form question...

    I'm currently learning php, I have apache, php, mysql, and a couple other things installed, it was one of those bundle things. So I am readig this tutorial about email forms done in php and I try it myself. My code looks like this:


    <?
    $name=$_POST['name'];
    $email=$_POST['email'];
    $comments=$_POST['comments'];
    $to="kungfukurt@yahoo.com";
    $message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
    if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
    echo "Thanks for your comments.";
    } else {
    echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
    }
    ?>


    I run this code and I get this error:

    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:\apachefriends\xampp\htdocs\phpbitch\mail.php on line 7


    Can someone help me out please?

    Thanks.
    I am the uber duck!!1
    Proxy Tools

  2. #2
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Sorry for this question, but do you actually have a SMTP server on localhost
    running, that is listening on port 25? Otherwise, mail won't work ...

    In case you don't have, you probably need to install a SMTP mailer, like blat[1].
    By the way: A while ago, there was a free IpSwitch Imail version available,
    but unfortunately I am not sure, whether this is that one[2] (I haven't tested it).

    The php.ini-file which actually is used, you can locate using the phpinfo()-command.


    Good luck.

    Cheers

    [1] http://sourceforge.net/projects/blat
    [2] http://www.golddownload.com/IMail_Se...load_2016.html
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  3. #3
    AFLAAACKKK!!
    Join Date
    Apr 2004
    Posts
    1,065
    Well, this mail software called mercury also came in the 'package' known as xampp and when I have that running and try my script I get this error:

    Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\apachefriends\xampp\htdocs\phpbitch\mail.php on line 7
    There was a problem sending the mail. Please check that you filled in the form correctly.

    What does this mean? Maybe I don't have it set for port 25?? Sorry, I'm not that skilled at configuring mail servers and such, I'm just starting to seriously get into web development.

    Thanks again
    I am the uber duck!!1
    Proxy Tools

  4. #4
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    I have no experience with that package xampp, but anyway:
    The message you obtain indicates that a mail server
    is running. There are several issues to consider in
    order that your mail server cannot be misused to send
    spam (so called open relays).

    a) Usually, your mail server delivers any email, when the
    recipient is a local mail account (to be defined). This is
    the case if someone wants to send an email to
    your email address myname@mydomain.com and your
    mail server is responsible for mydomain.com.

    b) Another function of a mail server is, that you, as an
    authenticated user (login), can send email to other people.

    Your error message corresponds to situation b). You try
    to send an email to a non-local address without identifying
    yourself to the mail server.

    That is the situation - but I cannot help you with the configuration
    of xampp mail server (Mercury?). But - if you use the PHPmailer
    class[1], you can configure the authentication process.

    In case you always send the mails to kungfukurt@yahoo.com, you
    could configure php.ini to use yahoo.com as the mail server - if I understand
    the working of mail() correctly ...

    Cheers.

    [1] http://phpmailer.sourceforge.net/
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  5. #5
    AFLAAACKKK!!
    Join Date
    Apr 2004
    Posts
    1,065
    And how can you correctly configure the php.ini file to use a particular mail server?

    Also, could I also use outlook express to do what your suggesting with phpmailer?

    Thanks again, I will take a look at phpmailer.
    I am the uber duck!!1
    Proxy Tools

  6. #6
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Originally posted here by The Duck
    And how can you correctly configure the php.ini file to use a particular mail server?
    In php.ini, there is an option SMTP. Due to the specifications of mail(), this is the
    SMTP-server used to send mail. If the recipient is a local account on that server
    (yahoo.com), the mail can be delivered without authentication.

    Also, could I also use outlook express to do what your suggesting with phpmailer?
    I really do not know what you mean. Phpmailer is a php-class allowing for a more
    detailed configuration than mail - like authentication
    (class SMTP, bool Authenticate (mixed $username, mixed $password) ).

    Cheers
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  7. #7
    AFLAAACKKK!!
    Join Date
    Apr 2004
    Posts
    1,065
    Oh, I thought phpmail as like a mailing program, like outlook express...
    I am the uber duck!!1
    Proxy Tools

  8. #8
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi


    If something is not working as I expect it to do, I am very much
    motivated to track the problem down. Here, mail() did not as wanted.
    See below why.


    The goal: Send an email to a specific address using php. OS: Windows.
    Two ways: phpmailer / php-native mail().


    phpmailer


    I played a little bit with the phpmailer[1] as an alternative, because
    mail() did not work. Make sure to have the files class.phpmailer.php
    and class.smtp.php in the same directory as the following php-script.

    Code:
    require("class.phpmailer.php");
    
    $mail = new PHPMailer();
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host = "yahoo.com"; // SMTP server
    $mail->From = "myself@mydomain.com";
    $mail->AddAddress("avalidaddress@yahoo.com");
    
    $mail->Subject = "PhpMailer test";
    $mail->Body = "Some text";
    $mail->WordWrap = 80;
    
    if(!$mail->Send())
    {
       echo "Message was not sent";
       echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
       echo "Message has been sent";
    }
    As explained in a previous post, no authentication is needed, if we
    use the appropriate mail-server.


    mail()


    Since I do not like "blackboxes", I also worked on how to get the
    same done using the native mail(). Mail() reads in a configuration-file
    php.ini, in which sendmail options (*nix) or mail-server options
    (windows) are set. The reason why mail() did not work:

    mail() seems not to be able to resolve DNS entries!

    Instead of setting the mail-server as "yahoo.com", we have grab one
    out of two solutions:

    - either we put a particular entry in the hosts file (somewhat dynamic)
    - or we directly use the IP address as mail-server (seems to need a restart
    of the apache server)

    First thing: Obtain the IP address of the mail server.

    Code:
    c:\> nslookup
    > set type=mx
    > yahoo.com
    > [a list of IP numbers - pick one, eg. 67.28.113.10]
    Second thing: Configure the php.ini file.

    The current php.ini used by apache/php can be determined using
    Code:
       <? phpinfo() ?>
    Search for the entry SMTP and add yahoo.com
    Code:
    SMTP = yahoo.com
    Open the hosts-file %windir%\drivers\etc\hosts and add
    Code:
    67.28.113.10    yahoo.com
    Restart apache and send an email using
    Code:
      if (mail("avalidaddress@yahoo.com","mail() test","Some text"))
    	echo "Message has been sent";
      else
    	echo "Message was not sent";
    A note of annoyance/hardening: Please make sure that the recipients email
    address is hardcoded. And if not - usually, an email address consists of
    alphanumerics, "-", "_" and one "@" only. There is no need for anything else.

    Cheers!

    [1] http://phpmailer.sourceforge.net/
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •