Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2007, 04:40 PM   PM User | #1
wayne3503
Regular Coder

 
Join Date: Jul 2007
Posts: 108
Thanks: 0
Thanked 2 Times in 2 Posts
wayne3503 is an unknown quantity at this point
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..
wayne3503 is offline   Reply With Quote
Old 09-05-2007, 10:26 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Just use a mailing list like PHPList.
Inigoesdr is offline   Reply With Quote
Old 09-05-2007, 10:31 PM   PM User | #3
Pennimus
Senior Coder

 
Join Date: Jul 2005
Location: UK
Posts: 1,051
Thanks: 6
Thanked 13 Times in 13 Posts
Pennimus is on a distinguished road
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.
Pennimus is offline   Reply With Quote
Old 09-05-2007, 11:13 PM   PM User | #4
ScottInTexas
Regular Coder

 
Join Date: Nov 2002
Posts: 567
Thanks: 2
Thanked 4 Times in 4 Posts
ScottInTexas is on a distinguished road
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.
ScottInTexas is offline   Reply With Quote
Old 09-05-2007, 11:29 PM   PM User | #5
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
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.
aedrin is offline   Reply With Quote
Old 09-05-2007, 11:41 PM   PM User | #6
ScottInTexas
Regular Coder

 
Join Date: Nov 2002
Posts: 567
Thanks: 2
Thanked 4 Times in 4 Posts
ScottInTexas is on a distinguished road
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.
ScottInTexas is offline   Reply With Quote
Old 09-06-2007, 12:19 AM   PM User | #7
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
You need an executable program to send mail.. the dll only adds functionality to a program.
Inigoesdr is offline   Reply With Quote
Old 09-06-2007, 01:28 AM   PM User | #8
ScottInTexas
Regular Coder

 
Join Date: Nov 2002
Posts: 567
Thanks: 2
Thanked 4 Times in 4 Posts
ScottInTexas is on a distinguished road
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.
ScottInTexas is offline   Reply With Quote
Old 09-06-2007, 01:55 AM   PM User | #9
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,712
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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.
CFMaBiSmAd is offline   Reply With Quote
Old 09-06-2007, 09:10 AM   PM User | #10
madmatter23
Regular Coder

 
Join Date: Jun 2007
Location: Maryland, USA
Posts: 165
Thanks: 12
Thanked 0 Times in 0 Posts
madmatter23 is an unknown quantity at this point
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
madmatter23 is offline   Reply With Quote
Old 09-06-2007, 12:51 PM   PM User | #11
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,712
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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.
CFMaBiSmAd is offline   Reply With Quote
Old 09-06-2007, 03:35 PM   PM User | #12
wayne3503
Regular Coder

 
Join Date: Jul 2007
Posts: 108
Thanks: 0
Thanked 2 Times in 2 Posts
wayne3503 is an unknown quantity at this point
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.
wayne3503 is offline   Reply With Quote
Old 09-06-2007, 03:56 PM   PM User | #13
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,712
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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.
CFMaBiSmAd is offline   Reply With Quote
Old 09-06-2007, 07:13 PM   PM User | #14
wayne3503
Regular Coder

 
Join Date: Jul 2007
Posts: 108
Thanks: 0
Thanked 2 Times in 2 Posts
wayne3503 is an unknown quantity at this point
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.
wayne3503 is offline   Reply With Quote
Old 09-06-2007, 08:21 PM   PM User | #15
madmatter23
Regular Coder

 
Join Date: Jun 2007
Location: Maryland, USA
Posts: 165
Thanks: 12
Thanked 0 Times in 0 Posts
madmatter23 is an unknown quantity at this point
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>'
madmatter23 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:12 AM.


Advertisement
Log in to turn off these ads.