Change HELO host name when sending email - php

A customer's website address is customerswebpage.com (not the real one, of course). The server itself has it's host name configured to server.customerswebpage.com, which has no A or MX type DNS records. This causes many web servers to refuse mail from this server.
Is there an easy and/or neat way to change the HELO address the server identifies itself as? The site is built on the Symfony framework version 1.0 and we're using the sfMail plugin to send the mail. The only solution I could think of so far is taking a copy of the whole plugin and modifying it to suit our needs, as the hostname is used only internally.
Maybe even more importantly, do you think we could say this is a DNS misconfiguration?

I think HELO needs to be changed in server's MTA and not in php.
http://www.sendmail.org/m4/whoami.html
You should probably just add the missing A and MX DNS records for server.customerswebpage.com and not change HELO.

Mail servers can be really picky, and it is by no means granted that adding a proper A and PTR record for the server will resolve all issues. It is usually most hassle-free to use an external smarthost (for example via your ISP or a dedicated service) for outgoing mail, and let them worry about deliveries.
The sfMail package is based on PHPMailer, and that package stores the HELO host name in $helo. Perhaps you can overload the sfMail phpMailer class and set that variable?

A way for avoiding this problem is to use sfMail with SMTP. So you can send your E-Mail with your real Mailserver so the SPF and MX Records are right.

Related

Sending mail from webserver to external mail server with local domain name

