Smtp email - from and bounce

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Smtp email - from and bounce

Post by webstyler »

Hi

we send email with own smtp class

on this class use this

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

to set FROM

We must setting a different email from email bounce, so the Return-Path bust be this new email

How to this ?

Thanks
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Smtp email - from and bounce

Post by Eric! »

Send a test email to yourself and look at the headers to find your problem. Some maiil servers are configured to deliver bounced messages to a specific address. Sometimes you can override it with -f like in this example:

Code: Select all

$from='me@email.com';
$returnpath="-f ".$from;  // Forces the return path to be configured properly
$mail_sent = mail($to, $subject, $content, $headers, $returnpath);
Make sure you have the errors and warnings on to see if it fails to reconfigure.
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: Smtp email - from and bounce

Post by webstyler »

Hello

we send directly to smtp .. not use mail() function

so need to set return-path as FROM

fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

BUT not work if we send return-path with this method :(
bhavani
Forum Newbie
Posts: 1
Joined: Mon Nov 09, 2009 2:13 am

Re: Smtp email - from and bounce

Post by bhavani »

webstyler wrote:Hi

we send email with own smtp class

on this class use this

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

to set FROM

We must setting a different email from email bounce, so the Return-Path bust be this new email

How to this ?

Thanks
thanks
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: Smtp email - from and bounce

Post by webstyler »

bhavani wrote:
webstyler wrote:Hi

we send email with own smtp class

on this class use this

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

to set FROM

We must setting a different email from email bounce, so the Return-Path bust be this new email

How to this ?

Thanks
thanks
??
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Smtp email - from and bounce

Post by Eric! »

webstyler wrote:we send directly to smtp .. not use mail() function
What are you doing? You still need an smtp server. Who configured the server? Get them to fix it.
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: Smtp email - from and bounce

Post by webstyler »

Eric! wrote:
webstyler wrote:we send directly to smtp .. not use mail() function
What are you doing? You still need an smtp server. Who configured the server? Get them to fix it.
we send email not with mail() function but with connection to smtp because need to manage a lot of smtp server, not only local

so we have a class that use fsockopen and other comand to talk with smtp

all work fine

We need only to specify a return-path different from "FROM" value, and don't know how make this

Thanks
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Smtp email - from and bounce

Post by Apollo »

Return-path is simply specified by the email's header, not a specific SMTP setting or something that requires a separate SMTP command.

Just make sure to include a line like

Code: Select all

Return-path: your@momma
in the header of your email content (the stuff you send after the DATA command), and you're good.

By the way, you sure you want to implement this yourself? There are tons of open source solutions for this which really work fine. Personally I can recommend PHPMailer (have good experience with it myself).
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: Smtp email - from and bounce

Post by webstyler »

Hello

We have try to add Return-path on the header send after DATA but this is replace with value "$from"

:(

we send this header after DATA
From: $namefrom <$from>\nReply-To: reply@domain.comt\nReturn-path: <$bounce>\nSubject: $subject\nTo: $to\n$headers\n\n$message\n.\n"

but when email arrived return-path is = $from

:/

We work on this own library for our customer that need function and procedure, we cannot use external class or framework :)
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Smtp email - from and bounce

Post by Apollo »

Strange, perhaps the SMTP server you're using does not allow custom Return-path addresses?

Have you tried connecting to a different SMTP server (from ISP, hosting provider, etc)? If that works, contact whoever is maintaining your current SMTP server, and tell them to fix this :)
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: Smtp email - from and bounce

Post by webstyler »

uhm.. -f with mail() function return correct value

so think must go also with smtp send way .. :/

must know how to send "-fbounce@domain.com" on smtp connection
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Smtp email - from and bounce

Post by Eric! »

webstyler wrote:must know how to send "-fbounce@domain.com" on smtp connection
You already did it by formatting the header sent to your server. Assuming your code is correctly defining $bounce and your header is properly formatted and your statement about sending the header AFTER the 'data' is just a language error or your talking about smpt commands(header is first followed by message body), then I would say your smtp server is causing the problem and your mail() function is using a config file that sets the server up correctly.

Traditionally you need CRLF at the end of each line. http://www.faqs.org/rfcs/rfc822.html

Depends on what mailserver you are using....
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: Smtp email - from and bounce

Post by webstyler »

we test with mail() function and setting Return-path as header and not work, as most other server

work only if force with -f on extra header on mail()

so, think is the same on smtp command.. not work setting as header .. must be force or setting with specify rules

as tell before setting as header is ignored and email header have as return-path the same value sent on FROM smtp
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Smtp email - from and bounce

Post by Apollo »

As Eric suggests, try using CRLF (that's "\r\n") line endings instead of just \r in your $header string.

If that doesn't make a difference, can you send a test mail with mail() and the -f parameter, so you get the correct Return-path in the header, and then copy all relevant fields *exactly* from that header (including correct upper/lower-casing while you're at it). Does that bring any improvement?
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: Smtp email - from and bounce

Post by webstyler »

Apollo wrote:As Eric suggests, try using CRLF (that's "\r\n") line endings instead of just \r in your $header string.
test with \r\n
nothing change, my return-path is ignored
Apollo wrote: If that doesn't make a difference, can you send a test mail with mail() and the -f parameter, so you get the correct Return-path in the header, and then copy all relevant fields *exactly* from that header (including correct upper/lower-casing while you're at it). Does that bring any improvement?
That's already done.. but mail() is local and not from one server to other server.

Think the issue is on exim or cpanel, that remove my return-path and insert default value

:banghead:
Post Reply