...

View Full Version : php mail



wayne3503
09-05-2007, 05:40 PM
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

Inigoesdr
09-05-2007, 11:26 PM
Just use a mailing list like PHPList (http://www.phplist.com/).

Pennimus
09-05-2007, 11:31 PM
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 (http://www.php.net/manual/en/function.mt-rand.php). 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 (http://www.php.net/manual/en/function.substr.php)
to extract just the part you need to check against the database.

4) See answer 1.

ScottInTexas
09-06-2007, 12:13 AM
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'


$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.

aedrin
09-06-2007, 12:29 AM
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.

ScottInTexas
09-06-2007, 12:41 AM
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.

Inigoesdr
09-06-2007, 01:19 AM
You need an executable program to send mail.. the dll only adds functionality to a program.

ScottInTexas
09-06-2007, 02:28 AM
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?

CFMaBiSmAd
09-06-2007, 02:55 AM
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.

madmatter23
09-06-2007, 10:10 AM
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

CFMaBiSmAd
09-06-2007, 01:51 PM
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/

wayne3503
09-06-2007, 04:35 PM
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.

CFMaBiSmAd
09-06-2007, 04:56 PM
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.

wayne3503
09-06-2007, 08:13 PM
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.

madmatter23
09-06-2007, 09:21 PM
Wayne,

if you want to send an HTML email rather than simply text, change your variables to to include this:


$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>';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum