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.
Related
I am hosting my website on https://www.gandi.net/en , thing is they don't allow connections over ssh only sftp.
I have a form on my website and want to allow user to contact me through that form. In other words an e-mail needs to be sent from form#mydomain.com to me#mydomain.com.
In order to do that there are a couple of options I tried, but none of them seems to work:
1) PHP's mail function: doesn't support authentification. In order to send an e-mail from form#mydomain.com I need to authenticate. And that doesn't seem to be possible with the mail-function
2) PHPMailer: I saw many people recommending this solution. I downloaded their sources and had a look. It seems like in order for it to work you need to actually install PHPMailer using composer. I can't run composer via sftp...
What other solutions exist? Or what workaround exists?
Thanks!
2) PHPMailer: I saw many people recommending this solution. I
downloaded their sources and had a look. It seems like in order for it
to work you need to actually install PHPMailer using composer. I can't
run composer via sftp...
You don't need to run composer, just download the PHPMailer files manually and upload it via sftp. Composer just makes it easier to install packages, the PHPMailer itself existed long before Composer was a thing.
If you don't know how to install it without Composer, take a look at this answer.
You can give swiftmailer a try: https://swiftmailer.symfony.com/
It is used by Yii2 Framework as well.
If I am not mistaken, for most if not all PHP extensions, you can integrate it into your website by using composer from your own development machine, and then you'd upload the source using FTP. You don't need to use composer on the host server.
I have used swiftmailer with Yii2 websites on a public host and I didn't have to do any special setup on the host.
If all else fails, change host. Get a refund and use your new host's web transfer services to move with minimum effort.
Looks like if you use a SPF TXT record in your DNS setup for their Simple Hosting package, you should be able to use mail() as-is without having to authenticate to your mail host:
# 10800 IN TXT "v=spf1 ip4:217.70.176.0/21 ip6:2001:4b98:c::/48 ip4:217.70.185.10 ip4:173.246.97.150 ip4:217.70.186.165 ptr ?all"
Source:
http://wiki.gandi.net/en/dns/zone/spf-record
Which has this quote:
This Simple Hosting records is only used if you plan to send e-mails through your website (via contact form, etc..)
After you've submitted each of these changes, be sure to activate the new version of your zone file, and keep in mind that it will take about 3 hours for it to take full effect due to the standard DNS propagation delay.
You can confirm the SPF TXT record is deployed using various online SPF testing tools.
Since a lot of users have the ability to edit StackOverflow posts, I recommend going to the source and copying and pasting the appropriate SPF record directly to avoid shenanigans. Also the Gandi Wiki will always have the latest list of IPs whereas this post may go stale after 6 months.
I recommend Composer-less CubicleSoft Ultimate E-mail Toolkit or one of the other already mentioned libraries over directly using the built-in PHP mail() function. The PHP mail() function is very misleading. It simply drops a properly prepared mail message into the mail queue on the local host. However, e-mail is very complex and really needs a library even for the most basic PHP mail() use-cases.
If you want to use one of the other Composer-enabled libraries but don't want to upload thousands of little rinky-dink files that comes with Composer-enabled software, then check out CubicleSoft Decomposer. Decomposer takes an entire Composer project tree and generates standalone builds with 1-2 files as the output.
I currently have a static website that I am trying to send an email form from. I am using a simple HTML form with fields such as name, email, message, etc. The PHP form is also very straight forward. I don't think there are any problems with the code. In fact, the code is basically exactly like any online tutorial you'd find (http://www.freecontactform.com/email_form.php). I think the problem has to do with the config on the server. I have a Digital Ocean server with Nginx. At first, when I tried to submit the email form I was getting a 405 error. Now that I handle 405 errors in the config file, I am getting the PHP form as a download when I hit the submit button. What do I need to install on the server or include in the config file to make this PHP email form work?
Edit/Update: I have installed Postfix on my web server and am able to successfully send emails from command line using Postfix to different emails outside the server (for instance, I can send from my root user to my personal email addresses on Gmail, etc.). I now have another problem...
This still doesn't help me on the front-end. When I try to click the submit button on the web page form it is still just downloading the PHP file. I think I am missing something in the php.ini folder and maybe some other things as well. Even though I have mail set up on the server, the PHP action button has no idea that it's set up or something along those lines.
You need to install a Mail Transport Agent (MTA) like postfix or exim4. I think you can configure nginx to rely emails to another smtp server.
Another way, would be installing swiftmailer and connect it with an email sending service as sendgrid, mandrill, sparkpost, etc.
Edit:
I personally recomend a sending service as they have white-listed IP for their sending services plus you save memory in your VPS server (as an MTA daemon is not required to run there).
I'm using sparkpost for a few projects and is working perfectly. They have a pretty high limit for a free account.
With any service you choose, ensure to enable DKIM and SPF to avoid been detected as spam.
I am really confused on where to start with sending emails. I have search the web but the amount of content available for different packages and softwares has really confused me. I was wondering if anyone here had a simple or knows of a simple tutorial of how i can send an email using xampp.
Im new to using local host and so far have only used MySQL and Apache from xampp to load and view my php files for an application.
I would really appreciate it if anyone could help me start setting up XAMPP to send emails when i use the php.
Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!
is this link any good? http://www.websnippetz.com/2013/01/send-email-from-xampp-localhost.html
Many are using SendMail package with XAMPP but i can't find a download for that.
anyone tried anything which worked for them?
please help a very confused developer guys!
Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!
PHPMailer is not a server it is a library. People often recommend using a Mail library because the built mail functions are very low level and hard to work with. Because they are modeled after using sendmail from the commandline.
If you want to send via SMTP, use attachments, or other things it can be difficult or impossible to do with mail() directly.
Personally I recommend using SwiftMail over PHP mailer. IMO, it's more modern, easier to use, and has a better API, and depending on which PHP F/OSS projects you are used to using or contributing to its more common and the standard.
Overall there are 2 parts to sending mail from PHP:
Setup of the actual mail server on a system (local or otherwise)
The configuration of PHP to use that mail server.
To setup the mail function you need to install and configure a mail server locally in order to fulfill item (1). This should already be included and set up on OSX. So to fulfill item (2) you need to configure PHP via the INI to use that mail server by changing the sendmail_path.
Now if you want to use a library, which I recommend you need to get that source into your project and then use it appropriately. For the example we will use SwiftMailer, with SMTP transport via a gmail account:
require_once 'PATH/TO/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
->setUsername('user#gmail.com')
->setPassword('secret');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('My SMTP Message')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receipient#domain.com', 'other#domain.com' => 'A name'))
->setBody('Plain Text Message Body');
$mailer->send($message);
To send emails from your localhost your need an Email-Server like postfix or Exim or you send your E-Mails over SMTP what is described on that site from your link.
The easiest way is to use an abstraction layer like Swift Mailer
http://swiftmailer.org/docs/sending.html
Here you have a lot of possibilities to send E-Mails. Another solution is to install a local Mailserver and fetch all sending E-Mails. In MAMP Pro for example you have an integrated Mailserver.
http://blog-en.mamp.info/2009/09/how-to-sending-emails-with-mamp-pro.html
I am writing a website which will automatically generate emails to users on special occasions (e.g. the activation email after user registration). The problem is, SMTP authentication is required, but the website will be hosted on a web hosting service, which does not have Pear Mail installed. I have read many articles on the Internet, saying that either Pear Mail, PHPMailer or SwiftMailer is required for SMTP authentication. As I do not have the authority to install any of them, what can I do in the PHP scripting level if none of the above exists?
A side question is, if Pear Mail, PHPMailer or SwiftMailer is a PHP library, does it mean we can actually perform SMTP authentication by writing our own PHP code?
Added: This link (http://www.webdeveloper.com/forum/showthread.php?233847-A-Way-to-Send-SMTP-Mail-w-o-PEAR) seems to have provided a solution, but when I tried, nothing happened (no email was sent). Does it really work?
Classes like PEAR Mail, SwiftMailer of PHPMailer are all just PHP scripts, no different to your own scripts, so if you can run PHP at all, you can install and run any of these libraries without any special privileges. You don't even need shell access on your host - run the pear installer, or download the package on your dev machine, uncompress it, then upload the PHP files along with your own scripts. You only need to make sure your include paths are working for whatever location you choose to put them.
The installation mechanism described in the documentation is preferable as you can be sure it's putting everything in the right place, handling dependencies, versions etc, but so long as scripts are readable and accessible to PHP it doesn't matter how they get onto the server.
If you're lucky, you may be able to run the pear installer in your shell account, where it would hopefully install pear packages somewhere accessible to you.
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.