views:

53

answers:

2

Designing forms has always been fun, but getting them to send email on the server side is another story. I have used various email scripts (dynaform,phpmailer, etc), and have experienced a ton of problems.

So here is the site I am working on: Contact On the Right. It is very basic: no validation, no required fields. I simply need anything that is entered to be sent back to me.

Does anyone know of any BASIC PHP form processing scripts, or have a few lines of code that would work here? I'm not a PHP guy, so I am struggling!

Thanks in advance.

+1  A: 

I simply need anything that is entered to be sent back to me.

<?php
mail('[email protected]','Site feedback',implode("\n\n",$_POST));
header("Location: thankyou.html");
?>

you can add this tag into thankyou.html:

<META HTTP-EQUIV="REFRESH" CONTENT="5;URL=http://v2.ztmag.com/livedates.html"&gt;

it will get user back in 5 seconds

Col. Shrapnel
Notice: Undefined variable: POST in /home/jessechase/ztmag.com/v2/email.php on line 2Warning: implode() [function.implode]: Invalid arguments passed in /home/jessechase/ztmag.com/v2/email.php on line 2Warning: Cannot modify header information - headers already sent by (output started at /home/jessechase/ztmag.com/v2/email.php:2) in /home/jessechase/ztmag.com/v2/email.php on line 3
JCHASE11
I receive this error message. I do receive an email, but with nothing in it.
JCHASE11
oh my bad. corrected
Col. Shrapnel
Actually this works out fine! Its exactly what I needed, although what is the PHP I need to write for the subject field in the email? I also want the email to be coming from the email address entered in the field
JCHASE11
@JCHASE11 better don't do it, because it will bring your script into spam-gate. You have all info in the email body. that's enough
Col. Shrapnel
Fair enough. I guess It would be nice to have the subject line saying, "Live Date Submission" so I can easily recognize it in my email box, but if not, its no big deal.
JCHASE11
@ JCHASE11 that's not a problem, this one. just change 'Site feedback' to 'Live Date Submission' in the code. You can write anything there save for the user entered data.
Col. Shrapnel
you answered my question perfectly, but I do have another question. Instead of redirecting to a thanks.html page, It would be nice to have a success message delivered on the current page. That is most likely more advanced using ajax, but I figure a simple javascript alert can be used. How would you implement a javascript alert saying, thank you for your message?
JCHASE11
@JCHASE11 there is no simple way to implement ajax or javascript. But I added simple HTML tag to do automatic redirect
Col. Shrapnel
I asked this on another S.O. question, and credited you...This solution is a workaround, but It still involves leaving the page, and then bringing you back, correct? I am looking for a solution that keeps you on the existing page.
JCHASE11
A: 

For simple and hard tasks (it does HTML mail) this library always served me well: PHPMailer

Depending on servers and administrators, sometimes mail() doesn't work. It must be configured to work correctly with smtp or have a sendmail binary installed in the correct path.

PHPMailer, instead, only needs outbound connection trough fsockopen not to be disabled.

A simple tutorial here:
http://www.ustrem.org/en/articles/send-mail-using-phpmailer-en/

A number of CMS uses it internally, too. Joomla, for example.

ZJR
Ive heard about PHPMailer and looked at it. It seemed intimidating. I will give it a shot now.
JCHASE11
The main site *is* intimidating, indeed, and could sport better quick starts, but once you read one from a third party, you're set.
ZJR
this particular third party tut would take me hours to figure out. Again, with little to no experience in PHP, I would have to do a lot of trial and error, which Is why I am searching for a very easy, basic solution
JCHASE11