Click to See Complete Forum and Search --> : Smtp & Php


Genixdeae
01-11-2005, 01:06 AM
Ok, i have the following script to send mail thro SMTP on a XP pro machine.<?PHP
function valid_email($email) {
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"; //Validate the email address
$valid = 1; //Presume it is valid
if(eregi($regexp, $email)) {
return $valid;
}
}

if(isset($_GET["task"]) && $_GET["task"] != "") {
if(isset($_POST["email"]) && $_POST["email"] != "") {
if(isset($_POST["subject"]) && $_POST["subject"] != "") {
if(isset($_POST["message"]) && $_POST["message"] != "") {
if(isset($_POST["cc"]) && $_POST["cc"] != "") {
if(valid_email($_POST["email"])) {
if(valid_email($_POST["cc"])) {
$headers = "From: ". $_POST["email"] ."\r\n";
$headers .= "Cc: ". $_POST["cc"] ."\r\n";
mail("mail@mail.com", $_POST["subject"], $_POST["message"], $headers);
echo "Your mail has been sent. We will get back to you shortly.";
}else{
echo "The Cc email address's you entered are not valid. Please go back and enter valid one(s).";
}
}else{
echo "The email address you entered is not valid. Please go back and enter a valid one.";
}
}else{
if(valid_email($_POST["email"])) {
$headers = "From: ". $_POST["email"] ."\r\n";
mail("mail@mail.com", $_POST["subject"], $_POST["message"], $headers);
echo "Your mail has been sent. We will get back to you shortly.";
}else{
echo "The email address you entered is not valid. Please go back and enter a valid one.";
}
}
}else{
echo "You need to go back and enter a message.";
}
}else{
echo "You need to go back and enter a subject.";
}
}else{
echo "You need to go back and enter an email address.";
}
}
?>Now this script works with PHP installed and running on IIS 5(on XP Pro SP1). I tried putting it on a server 2k3(IIS 6) and when i submit the form(and it to send the mail) it doesnt bring up any errors and says everything was sent fine. however when i check my mail nothing is getting recieved....anyone have an idea on what's wrong?

FYI:we tried another PHP send mail script another person made to make sure mine wasn't screwy and it did the same thing. it says it send it but in reality it doesnt.

any help or ideas is appriciated.

Exuro
01-11-2005, 01:30 AM
Are you sure that the SMTP server is running and properly configured on the 2k3 machine? Maybe you should try using an ASP.Net sendmail function to see if that works, and if it does then you know it's a PHP-specific problem.

Genixdeae
01-11-2005, 08:59 AM
u dont happen to know how to build an asp.net one do u? I dont know nething about asp.net so...

i was told by another person that you have to configure the php.ini file differantly on a 2k3 server machine then xp pro. and so i made a few changes(like i put in a mail.domain.com in the SMTP =)...

Exuro
01-11-2005, 12:02 PM
Place this code in an ASPX file (such as "test.aspx") on your server, and when you visit the page it should automatically send the email:
<% @Import Namespace="System.Web.Mail" %>
<script language="C#" runat="server">
void Page_Load(Object src, EventArgs E) {
try {
SmtpMail.SmtpServer = "127.0.0.1";
SmtpMail.Send("from@address.com","to@address.com","Subject","Message");
Response.Write("<h1>Mail Sent</h1>\n");
}
catch (Exception ex) {
Response.Write("<h1>Send Mail Error</h1>\n");
}
}
</script>

Genixdeae
01-21-2005, 06:37 PM
ok, the aspx one worked so it is php...but what could it be?

Exuro
01-22-2005, 01:50 PM
Is your sendmail_path set to null, and your SMTP set to localhost in your INI file?

Genixdeae
01-22-2005, 03:44 PM
ok, figured it out. when we had the ini file set to localhost for the SMTP and the Smtpfrom_mail(or sumtin like that) was set to blank it didnt work. that aspx script gave me an idea of trying to put 127.0.0.1 instead of localhost. so i set SMTP = 127.0.0.1 and Smtpfrom_mail = administrator@127.0.0.1 and it worked!

anyways thanks for the help guys :)