Change sender email on VPS with Debian

252 views Asked by At

I am sending a contact form response through PHP, respectively PHPmailer. It is sent from VPS with Debian & ISPConfig & Apache installed. The email is sent fine, Gmail recives it with no problem. However when I open the "original mail code" there is a wrong sender email:

Return-Path: <[email protected]>

resulting in SPF notice:

google.com: [email protected] does not designate permitted sender hosts

This of course causes some other web-mail providers not to recive this email.

I've looked through php.ini and some other configs but I could not find where would I set this.

Is it possible to change this through the PHPmailer (best option)? (or at least in some PHP-way?)

Or do I have to set it somewhere on the server-option side - if so - where?

EDIT: I've managed to change the address itself through $mail->Sender = [email protected]; but it still does not designate

EDIT2 - partial solution:

The previous EDIT solves the problem with email providers not recieving the emails - now it comes with no problem, however I would still like to solve where to set the SPF properly so I would solve the designation problem.

3

There are 3 answers

2
steffen On

The web1@server1 looks like something from ISP Config for the default user.

Try:

$headers.="Return-Path:[email protected]\r\n";

in your php ... the need to be greater and lesser signs around themail adress ... but I can not get them to display here.

Nicer would be checking the ISP Config Manual ... I am definately sure you are not the first to use that panel and have that problem. Changing or adding to the php.ini is not advised as this would change it for ALL users.

3
olegsv On

You have to add SPF record to DNS zone of server1.example.com domain .

Something like "v=spf1 a mx a:server1.example.com ~all"

There is a good wizard from Microsoft that helps to construct SPF record.

I'm afraid PHP can't help you here.

1
Synchro On

"... does not designate permitted sender hosts"

Note that this is not an error. It's just a statment of fact, and will have little bearing on your deliverability. Presence of an SPF record can improve your deliverability, but absence will not make it worse.

You can't change your SPF from PHPMailer. It has to go in your DNS server.

To check what's in your DNS, install the dnsutils package which should include the dig utility. You can then look up DNS records like this:

dig txt google.com

; <<>> DiG 9.9.5-3-Ubuntu <<>> txt google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58518
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 5

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.com.                    IN      TXT

;; ANSWER SECTION:
google.com.             3427    IN      TXT     "v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all"

;; AUTHORITY SECTION:
google.com.             154413  IN      NS      ns2.google.com.
google.com.             154413  IN      NS      ns4.google.com.
google.com.             154413  IN      NS      ns3.google.com.
google.com.             154413  IN      NS      ns1.google.com.

;; ADDITIONAL SECTION:
ns1.google.com.         154332  IN      A       216.239.32.10
ns2.google.com.         154332  IN      A       216.239.34.10
ns3.google.com.         154332  IN      A       216.239.36.10
ns4.google.com.         154332  IN      A       216.239.38.10

;; Query time: 19 msec
;; SERVER: 217.70.184.225#53(217.70.184.225)
;; WHEN: Thu Nov 20 14:52:33 CET 2014
;; MSG SIZE  rcvd: 263

There you can see looking up TXT records for google.com, and that gives your their SPF (which is actually slightly sub-optimal as the ip4 clauses should come before the include).