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.
I simply need anything that is entered
to be sent back to me.
<?php
mail('your#mail.here','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">
it will get user back in 5 seconds
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.
Related
Is it possible to include a separate html page in a php email?
Example, create a separate page that has all the content on it I want to email it and then include it in a php mail() on another page as the message?
Thanks
If you meant sending HTML email, yes. You can do that. You just need to add additional headers in the fourth parameter of mail() and pull the information from the HTML file you have using file_get_contents(). Please check this:
http://css-tricks.com/sending-nice-html-email-with-php/
Yes, it's possible exactly how rationalboss explained. Personally I use PEAR for html emails. It's a pain to get started with if you're not familiar to PEAR, but life has improved once I got it going.
Careful though, html/css does not have the same support in email clients that it does in browsers. You can create a beautiful page and find out that most people receive it with huge glitches due to certain CSS rules being ignored.
Best practice last I heard is to keep it simple and use inline styles for everything. Avoid floats and positioning. In fact, I believe it is actually still safer to use tables when dealing with email layouts if you need things to sit next to each other.
And then test in as many email clients as you can. Then cry and try to fix things.
I hear good things about Email on Acid for testing. It's a pay service but they offer a limited test for 3 clients as well.
If you're just doing a relatively simple email then it shouldn't be too bad. But if you're trying to make something that really looks great I recommend doing some googling on styling html specifically for emails.
After searching for days on how to do this I came across this question:
Send email using the GMail SMTP server from a PHP page
Seems like exactly what I have been trying to achieve but I have had no success, maybe it's because I don't know how to do the HTML to work with this code?
for testing purposes I tried the code on the top voted question on the link I pasted and
made a button that when you click it, it would go to the PHP file (No success).
You can't do it with PHP only, because mail() doesn't support authentication. You have to use a mailing library.
I recommend SwiftMailer which is easy to use, supports many features (authentication, sending HTML mails, attachments, etc.), and is well documented.
You also need to send over tsl/ssl which is why your mail function is not working.
Solution with tsl/ssl already exists here: Using php's swiftmailer with gmail
Check http://neo22s.com/send-email-using-gmail-and-php/ and http://webcodingeasy.com/PHP-API039s/Send-email-from-Gmail-using-PHP
I have a Joomla website up and running and need to set up a simple contact form.
The problem is, whenever Joomla tries to send an email, the page will hang for about a minute before I get a response. The mail will ultimately be sent fine, but the delay is way too big. I've tried setting the outgoing mail setting to PHP Mail, Sendmail and an SMTP server, all with the same effect.
Curiously, if I edit components/com_contact/controllers/contact.php and replace the lines that send the mail with a simple call to mail(), everything works fine.
Using Joomla 1.6.5, CentOS5 with PHP 5.3.
Anyone experienced something similar? Thanks in advance!
(Also, is this a case for StackOverflow or ServerFault? It seems borderline!)
Updated: Narrowed this down to PHPMailer using uniqid to generate its boundary strings. It seems that on some platforms, uniqid (without the more_entropy flag) is extremely slow.
If anyone else ever comes across the same problem, edit libraries/phpmailer/phpmailer.php and in the first few lines of the CreateHeader() function, pass true as the second argument of uniqid(). Seems to have fixed it.
Narrowed this down to PHPMailer using uniqid to generate its boundary strings. It seems that on some platforms, uniqid (without the more_entropy flag) is extremely slow.
If anyone else ever comes across the same problem, edit libraries/phpmailer/phpmailer.php and in the first few lines of the CreateHeader() function, pass true as the second argument of uniqid(). Seems to have fixed it.
I have created a small script that sends a multipart email via php the mail() (that has been a challenge in itself!).
When I test the script and send and email it all works fine, but when I try another address (one which has the same domain as the server) the email appears blank. All the content is there when you look at the raw code, but nothing displays.
I solved the problem by removing the doctype tag from the code and left everything bare coded.
I also noticed the php variable
$body=' (html code here) '
The whitespace after ' was causing the email to show up empty sometime... I'm not exactly sure why!
I have encountered a similar issue and it was because I had a website www.example.com sending an email to me#example.com but the web server and email servers were on different machines. I had to ask the host to sort it so that the website wouldn't try to route emails within the server itself.
I managed to sort this by changing my own code to instead using something a little more supported - phpMailer.
I found this very easy to use and install into my own code. Also giving me as much flexibility as I had with my original code.
I guess though this isn't sorting the original problem, but it did seem to sort on my code.
I have a place where I want users to submit emails for newsletter subs and a place to submit an entire contact form. Zero php knowledge outside of know that it can do what I need.
There's a mail function built-in, take a look at
http://php.net/manual/en/function.mail.php
you will however, need to format the email body with the form data posted, of course.
Check out FormToEmail. From their site:
FormToEmail is a PHP form mail script.
It comes in a free version and a Pro
version. It processes web forms and
sends the contents of the form to you
by email. It will process any form. It
doesn't make forms but it comes with
HTML code for a basic contact form
that you can use on your website. It
is very secure and cannot be hijacked
by spammers. It is very simple to
install, you only need to add your
email address to it. Step-by-step
instructions written in plain English.
Actually, you don't need to do any php programming to create a such a setup. There are plenty of mailing list software apps available and you can grab a formmail script (like the one from Matt's Script Archive) and build the html with the right fields.
Use the mail function.
However be aware that you need to specify the correct headers yourself if you want to use html in your emails!
A common beginner's mistake is assuming you can simply use html tags with mail and it should work automatically.
Figured this was worth mentioning, since you are wanting to do a newsletter. If you try sending the email, and the raw html tags seem to appear in the message, this is your issue :)
As someone who is a PHP know-nothing, I often look for easy solutions to complex problems. Using a super simple PHP form can have some downsides such as getting massive amounts of spam if you don't have any measures to prevent that, setting up those measures is hard to do if you do not have any knowledge of PHP.
Here is what I found, there is a script here: http://www.dagondesign.com/articles/secure-php-form-mailer-script/
that you can download at no charge and the developer seems to have a lot guidance on how to install and use. I was able to set it up and get it to work.. not without having to spend quite of bit of time reading and trouble shooting. Hope that helps you.