This is an issue I've encountered several time and haven't yet found a decent solution for:
Sending an e-mail from a webserver on e.g. "domain.com", to info#domain.com which is hosted on an external mail server e.g. Google Mail
In my case I always send from PHP over Apache and often on shared hosting, but I can imagine this is the same case on other frameworks.
These e-mails always seem to be delivered to the local mail server, even if I set the MX records on that server to point to the right external mail server.
A solution for this is to use an external SMTP server, but this isn't always easy when you're working with clients that either need to set-up a new e-mail account on their server and provide the SMTP details or sign-up for a third-party SMTP server.
What is the solution for this? Is there no way around SMTP?
Most emai/MTA server "autoconfigure" themselves. They guess list of local email domains (doimans with locally hosted mailboxes).
In sendmail case you can turn it off adding the following line in sendmail.mc:
define(`confDONT_PROBE_INTERFACES', `True')
Documentation : cf/README - confDONT_PROBE_INTERFACES
I have had the same issue many many times (in my case using PHP on a LAMP stack).
Try/check the following.
If you are using cPanel or similar, set the MX records to the external mailserver (Google apps etc).
Set up an SPF record to allow your hosting website to send email (this way no need to configure SMTP).
This may not be applicable but if you are using something like phpmailer. Set the property $mail->isMail(); so it tries to use your SPF allowed local mail() function to send the email. Sorry for going off into very specific advice, but might help in your particular situation.
Worth checking there are not similarly named local mailboxes on your hosting box.
Hope this helps!

PHP mail() not working

I'm building a site on my home computer using MAMP. The code I'm using employs the PHP mail() function to send emails, but whenever I test it, the mails aren't getting sent.
My computer is connected to the net, but I'm wondering if there's something about local hosting that prevents mails from getting sent. I'm not getting any kind of error message.
Any ideas?
PHP can send mail in one of two ways.
The first, and the default on non-Windows systems, is to use the local mail transfer agent installed on the system. This would be "sendmail" or an application compatible with it, the most popular probably being postfix.
The other is to connect via SMTP to some mail server.
You will either need to install a mail transfer agent on your local system (and set it up correctly), or edit PHP's configuration to specify an SMTP server address and port.
Yes, there are things that could block locally hosted mail. For one, your ISP could block SMTP to servers other than the ISP. ask your ISP support if they block SMTP... Or try telexing so someone's MX port 25 and do you get a response?
If your ISP blocks smtp you can still send the mail, but first you must relay that email through a hosted email server like your ISP mail server. This process is called 'smart hosting' and you can search for more info.
Even if you are not blocked on port 25, many sites will refuse or lose smtp traffic that originates from a dynamic or residential IP address, so again the smart host suggestion.
Also I suggest not using the built in mail() function in PHP... Use something that replaces and improves it like http://pear.php.net/package/Mail or http://sourceforge.net/projects/phpmailer/. Again, use the SMTP method as it is way more reliable than direct sending or calling Sendmail.
It is important to confirm this problem, doing SMTP manually over telnet. That way you isolate the problem from PHP. I did ISP support for years and saw this question lots. Most people setup php and mail correctly but get stuck on a background network issue with SMTP.
If you have Wireshark installed, it can record network traffic and you might see the actual SMTP traffic, for example the remote server may be refusing your connection. Wireshark is helpful but not required to solve this though. Good luck.
You need to setup SMTP server in order to be able use mail function, or you can use PHPMailer class, with it you can avoid using mail function and setup problems, PHPMailler need socket extension to be loaded in order to function correctly.

How to send email from a specific ip address?

I'm running a vps with cPanel/CentOS, And i want to dynamically choose the IP address to send an email from right inside the php code. ( i'm open to any weired ways )
Is there any way to do that? i would really appreciate some clear ideas as i'm not that good at exim and stuffs.
P.S. i already have available IPs in WHM.
Thank you
You can achieve this by using sendmail and passing parameters to define the configuration file to use. Inside the configuration file you can use the Masquerading And Relaying options together with CLIENT_OPTIONS(`Addr=aaa.bbb.ccc.ddd') to send via a certain IP.
When using PHP mail use the additional_parameters to specify the sendmail config file to use and in that config file use the above options to configure it.
PHP has no control whatsoever over the SMTP server that sends the mail. You can bind SMTP servers (sendmail, postfix, exim, etc...) to specific interfaces, but that's got nothing to do with PHP. PHP's involvement with the email sending process is purely to generate the mail and then hand it over to an SMTP server for actual delivery.
Here is a thought. If what you need is to send the mail from a specific IP you have control over, but where the impetus for that mail doesn't originate from that IP, but from some web interface or whatever, you could:
Add the mail details to a table on a DB with the desired IP address as a field.
Setup crons to run a php script on each box with those IPs.
Parse over the table with that script to find any mail that needs to come from that IP.
Send the mail.
I have a reseller account on a virtual host and all my domains for example are under the same IP number, then whatever domain I'm using to send an email, it will be sent under the same IP number, I think it is controlled by the smtp especification, you can configure your smtp to send email with another server where of course you have an account.
Also create a table to control what server you want to use to delivery yours email.
ClientPortOptions and DaemonPortOptions are special cases since multiple
clients/daemons can be defined. This can be done via
CLIENT_OPTIONS(`field1=value1,field2=value2,...')
DAEMON_OPTIONS(`field1=value1,field2=value2,...')
Note that multiple CLIENT_OPTIONS() commands (and therefore multiple
ClientPortOptions settings) are allowed in order to give settings for each
protocol family (e.g., one for Family=inet and one for Family=inet6). A
restriction placed on one family only affects outgoing connections on that
particular family.
Source: http://www.sendmail.com/sm/open_source/docs/configuration_readme/

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.

Is there a SMTP mail transfer library in PHP

I want to write an email transfer service and need a MTU replacement of sendmail/postfix.
I'm not looking how to deliver to a transmitting SMTP server (like a postfix listing on a SMTP port). I also don't need the receiving part of the server, bounces etc. would go to a different existing postfix.
All of it in pure PHP. SMTP is a pretty easy protocol but this would require access to the MX DNS record and other lot of details that need to be taken care of.
Why do i need this? Because most shared internet providers have insane low limits for sending out emails like 500 per day. Thats almost nothing if you want to setup even the lowest traffic email list.
EDIT: Please Note: The code needs to connect to the receivers SMTP server and deliver the message with an adapted header set (removed BCC list, added Path route). If you see a SMTP class less then 5000 lines or requires you to configure a SMTP hostip and port then this is not the stuff i'm looking for.
It needs to do all the stuff sendmail is doing just as a PHP library.
I use Pear's Mail class.
EDIT
After re-reading this, I see there's more to it than just a library. You are asking to send direct to the remote MX.
Why reinvent the wheel? Set up an instance of postfix on the server, which only listens to connections from the web server... and let an MTA do what it does best. Hand off the messages from php to a real mail server and move on.
In the case of ISP's that block outbound port 25 and force the use of a smarthost, this also allows you to restrict the rate of messages sent to the smarthost.
Lastly, sending straight to the end MX from your php script is a bad idea, because if you send to me, I'll never get it. I and many other sites use "greylisting" to reduce spam, which denies all initial requests with a 450 temporary error. Real MTA's will try again, but unless you implemented a delay queue and try again, your message will never go through.
We use http://sourceforge.net/projects/phpmailer/ to do SMTP email from PHP
SwiftMailer is the only library you'll need.
Try Zend Framework component Zend_Mail (you can use the component independently of the entire framework).
Here is something I wrote. It's quite minimal and I don't know how well it performs, but I wrote it with the intention of replacing sendmail, meaning that it will take a message, lookup all the MX records for the recipient domains, contact those mail servers and deliver a message for the corresponding recipients. It worked well enough for me at the time.
https://github.com/denvertimothy/ThriveSMTP
It's been a long time since I've used it, but I threw it up on Github just now.
I used http://www.mailerq.com/ which works cool. Its a queue based mail transfer agent. It requires rabbitmq.
It provides multiple worker as well.easy to store in database.
It provided management console as well.
worth to check it

Categories