How to enable mail() function - php

I am trying to work with a shared host in which the mail() function was disabled (I can see that on disabled functions on phpinfo()) by someone that I don't know.
All I have access is the root folder for the site files in the ftp, so I can't edited the php.ini in /etc/ neither restart Apache (I know is a linux based OS).
Is there any way I can enable it by a secondary php.ini or ini_set()?
EDIT: I am aware of PHPMailer. I was trying to use it but it was being block as well. That's why I started trying to use mail(). Just to see if it would work

You need to get a new host or upgrade to some different plan.
However you can go ahead with mailgun(https://www.mailgun.com/) which is very cheap and no cost to set up.
You just need to link your credit card for a safety but they never charge you unless you pass 10,000 emails per month(https://www.mailgun.com/pricing).
There are other solutions as well like mandrill or sendgrid. However, Mailgun is almost free unless you are using more transactions emails.
You can find the official mailgun php package in here : https://github.com/mailgun/mailgun-php
You need to check if curl is installed in your server though.
Secondly, trying to send emails directly is not a good practice. Most of the times they will end up getting in spam folder. Use SMTP and use PHPMailer Extention.
Steps to do so :
1. So to cpanel and go to emails
2. Create a new email account and add a password
3. Click on configure mail client related to the new email address you have created
4. You will get 2 tabs, SSL configurations and NON SSL configurations
5. You can choose TLS, copy the outgoing host, email and password.
6. Now install phpmailer and enter the above credentials and try sending email.
7. Also as a safety, go to authentication in your cpanel and check if any issues are mentioned for emails just for safety.

Related

check and view reply for sent email - PHP - Codeigniter

I am using php and Codeigniter, I need to implement the following schema
for list of emails I need to send emails for them, and if they reply to this email, I need to know if the reply and what the content of this reply and view it using my php project.
Also I need to send them a multiple choice question and they have to chose one option as answer, and then check this answer from my php project.
I can send email from my gmail, but can't send it from the wamp server itself.
Any help?
I'm not exactly familiar with CodeIgniter, but if you want to send an email, and it doesn't work, especially on Windows the common problem is that there is no SMTP server configured.
Most *nix distros have some form or another of a SMTP server running by default, Windows doesn't. When unconfigured PHP assumes localhost to be an SMTP server.
This SMTP server is what PHP needs to be able to send emails, so you'll either have to configure one or find one you can use that's provided by someone else.
For using PHP's native mail() function and any library that relies on it the configuration entries you're looking for are SMTP and smtp_port. (Have a look at: http://php.net/manual/en/function.mail.php)
It might very well be that your ISP provides a SMTP server. Otherwise you can always set up a gmail/hotmail/whatever account and use their SMTP settings. This is usually far easier than setting up your own server.
If you choose to set one up yourself, you'll want to look into SPF, so your messages don't get marked as spam by default.

Configuration issue when sending email on Mountain Lion using Postfix

I've been stuck on this problem for the whole afternoon and tonight but cannot find an answer. But I believe it's some easy configuration issue on Mountain Lion.
I want to send out email using PHP, and I installed PEAR:Mail package; that all works fine.
But when I try to send email in PHP, it returns me no error; but email not received.
I further dig into the problem, found that I need to properly set up my local postfix mail program. I therefore following these articles to setup:
http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/#comment-259; when that didn't work, I followed that one instead: http://slashusr.wordpress.com/2012/02/14/enabling-postfix-for-outbound-relay-via-gmail-on-os-x-lion-11/.
The basic steps in the blog post is to teach you how to send out using GMail by doing some settings in /etc/postfix/main.cf
But when I test it in terminal with command:
date | mail -s test <my_email_address>
Nothing happened, except that when I type "mail" again, it prompted me with a new message, telling me this error (part, only what I think to be useful):
: host smtp.gmail.com[209.85.225.108] said: 530-5.5.1
Authentication Required. Learn more at 530 5.5.1
http://support.google.com/mail/bin/answer.py?answer=14257
aa4sm11414435igc.15 (in reply to MAIL FROM command)
--1306515822A0.1347279593/songyy.local
Content-Description: Delivery report
Content-Type: message/delivery-status
I visited the link given in the error message, but it's irrelevant.
I'll very much appreciate if anyone can give me some advice on this.
I want to send out email using PHP, and I installed PEAR:Mail package; that all works fine.
Very well. Then you must have a "mail relay server" address, to whom mails get sent. It is usually supplied by your Internet provider.
You must configure that address into Postfix, as relayhost. No other setting is usually necessary.
The recipe you followed is much more complicated because it entails Postfix connecting to GMail and authenticating as a user, all through TLS/SSL. To do this you must store the username and password to your GMail account (or another account created for that purpose) in the postfix passwd file.
The fact that GMail complains of "Authentication Required" tells us that either you skipped this detail, or you stored the wrong password; so GMail can't go through the email forwarding process.
Note that if you only use plain SMTP, the outbound emails will be sent in the clear (as opposed to GMail use of SSL encryption).
Check out the system logs if you need to see in detail what happened to your mails.
Another thing to watch out, you say:
I specified the file by setting: smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
This file expects to be in a specific format (documented in the file itself). After that, though, you have to convert the file into the hashfile, which is the same filename but .db extension. Some distributions do this automatically, otherwise you need to manually run the postfix utility postmap (or in a pinch, makemap). In your case:
postmap -c /etc/postfix /etc/postfix/sasl_passwd
This will take /etc/postfix/sasl_passwd and hash it into /etc/postfix/sasl_passwd.db, which is the actual file Postfix checks. It is possible that this particular detail was not covered in the tutorial you followed, and Postfix is still checking a .db file which was built from the previous (and empty!) sasl_passwd.
You are quite right that by specifying user, host and pass in PEAR, you are effectively overriding Postfix configuration - I think the Mail package performs so-called direct-to-MX exchange, and thus does not even need Postfix at all.
The log files should be specified in main.conf and are usually /var/log/messages or /var/log/mail(.something).

Virtual Hosts / Postfix mail log, show sending website

I've been googling around for awhile now and have been unable to find any sort of solution or any information at all.
What I need to do is to configure postfix so that when one of our websites sends mail using PHP (via a contact us form or w/e) the mail log will show what the sending website was. This way we can identify a compromised website/form, etc in case one of our IP addresses should get blacklisted. We run virtual hosts so each server could have dozens to hundreds of websites on them. For us to otherwise track them down manually could take forever.
Is this even possible? Perhaps its not if I couldn't find anything on google :(
Consider using PHP 5.3's new mail.log configuration directive. It will allow you to define a log file where all calls to the mail() function are recorded, including the To address, the headers, and the full path to the script that made the call.
If you aren't running 5.3, consider upgrading to it, or to 5.4 once it's out in a few weeks.
Unfortunately this is only half of a solution. There are numerous PHP mail libraries that speak SMTP. If you permit local SMTP connections (as most good web hosting providers should), then users would have a way to bypass that log.

How to send myself an email with php, Windows 7, WAMP server? need SIMPLE solution

I have spent the last 15 hours trying to figure out a simple, free way to send a simple text email via a php script when a form is filled out on a html page. I don't care how it looks, as these emails are only going to be sent to me (at most 15 a day). I don't need anything except a simple email to me when the form is filled out. I understand everything except I cannot get past:
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini
What i have tried:
Playing around with the pear mail extension and using smtp.gmail.com
Downloading countless smtp mail server applications.
Using my ISP smtp and port 25: smtp-server.wi.rr.com.
Using PHPMailer.
Using the windows SMTP server.
Although all of these things should work... I am apparently too dumb to figure it out. I have read every sentence on the subject on the internet and have tried to follow instructions, but each time I try something else, I just run into more problems. Someone PLEASE give me a simple fix to this, so I can never look at PHP mail stuff again.
If you're sure all these settings are correct, you should check your firewall. If all else fails, try sending a mail from a mail client (or make an attempt using Telnet!). If this succeeds, than you're doing something wrong in the PHP configuration, or the way you send the e-mail. If sending fails with other clients too, than the problem lies in the ability to send e-mails from that computer at all.
Your own ISP should work fine. Remember that most ISP's don't require you to enter a password. Only the smtp server will suffice in that case.
Folks.
After many hours of trying I found that:
You don't need additional tools like mailservers or pear additions. These only provide additional potential security leaks that you have no control or insight over.
To get mail function to work on localhost, all you need to do is change the php.ini file.
I just checked my outlook account settings and copied those to the php.ini file.
So SMTP server, port, username and password.
Now,
You may think it does not work but
You should know that many mail clients reject emails if the From field has a different domain than the actual domain an email is received from.
So if the php.ini file contains for example
smtp.ziggo.nl
Be sure that the header contains:
From: info#ziggo.nl
So for making universal code on both localhost and remote host, I check for the existence of a file that I only have locally (e.g. z_local) and set the headers accordingly. If the local file does not exist I must be on the remote ISP and choose the header "From: info#remotesite.com"

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