Server/Laravel 5.1 - Mail storage? - php

So I developed an application with laravel and everything is running fine. I had mail as my mail driver but my server was misconfigured, or let's say, postfix was not installed. So the mail a user sent via contact form in my laravel app never got sent. Laravel never complained so I didn't even see any errors in the logs.
My question is: Did laravel or my server save the mail it tried to send anywhere so I could see what the user tried to send me?

Unless you've somehow manually added mail logging, this won't be logged for you to send later.
Laravel's Mail functionality does include a Log driver, so that mail writes to a log- but this does not work in tandem with the other drivers, so you likely have zero logs currently.
http://laravel.com/docs/5.1/mail#mail-and-local-development
There are also several results in google on how to implement global logging for all mail sent, maybe check out this or look into laravel events.

Related

Forcing PHP mail to mock success on dev server

I'm developing a Lumen API (on a VirtualBox) which will occasionally send out emails. However, on my dev server, I don't want to send mails; rather, I'd like the server to fake sending the mail and just return true. In the past, I've done conditionals that check if I'm on the dev server, if so, skip the entire sending mail process, but this feels like the wrong way to do it.
So what I'm trying to get to is: can I somehow get the server to not try sending the email and just move on? Am I thinking about this wrong, and should I try to get mail working on my VB or is a conditional the right way to go after all? I'd love advice on this.
If you are sending emails using illumenate/mail (Lumen 5.3 send email) you can set up the mail driver to log in your .env file for your dev environment. https://laravel.com/docs/5.2/mail.
If you are using your own functions for sending emails you should still get smtp server from .env, so you can set it to a server that will not send out any emails

Laravel Mail SSL Error

while working on my current project, I already started to experience problems after trying to implement the Password Reset function based on the scaffolding that Laravel provides.
Currently, I am only using the default routes and controllers for the password reset procedure.
When it came to testing that functionality, I got the following error:
stream_socket_enable_crypto(): SSL operation failed with code 1
I checked my mail server and I saw that I hadn't yet implemented the new Certificate from Let's Encrypt but was still using a self-signed one. After fixing that issue and also taking care of the intermediate certificate for the Lets Encrypt CA, I checked my server with this tool: https://ssl-tools.net/mailservers/mail.dream-code.eu
This clearly states, that my server is not having any SSL issues anymore, but still, I receive the same message from Laravel when I try to use the Mail function. Is there any known issue about this or do I have to take further steps?
I found something about Laravel 4.2 where you had to change the mail provider from smtpto mail which had fixed the issue for some people but this was also not successful. When I used that mail provider, there was no error but I also did not receive an E-Mail. Neither in the default folder, nor in the spam folder.
When I "manually" send mails via Thunderbird from the same address that is set for Laravel, there is no problem, the E-Mail arrives just a few seconds after sending.
Just in case it's somehow relevant, I try to send to a gmail address. The mail server is a Dovecot/Postfix Combo with the already mentioned Let's Encrypt certificate. PTR Record is configured correctly.

What is required on web server to send email using PHP/HTML form using Nginx?

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.

Email sending issue

The project that I'm currently working on, is large scale. I'm using email activation method for user registration system: Sending activation code via my shared hostings smtp server to users email address after successful signup.
During tests, I have noticed that, it sends emails to famous mail services like gmail, live without any problem and receiver gets message directly but when I tried to send email to well known email server (rambler.ru), the swiftmailer script (that I'm using to send emails) returned success message. BUT another side didn't received any message. That's big problem for me.
At first I thought maybe that's scripts problem. Tried phpmailer too. No success. Then tried to send from Outlook to that server for testing purposes. The user on rambler.ru received message with very big delay. I'm using shared hosting on Hostgator. There might be users that using rambler.ru server, and I dunno if that's one and only server that occurs such problem.
How to deal with that problem? I know that, I can send from live or gmail servers with "fake" from name. But another problem, is there will be probably daily limit or something like that. Any suggestions?
Check your SMTP server's logs to see what happened to the email. Getting TRUE from mail() or swiftmailer just means that they've successfully handed the email off to your smtp server. It does NOT mean that the email was delivered to the receiving host. That comes later, AFTER your php script has exited.

A couple problems re: CodeIgniter emailer

I have some problems with the email system for CodeIgniter:
First, the emails I send out (registration, confirmations) are getting caught in standard spam filters in gmail and other mail clients. How do I get around this? How do companies like Facebook get their emails through consistently?
Second, the mailer is working locally but once we deploy it it no longer runs (doesn't send emails) but all the other forms run just fine. Anyone ever run into a problem like this?
Thanks for all the help!
I can't really answer your first question - it's not specific to CodeIgniter. You just need to make sure your email doesn't look like spam. In short - there's no way of guaranteeing your e-mail will not end up in a spam filter.
As for the second question, I expect your production server needs to be configured properly for email. You probably need to configure CodeIgniter to send email properly. I would suggest setting up an SMTP server (or using an existing one) rather than using the standard PHP mail which I think CodeIgniter uses by default.
Regarding spam, most organisations are very secretive about how they prevent spam (not wanting to publish information which helps the spammers) and in some cases they don't actually know - an obvious examlpe of this is bayesian filtering - but, for example, hotmail use a completely unaccountable army of volunteers to manually classify emails.
Do and get a copy of spamassassin and try to reverse engineer how the standard rules work. Obvious things to check are:
1) AVOIDING LOTS OF CAPITALS
2) don't mention the 'V' word
3) make sure you've got a current and restrictive SPF 1.0 policy published
4) make sure your sending from an address which has A and PTR DNS records
5) Do provide a reply-to and from email address which use your domain in the address
the mailer is working locally but once we deploy it it no longer runs
doesn't send emails
Which? These are 2 totally seperate things. If the code is falling over (if so why have you not provided the error details) then its likely a PHP version issue or a problem with the connection to the MTA (or the PHP mail config).
The latter is a problem with the MTA itself.
99.9% of problems reported as PHP mail failures have nothing to do with PHP and are problems with the MTA.
Enabled detailled error reporting for your MTA and see where it is failing.
C.
You may have to configure the email on your server differently than your local development environment. I've had to in the past.
There are two basic ways that PHP can send mail:
Via a UNIX program called "sendmail" (only on non-Windows servers and only if it is installed - check with your hosting provider)
Via a SMTP server.
If you've configured CodeIgniter to use SENDMAIL, check to ensure that the Sendmail path is correct. Your hosting provider usually provides this somewhere in their online documentation.
If you're using SMTP, you need to make sure that your server can contact the SMTP server. You can do this by logging into the server via SSH and typing "telnet your.smtpserver.com 25". If you get an error message about not being able to connect, you know you have a problem with your hosting provider connecting to your mail server.
I've been able to diagnose this problem by enabling logging on my production server (http://bit.ly/4pprd6) and adding log_message('error', $this->email->print_debugger()) right after I attempt to send a message.

Categories