I am using this PHP form builder class but I think I'm missing the very basic which is how to send the email. I know enough php to download and modify the code but not quite sure how to implement:
mail(to,subject,message,headers,parameters)
Does anyone know how to get this working and send the email to myself when the form is submitted?
Take a look at the PHP documentation, or better use some abstracted class like swiftmailer. Swiftmailer will save you some hassle down the line, as it sets the headers correctly and is independant from the mail subsystem.
Here is a basic example how to include swiftmailer
You don't have to implement the mail function, it should already be there and it has been there by default since PHP 4.
If you're not finding a mail function (or if it is not working), then chances are that you are not running on a machine where PHP has access to the sendmail command. You can read about the requirements of the mail function here. If this is the case (and you have to be able to test the emails), then you will need to get a mail server. If you're on Windows, I know that XAMPP comes with one, but I normally do that sort of development with a Linux box.
Related
I have ftp access to a server which hosts a web site made with typo3. The web site in typo3 has a contact form somewhere, but I don't have any specifics, for I am not a typo3 developer at all.
I now want to add to that very server a simple service that takes POSTed form data and generates a mail. I have tried a very simple PHP script:
<?php
mail("support#mydomain.com", "Bug report", "A new bug report was submitted: " + json_encode($_POST));
echo("<html><head><title>Thank you for your report</title>...
...
?>
The rest of the script works (it is executed and echo outputs the correct HTML based on the locale), but the mail isn't sent out. I found that the php mail function is unreliable, so I decided to find another way.
How can I find out how typo3 sends its mails?
Can I use typo3 code to send mails, and if yes, which scripts do I have to import?
Could I possibly destroy anything in the typo3 web site by importing typo3 scripts into my script?
TYPO3 uses SwiftMailer to send mails. You can find it in the contrib directory (the place of this directory depends on which TYPO3 version you use). TYPO3 only adds a wrapper class to use the mailtransport configuration (mbox, mail(), sendmail, SMTP) which can be set in the Install Tool.
You can use SwiftMailer in your own code, but you have to use your own configuration.
Once or twice a year i find myself in the position of having to develop complex emails.
They often include Plaintext and Html versions, along with attachments and other headers.
Previewing the development using standard send/receive is painfully slow and tedious.
What i'm looking for is a local testing platform that processes the mail function and provides a mail client style preview with access to alternate views, headers, etc. Or possibly a real mail client that can take mail directly.
I've searched and searched but no luck so far, hopefully someone can point me in the right direction.
Thanks in advance. TT
I'm not sure if this is what you want but you can use your localhost mail and access it via thunderbird for example
How do I read local email in thunderbird? - Ask Ubuntu
Via this way you don't have to wait endless for mail to be delivered as it's local. And you can see your send mail in a actual mail client
I don't know any software but I had some good experience with the following online service: http://litmus.com/ It's somewhat like browserstack. (live crossbrowser testing tool)
I use Papercut, which listens to a SMTP port, catchs all e-mails and shows headers, source, text and html view. It's very useful!
I have now solved this.
In the php.ini file there is an option to set an export path for the mail function called sendmail_path.
I set this to tee mail.eml > /dev/null and it now saves the sent mail to the same directory as where the function is called and i simply open it with my mail client.
sendmail_path = tee mail.eml > /dev/null
2 notes on this.
this is a solution for unix platforms only.
the file extension has to be set to suit your chosen mail client
For a task like this I use fakemail for receiving the mails into a maildir and mutt for reading the mails. Mutt can also be configured for reading HTML mails.
If you just want to log the emails without reading them, you could use the "logmail" approach described in this article by Chris Shiflett:
Edit: The lastcraft.com host seems to be down at the moment, my Google search for "fakemail" revealed this Python project that might be helpful: https://github.com/isotoma/FakeEmail
If you're just looking to preview your HTML emails (and alternatively, if you need help designing them) you can sign up for a free MailChimp account. It's actually an email send service, but they also have an interface for a drag-and-drop email builder.
For your situation, you could use the "code your own" tool, drop in your HTML, CSS, plain text, etc. and then preview the email in all sorts of email clients, test at different screen resolutions, etc.
(*I am not affiliated with MailChimp)
You can also try https://github.com/ycecube/phpmaildebug.
It uses the php's sendmail output to capture the mails.
I have a PHP form simply using mail() function of PHP. After i changed my server emails to use SSL (Secure-SMTP,Secure-IMAP,Secure-POP) the form don't send emails to account#mydomain.com , I think it's because of the protocol changes and hope someone can help me with this.
Also I tried to use SMTP Authentication in my PHP codes using SSL (to see if it can solve my problem) but i don't know what is the included file at the first of this example: http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
The example you posted describes how to send mail with the Mail Pear library. So the
require_once "Mail.php"; instruction simply loads this Pear library.
It assumes you have correctly installed it, see pear documentation.
Another good library for mail via php is phpmailer!
I have a question about PHP.
I want to create a really simple page with only one function.
a text box, and a button to send it to my e-mail address.
**/ I don't really even get the concept of a .php file, or how to implement it to a html file (or do I just create a php file?)
I've been surfing on the web for a way, but quite can't get it.
If you can give me some advice on it, I'd really appreciate it.
I wrote the program, but won't send it to the address("itoyanlifelog#gmail.com").
I'm running it on MAMP, local server.
1) use php mail() function: http://fr2.php.net/manual/en/function.mail.php
2) if you are on a local machine be sure that you can send emails from local. Take a look here: http://wiki.uniformserver.com/index.php/PHP_mail_function
i tried googling but sadly i get only documentations (or am i using bad keywords)
anyway
i can see that alot of programmers (even those im working with right now) does not seem to approve to using the php native mail function and resorts to using some other framework like sendmail? swift mailer etc...
i'd like to know why? are there really disadvantages to using the native mail function?
if so how does the mailing frameworkds solve that or how are they better??
There's nothing wrong with it for sending simple plain text emails.
However, once you get into multipart mime emails (say, you want an HTML version or to add an attachment) then you have to build the email yourself, and it can be quite tricky to get all the headers and encoding correct. In this case you're better off using a library.
The PHP manual for function mail mentions that there are some restrictions with the mail function and one of these are that the function opens and closes an SMTP socket for each email. The mail function works good when you just want to send a mail or two.
As far as I'm concerned, all of these problems pale in comparison to the major security problem:
Mail header injection: ( http://en.wikipedia.org/wiki/E-mail_injection , and php specific info: http://www.damonkohler.com/2008/12/email-injection.html )
Whereby a spammer bot spiders your site and, finding a vulnerability in your script that is easy to still have when using the very insecure mail() function, IS ABLE TO SEND EMAIL FROM YOUR SERVER TO AN ARBITRARY LIST OF CONTACTS, essentially turning your script & server into a cog in their spam email machine.
I recommend never using mail() with user input, and in general, just making use of PEAR::mail instead. http://pear.php.net/package/Mail/
Using PHP's mail() function requires a properly configured sendmail or equivalent on the host the program is running. However, the Windows implementation is a bit different. If you don't have your MTA configured properly, you won't be able to successfully send emails from your PHP scripts. Like another commenter said on this thread, PHP manual explicitly states that each call to the mail() function opens and closes a socket. This can cause unnecessary delay in script execution.
Additionally, your development and testing environment may not have a public static IP address. Your IP address might be blacklisted by DNSBL, Gmail, Yahoo! and other popular email service providers.
Your best bet in this situation is to use a properly configured external SMTP server. Chances are your employer has already provided an email account with SMTP access. If you don't have one you can use a Gmail account. Gmail provides SMTP access to all email accounts.
You can write scripts to open a socket connection to the external SMTP server. When there are tried and tested open source libraries for this purpose, why write your own?
Incidentally, I wrote a blog post on the very same subject yesterday: Using SMTP With Zend Framework - Solve Email Delivery Problem
Best regards,