mail()-ing from a different server

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

Post Reply
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

mail()-ing from a different server

Post by heiatufte »

Hi,
I'll try to be as short and precise as possible... ;)

My server doesn't support the mail() function so I need to use that function from another server.
I have full access to both servers.
My own server has a registration page, which leads to a process page which retrieves the POST information, inserts it into a database, (is supposed to) send an email to the administrator (me) and then shows results back to the user.

Now, it isn't so hard to create the page on the other server which retrieves POST info and uses it in the mail() function. The problem is to unite it with the other page so that the user is redirected forth and back without noticing. Ok so perhaps he/she notices it, the point is that he/she shouldn't need to repost on the other server, I'd like the page to repost automatically.

Including or requiring wouldn't work of course, the other server would just send the processed PHP page back to my server.

Another solution could be if it went like a brench on a tree; e.g. a small side window opens on the remote server, posts, the server sends the email and the window is closed (and the other post just continiued uninterrupted). That way, I could use the same email page on the other server from several of my pages.

If I could POST header("Location ..."); that would be a good solution. I don't think that's possible but is there another way to do it?
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

Why not just use CURL() or fsockopen(), I think it will give you far more control. You can even use fsockopen() to send mail if imap is not on the server. Redirects are fine for some things, but PHP like any good scripting language gives easier ways to do things even if you can't do them the simple way.


yj
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Post by heiatufte »

Whoa, that doesn't seem like a bad idea. Thanks, and thanks for the incredibly quick reply!
I'll try to look into the function, which I've never actually used before, and get back to you if there's any problem ;)
By the way: what do you mean "even if imap is not on the server"? Isn't the only _send_ protocol for email SMTP?
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

If you need help just tell me I will give you example based on what your trying to do! This way the whole public process is done on one server and the back end script contacts the other server and processes the request internally! User never has to be redirect, it more professional than doing redirects, plus error control can be better managed.

yj
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Post by heiatufte »

Well, I think perhaps you mean to use fsockopen() to contact the other server with the PHP script, and then somehow use the other script. As you say that's better than what I was trying to do in the first place, but even better would be to just use fsockopen() to send the email to an smtp server, don't you think?
As a matter of fact, I have a third server which I use as just an email server (it unfortunately runs windows 2000, I can't manage to get email serving working on the linux box) and I use the web server to contact the mail server with smtp:

Code: Select all

$fp = fsockopen("my.mail.server.com", 25);
if ($fp) {
   $out = "HELO mywebsitename\r\n";
   $out .= "MAIL FROM ".$from."\r\n";
   $out .= "RCPT TO ".$to."\r\n";
   $out .= "DATA\r\n";
   $out .= $text; // remember to put headers and an extra \n when starting on bread text
   $out .= "\r\n";
   $out .= ".\r\n";
   $out .= "QUIT";

   fwrite($fp, $out);
   fclose($fp);
}
Something like that should work, I haven't tested it yet.
Even though that perhaps wasn't your intention (if I get you right) you gave me the idea, so thanks ;)
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

That sort right, put you have to loop (read and write) to the socket. Give me 30 minutes and I will write you something that will work and will support LOGIN if the server needs it!


yj
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Post by heiatufte »

Hehe, if you'd do that, I'd be very grateful :)
Post Reply