Jump to content


Photo

php email script help


  • Please log in to reply
8 replies to this topic

#1 msaz87

msaz87
  • Members
  • PipPipPip
  • Advanced Member
  • 190 posts

Posted 06 July 2006 - 10:08 PM

Hey guys,

Here's my problem...

I configured a php-email script on one server, but it no longer works on a new server of mine (Apache 2.2). I actually don't remember where i found the script, i think it was just off a university website or something. In any case, here's the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Arizona Belo - Ask the Managers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#DD1032">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="56%" id="table17" cellspacing="0" cellpadding="0">
	<tr>
		<td width="435">
<?php
// SECTION 1
// if the variable "form_submitted" is true, it means that the "Submit" button has been pressed
if ($_POST['form_submitted']) { // if "true" process form
	 
	 // SECTION 2
	 // get our form field values and put them in variables
	 $name = $_POST['name'];
	 $department = $_POST['department'];
	 $question = $_POST['question'];
	 
	 // SECTION 3
	 // Type your thank you message here.
	 $thank_you_message = "Thank you for submitting your question. You may now close this window.";
	 
	 
	 // SECTION 4
	 // build the mail function
	 $to = "$email";
	 
	 // Type the phrase you want to show up in the subject line
	 $subject = "Ask the Managers Question";
	 
	 // Type the message you want to appear in the body of the email
	 $message = "Name: $name\n\nDepartment: $department\n\nQuestion: $question\n\n";
	
	// SECTION 5
	// call mail function (will send the email)
	// the mail function returns true upon a successfull send so if the mail is sent you can say thanks
	// Change information after From: to match your name and email address
	if (mail("******@yahoo.com","Ask the Managers Question","$message",'From: "Form Sender" <noone@formsender.com>')) { 
		echo "$thank_you_message";
	} else {
		echo "There was sort of problem that was beyond me.";
	}

// SECTION 6
} else { // else, show form
?>
<input type="hidden" name="form_submitted" value="true" />
<p style="margin-top: 0; margin-bottom: 0">
<img border="0" src="images/logos/askmanagerslogo.gif" width="435" height="100"></p>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="0" width="95%" id="table18" cellspacing="3" cellpadding="3">
	<tr>
		<td>
<p style="margin-top: 0; margin-bottom: 0" align="left"><b>
<font color="#FFFFFF" face="Verdana" size="2">Name (Optional): </font></b> &nbsp;</p>
		</td>
		<td width="169">
		<p align="center"><font face="Verdana">
		<input input type="text" name="name" size="30" /></font></td>
	</tr>
	<tr>
		<td>
<p style="margin-top: 0; margin-bottom: 0" align="left"><b>
<font color="#FFFFFF" face="Verdana" size="2">Department (Optional):</font></b>  
		</p>
		</td>
		<td width="169">  
		<p align="center">  
		<font face="Verdana"> 
		<input input type="text" name="department" size="30" /></font></td>
	</tr>
</table>
</div>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<table border="0" width="99%" id="table19" cellspacing="0" cellpadding="0">
	<tr>
		<td>
		<p align="center" style="margin-top: 0; margin-bottom: 0">
<font color="#FFFFFF" face="Verdana" size="2"><b>Question:</b></font></p>
		<p align="center" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<p align="center" style="margin-top: 0; margin-bottom: 0"><textarea rows="6" name="question" cols="33"></textarea></p>
		<p align="center" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<p align="center" style="margin-top: 0; margin-bottom: 0"><font face="Verdana">
<input input type="submit" name="submit" value="Ask!" style="font-family: Verdana; font-size: 12pt; color: #FFFFFF; font-weight: bold; font-style: italic; border: 2px outset #FFFFFF; background-color: #6F0205" /></font></p>
		</td>
	</tr>
</table>
<p align="center" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="1" width="94%" id="table20" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table21" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
</div>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="1" width="94%" id="table28" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table29" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
</div>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="1" width="94%" id="table30" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table31" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
	<p style="margin-top: 0; margin-bottom: 0">&nbsp;</div>
<div align="center">
<table border="1" width="94%" id="table32" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table33" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
</div>
		</td>
		<td>&nbsp;</td>
	</tr>
</table>
<input type="hidden" name="form_submitted" value="true" />
</form>
</body>
</html>

When i hit submit, it presents the "There was sort of problem that was beyond me." error (makes sense if you read the code).

The code isn't very clean.. but it worked on the other server. I also ran a simple script to test the e-mail function of php on my new server and it failed.

Any guidance is appreciated. Thanks.

#2 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 07 July 2006 - 12:55 AM

$to = "$email";
where are you declaring the $email var?  does it have a value somewhere else in the script?
"Confidence in the face of risk."

#3 msaz87

msaz87
  • Members
  • PipPipPip
  • Advanced Member
  • 190 posts

Posted 07 July 2006 - 01:12 AM

I got that same question on another forum. The answer is... i don't know.

I'm not very familiar with php, i know only enough to somewhat modify premade scripts. So basically, i had changed it enough to work on the original server (run by lunarpages). I copied the file to the new server (run by me) exactly.... so all the code, correct or wrong, worked on the lunar server and not on this one.

Is it possible when Apache was installed on the new server that the mail function wasn't installed?

Thanks.

#4 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 08 July 2006 - 03:59 AM

$to = "$email";

change $email to your own address then run the script. if it sends you an e-mail, then you know where the problem is.

$email is the variable that should contain the address where you want your e-mail sent to. the variable has to be set somewhere else in the script - either from the submitted form, or hard coded by you.
"Confidence in the face of risk."

#5 msaz87

msaz87
  • Members
  • PipPipPip
  • Advanced Member
  • 190 posts

Posted 09 July 2006 - 08:26 PM

I changed the code to the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Arizona Belo - Ask the Managers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#DD1032">
<body bgcolor="#DD1032">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="56%" id="table17" cellspacing="0" cellpadding="0">
	<tr>
		<td width="435">
<?php
// SECTION 1
// if the variable "form_submitted" is true, it means that the "Submit" button has been pressed
if ($_POST['form_submitted']) { // if "true" process form
	 
	 // SECTION 2
	 // get our form field values and put them in variables
	 $name = $_POST['name'];
	 $department = $_POST['department'];
	 $question = $_POST['question'];
	 
	 // SECTION 3
	 // Type your thank you message here.
	 $thank_you_message = "Thank you for submitting your question. You may now close this window.";
	 
	 
	 // SECTION 4
	 // build the mail function
	 $to = "***@yahoo.com";
	 
	 // Type the phrase you want to show up in the subject line
	 $subject = "Ask the Managers Question";
	 
	 // Type the message you want to appear in the body of the email
	 $message = "Name: $name\n\nDepartment: $department\n\nQuestion: $question\n\n";
	
	// SECTION 5
	// call mail function (will send the email)
	// the mail function returns true upon a successfull send so if the mail is sent you can say thanks
	// Change information after From: to match your name and email address
	if (mail("****@yahoo.com","Ask the Managers Question","$message","From: "Form Sender" <noone@formsender.com>")) { 
		echo "$thank_you_message";
	} else {
		echo "There was sort of problem that was beyond me.";
	}

// SECTION 6
} else { // else, show form
?>
<input type="hidden" name="form_submitted" value="true" />
<p style="margin-top: 0; margin-bottom: 0">
<img border="0" src="images/askmanagerslogo.gif" width="435" height="100"></p>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="0" width="95%" id="table18" cellspacing="3" cellpadding="3">
	<tr>
		<td>
<p style="margin-top: 0; margin-bottom: 0"><b>
<font color="#FFFFFF" face="Verdana" size="2">Name (Optional): </font></b> &nbsp;</p>
		</td>
		<td width="192"><font face="Verdana">
		<input input type="text" name="name" size="35" /></font></td>
	</tr>
	<tr>
		<td>
<p style="margin-top: 0; margin-bottom: 0"><b>
<font color="#FFFFFF" face="Verdana" size="2">Department (Optional):</font></b>  
		</p>
		</td>
		<td width="192">  
		<font face="Verdana"> 
		<input input type="text" name="department" size="35" /></font></td>
	</tr>
</table>
</div>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<table border="0" width="99%" id="table19" cellspacing="0" cellpadding="0">
	<tr>
		<td>
		<p align="center" style="margin-top: 0; margin-bottom: 0">
<font color="#FFFFFF" face="Verdana" size="2"><b>Question:</b></font></p>
		<p align="center" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<p align="center" style="margin-top: 0; margin-bottom: 0"><textarea rows="6" name="question" cols="33"></textarea></p>
		<p align="center" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<p align="center" style="margin-top: 0; margin-bottom: 0"><font face="Verdana">
<input input type="submit" name="submit" value="Ask!" style="font-family: Verdana; font-size: 12pt; color: #FFFFFF; font-weight: bold; font-style: italic; border: 2px outset #FFFFFF; background-color: #6F0205" /></font></p>
		</td>
	</tr>
</table>
<p align="center" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="1" width="94%" id="table20" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table21" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
</div>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="1" width="94%" id="table28" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table29" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
</div>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<div align="center">
<table border="1" width="94%" id="table30" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table31" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
	<p style="margin-top: 0; margin-bottom: 0">&nbsp;</div>
<div align="center">
<table border="1" width="94%" id="table32" cellspacing="0" cellpadding="0" bordercolor="#6F0205" style="border: 1px solid #000000">
	<tr>
		<td bgcolor="#FFFFFF">
		<table border="0" width="100%" id="table33" cellspacing="1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0"><b><font size="2" face="Verdana" color="#6F0205">Question 1: 
				Why isn't there more coffee in the break room?</font></b></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td>
		<p style="margin-top: 0; margin-bottom: 0"><font face="Verdana" color="#FFFFFF" size="2">&nbsp;We can't afford 
		it. Sorry.</font></td>
	</tr>
</table>
</div>
		</td>
		<td>&nbsp;</td>
	</tr>
</table>
<input type="hidden" name="form_submitted" value="true" />
</form>
<?php
}
?>
</body>
</html>

The script still did not work, though.

I also ran this code to test the e-mail system:
<?

$to = '****@yahoo.com';    // REPLACE THIS WITH YOUR E-MAIL ADDRESS
$subject = 'PHP mail Test';
$message = 'This is a test of PHP mail';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if (mail($to, $subject, $message, $headers))
  echo "MAIL SENT\n";
else
  echo "MAIL FAILED\n";

?>

That script also failed.

So.. my only guess is there's something wrong with the way the mail function is set up in php?

Any ideas?

#6 a1ias

a1ias
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 09 July 2006 - 08:48 PM

try running this:

<?php

if (isset($_POST['sendit'])) {

    $to = "*****@emailaddy.com!"; //Change to your email
    $subject = "Test Email";
    $message = "Hello, this is a test email.";
    $headers = "From: someone@somewhere.com";

    mail($to,$subject,$message,$headers);

    echo "Mail sent, check your inbox";
    exit;

} else {

?>

<form  method="post" action="<?php $_SERVER['PHP_SELF']; ?>">

<input type="submit" name="sendit" value="Send It" />

</form>

<?php

}

?>

If that works, your mail setup is fine.



#7 msaz87

msaz87
  • Members
  • PipPipPip
  • Advanced Member
  • 190 posts

Posted 09 July 2006 - 09:12 PM

Didn't work.

<?php

if (isset($_POST['sendit'])) {

    $to = "msaz87@yahoo.com"; //Change to your email
    $subject = "Test Email";
    $message = "Hello, this is a test email.";
    $headers = "From: someone@somewhere.com";

    echo "Mail sent, check your inbox";
    exit;

} else {

?>

<form  method="post" action="<?php $_SERVER['PHP_SELF']; ?>">

<input type="submit" name="sendit" value="Send It" />

</form>

<?php

}

?>

Any ideas how i can check the setup of the mail function?

The following is taken from my php.ini regarding the SMTP setup... not sure if this is what i should be looking at or not though.
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

(the above code is verbatim)

Thanks for your help.

#8 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 09:39 PM

Oh, if you're on windows then you'll need a separate SMTP server, which you may know.
If it's not up that'll be a problem.
I don't know about the set up, try using your email accounts' SMTP server.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#9 msaz87

msaz87
  • Members
  • PipPipPip
  • Advanced Member
  • 190 posts

Posted 10 July 2006 - 08:57 PM

I was able to find the IP address for the SMTP server. So i plugged it into my php.ini as so:

[mail function]
; For Win32 only.
SMTP = 147.***.233.10
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

I restarted the server after making the changes.. but the e-mails still don't go.

Any ideas?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users