PDA

View Full Version : Sending emails with PHP


Izinyoka
31st March 2009, 18:58
When sending emails with PHP, (from looking at the logs) the from address is translated to 'webID'@servername.serverdomain.
But when the email is delivered, the from address looks correct (mailbox@domain).

So here is the example from my log:
amavis[2564]: (02564-02) Passed CLEAN, <web3@websrv1.serverdomain> -> <sales@recipientdomain>, Message-ID: <20090331122742.9E66FF7C24F@websrv1.serverdomain>

So the server domain is not the same as the website sending the email.
I can't even see a reference of the actual domain.

some mail servers will not accept emails like this.

said: 550-Verification failed for <web3@websrv1.serverdomain> 550-The mail server could not deliver mail to web3@websrv1.serverdomain

But if it did a verification on the actual sender domain, it would be fine.

When using Outlook, it does not do this. The address is correct, even when looking at the log.

I had the same thing with ISPconfig2, just cant figure out what it is.
Any help would be much appreciated.

Izinyoka
31st March 2009, 19:16
when looking at the Message source (on an email client once the message has been delivered), its only the 'return-path' that has the translated address, the actual 'from' is the correct email address.
And the message ID is 20090331033304.B98012180AC@websrv1.serverdomain

Izinyoka
31st March 2009, 19:29
yeah, it seems that the 'return-path' is taken from who delivers the email to postfix which is the user that apache ran the script as.
Seems like there is much discussion about this but no real way to override it.

edge
31st March 2009, 20:00
Sure there is.
Make sure you set a from email address in the header!


$Name = "Me"; //senders name
$email = "me@me.tld"; //senders e-mail adress
$recipient = "to@to.tld; //recipient
$mail_body = "Hello."; //mail body
$subject = "The subject of message"; //subject
$header = "From: ". $Name . " <" . $email . ">"; //optional headerfields
mail($recipient, $subject, $mail_body, $header);

Izinyoka
31st March 2009, 21:35
Sure there is.
Make sure you set a from email address in the header!


$Name = "Me"; //senders name
$email = "me@me.tld"; //senders e-mail adress
$recipient = "to@to.tld; //recipient
$mail_body = "Hello."; //mail body
$subject = "The subject of message"; //subject
$header = "From: ". $Name . " <" . $email . ">"; //optional headerfields
mail($recipient, $subject, $mail_body, $header);

There is a from address in the header and it is the correct one, but the return-path is the user apache is running as @ the server domain, not the actual hosted website's domain.
And when the recipient mail server validates the email, it validates the return-path, not the from address.

I understand this is how a normal Unix mail system would work. A user sends a mail, it uses the username @ domain, there is no seperate email field.

I have been working on this issue on and off for almost 2 years... I doubt its going to be as simple as that.

make-fun
1st April 2009, 03:48
You may wanna try the so called "fifth parameter" or "5th parameter" of the mail functionů
$myParam = "-f ".$email;
mail($mailto, $subject, $message, $headers, $myParam))


Cheers

Izinyoka
7th April 2009, 16:20
Na man, its not the script.
It happens with Joomla, Indexu, Gallery2 etc.
Im not gona go and edit the sendmail files on each application.

The problem is with ISPConfig, not the PHP scripts...

till
8th April 2009, 12:19
The problem is in your script or setup and not ispconfig as ispconfig does not interfere in the mail sending process at all. The mail is handled by postfix and not ispconfig.

Izinyoka
9th April 2009, 16:52
Yeah maybe not ISPConfig itself, but it NOT the script!!
these are prebuilt scripts like Joomla, not something I made.

E.G
My hosted domain is test.com, my server is on lab.com
The PHP script on the hosted domain sends an email using the PHP sendmail command, the user sending the email is web31@lab.com so it is understandable that this will be the return path.

The from address is correct, info@test.com, but when a mail server validates the sender, it validates the return path.
So 95% of emails being sent from this server work fine, but the ones that validate the return path will not accept.

This may be an unavoidable issue with hosting multiple domains, but maybe there is something that can be done? but if you don't know, don't tell me my script is wrong because it's not! you will just confuse people reading this.