Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15

Thread: php mail

  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts

    php mail

    On my site im working on I will be having some forms that will send mail to me once the forms have been filled out. Im looking for a mail script or something that can do these things...

    1) Send mail to me once visitor has filled out the form
    2) Will add the persons email address to a list (db or flatfile, db prefered)
    3) Validate email address with a "click here to verify" link in it, perhaps.
    4) Will allow me to send text and HTML mail

    I think thats it. Any ideas?
    Thanks for the help
    Last edited by wayne3503; 09-05-2007 at 04:48 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Just use a mailing list like PHPList.

  • #3
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    1) http://www.php.net/mail

    2) A standard MySQL insert. Many tutorials out there, eg http://www.tizag.com/mysqlTutorial/mysqlinsert.php

    3) When you add the persons email address to the database, also add a random integer to a second column, generated using mt_rand. Include this integer as a variable tagged on to the end of a verify link in your email that you send. For example, www.domain.com/verify.php?user=12345678.

    Have verify.php check the database for this user and if found, either mark the user as "verified" in a third column, or move the user to another table (neater, imo).

    For extra security, include dummy numbers at the start and end of the integer that you email out, and use substr
    to extract just the part you need to check against the database.

    4) See answer 1.

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    I have been trying to use mail() in my web page. For development I am using localhost on an XP platform. I cannot send an email to myself. mail always returns false. Looking through the documentation at php.net I read that "For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time." If I didn't compile php on my own machine does that mean that I can't test the mail function until it is on the production server?

    My php.ini shows smtp='localhost'
    PHP Code:
                $email $_POST['toadd'] ; 
                
    $subject $_POST['subject'] ;
                
    $headers='From:'.$_POST['fromadd'];
                
    $message=wordwrap($_POST['mailmsg'], 70);
                
    $message=str_replace('\n.''\n..'$message);
                if (
    mail("myaddress@yahoo.com"$subject$message$headers )){
                    echo 
    "Thank you for using our mail form";
                }else{
                    echo 
    "It didn't work.";
                } 
    Do I have to do anything else with the php.ini?

    Thanks.
    Scott Stewart
    Always happy to learn from pros.

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Windows doesn't have sendmail by default. You'll have to find a Windows implementation of it.

    It doesn't matter whether you compiled PHP or not.

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    I have a sendmail.dll in my c:windows/system32 folder. I have also checked to make sure that the folder is in the path environment variable and in the user path variable.
    Scott Stewart
    Always happy to learn from pros.

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You need an executable program to send mail.. the dll only adds functionality to a program.

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    What executable do I need? According to the php documentation on mail() all windows needs is "localhost" as the smtp. But it also says that sendmail has to be present at compile time. Whats up with that?
    Scott Stewart
    Always happy to learn from pros.

  • #9
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,080
    Thanks
    2
    Thanked 321 Times in 313 Posts
    Slow down. Even if you setup a mail server on your local development system, unless it is a properly configured public mail server with proper DNS records pointing to it, you will not be able to send an email to any other mail system. The receiving mail servers simply won't recognize your mail server as a valid server. If you want to go through the trouble of setting up an SMTP mail server, there are several open source/free ones available. You would be able to send an email locally to yourself on your local mail server. I just don't think that this amount of effort will get you very far toward developing and testing your scripts.

    Secondly, PHP on Windows can only use an SMTP mail server. To do this you need to set the SMTP = and smtp_port = settings to point to the SMTP server that you intend to use. You can set these in php.ini, a .htaccess file, or at runtime using ini_set(...) statements in your code.

    Normally, to allow you to test sending email from code on a development system, you use an SMTP server at your ISP or at the hosting company where you will ultimately run the script at.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #10
    Regular Coder
    Join Date
    Jun 2007
    Location
    Maryland, USA
    Posts
    165
    Thanks
    12
    Thanked 0 Times in 0 Posts
    I'm curious about one of wayne's initial questions that went unanswered. #4. Does anyone know how to send an html email using the php mail function?

    I have the function all set up and working for text emails, but I'd like to be able to use html rather than simply text in the email body. Placing <html></html> tags on the ends of the body didn't seem to do the trick.

    Does anyone have any ideas?

    Thanks

  • #11
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,080
    Thanks
    2
    Thanked 321 Times in 313 Posts
    To send just a HTML email, see Example 1110 in the php manual - http://www.php.net/manual/en/function.mail.php

    However, to send both plain text and HTML bodies at the same time (and let the mail client display the one it is capable of/set for), you need to send a multi-part mime message, with mime boundaries, content type headers... The easiest way to do this is to use one of the existing mailer classes, such as the phpmailer - http://phpmailer.sourceforge.net/
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #12
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    wow alot of stuff happened in here. Thank you all for your posts and also, Im not trying to send both html and text at the same time, i just want the flexability to do either. Maybe what I will do is leave it to the site visitor to choose if they want plain text or html.

  • #13
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,080
    Thanks
    2
    Thanked 321 Times in 313 Posts
    Once ScottInTexas hijacked the thread it did get a little off topic.

    I took your "and" in item #4 literally, as it is possible to send both types of message bodies at the same time and let the email client display the one that it can or is set for.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #14
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    well i do have some code to play with now. If anyone else has any code, functions, scripts, or suggestions it all will be appreciated.

  • #15
    Regular Coder
    Join Date
    Jun 2007
    Location
    Maryland, USA
    Posts
    165
    Thanks
    12
    Thanked 0 Times in 0 Posts

    HTML email

    Wayne,

    if you want to send an HTML email rather than simply text, change your variables to to include this:
    PHP Code:
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $headers .= 'From:'.$_POST['fromadd'];
    $message=wordwrap($_POST['mailmsg'], 70);
    $message=str_replace('\n.''\n..'$message);
    $message '<html>'.$message.'</html>'


  •  

    Posting Permissions

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