Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a question. I will be using either perl or php (whichever I get helped with first) to make a script to grab some information from a form, and mail it to a specified email address. Now, I've used the mail function in both. My problem is, the web server and the mail server are 2 separate servers. How do I specify the email server so that when I click submit, the web server sends the request to the email server? Sorry if i'm not being clear enough. Any help would be appreciated.

heya hybernate20,
(btw: I'm a musician too)
What I would do is set up 3 PHP pages on your web server to handle the mail() function, and your email server will just do the receiving.
Set up three .php pages:
[1] contact.php
[2] mail.php
[3] success.phpThe contact.php contains the form field text boxes for user input and a click button or whatever to start the send process.
[1] CONTACT.PHP
<form action="mail.php" method="POST" name="mailer">
NAME:
<input type="text" name="name" value="" />
EMAIL:
<input type="text" name="email" value="" />
WRITE A MESSAGE
<textarea name="details" text="" cols="40" rows="7"></textarea><input type="submit" name="submit" value="SEND" />
</form>[2] MAIL.PHP
<?php$name = $_POST['name'];
$email = $_POST['email'];
$details = $_POST['details'];if(($_POST['name'] == "") || ($_POST['email'] == "") || ($_POST['details'] == "")){
// REQUIRES USER INPUT IN ALL 3 TEXT BOXES
// IF ANY OF THEM ARE EMPTY, REDIRECT HEADER
// BACK TO THE CONTACT PAGEheader("Location: contact.php");
}else {
$message = "<html><body>";
$message .= "name: $name<br />";
$message .= "email: $email<br />";
$message .= "$details<br />";
$message .= "</body></html>";$to = "youremail@goeshere.com";
$subject = "Feedback Band Web Inquiry";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";mail($to, $subject, $message, $headers);
// REDIRECT TO 'success.php' WHEN MAIL //FUNCTION IS FINISHED
header("Location: success.php");
}
?>[3] SUCCESS.PHP
Just create a .PHP page with anything you wish to say to confirm their email has safely been sent.

Thanks for all the help. The only thing is, how do I point the program to my mail server? It does have its own IP address...its on a different box than the web server.

"For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time."
This is a little beyond my scope as I farm out my hosting, but from a little information I found you need to have sendmail or another MTA appication installed at the time you compile the PHP from source. You do not need to point it to your mail server.
Michael J

Sorry, forgot to post the link where I got the quote: http://us3.php.net/manual/en/ref.mail.php
There should be more information you can find there.
Michael J

Michael J is right - you don't need to point it to your mail server, since the $to variable contains the destination of the email.
Also, the PHP mail() function must be included during compile time when the server installed PHP, otherwise it will be missing. I ran into this problem before, and contacted the hosting administrator, and he recompiled PHP for me, and even upgraded to a higher distribution.
If it isn't working, as is, then contact your web hosting administrator. The script I included here should work fine.

So basically, I need to have a mail server installed on the web server as well? I can't tell the program to send the email using a different server?

PHP's mail() function is a core function and should be installed already. We were simply saying "IF" the mail() function isn't included with your PHP installation, you can simply call your host and have them recompile PHP.
But, the way you have it set up, it should work. Why don't you just try it and find out?
I gave you the script for 3 pages that should target your mail server without a PERL script or anything.
All you need to do is change the place where it says:
$to = "youremail@goeshere.com";Put your email address in there, save those 3 pages "contact.php", "mail.php", and "success.php" on your server, and then load the contact.php page. It should give you the text boxes and a click button. Fill in the blanks (all of them are required), then click the SEND button.
This sends the text to the mail.php using the POST method. The text is placed into the right variables, and sent to the email address YOU CHOOSE.
If the email is sent successfully, then the mail.php page sends you to the success.php page.
That's all there is to it. Go ahead and try it. You'll have it running in 10 minutes if the PHP mail() function is working properly on your server.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |