Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

msaz87

php email script help

Recommended Posts

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:

[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>[/CODE]

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.

Share this post


Link to post
Share on other sites
[code]$to = "$email";[/code]
where are you declaring the $email var?  does it have a value somewhere else in the script?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
$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.

Share this post


Link to post
Share on other sites
I changed the code to the following:

[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">
<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>[/code]

The script still did not work, though.

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

$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";

?> [/code]

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?

Share this post


Link to post
Share on other sites
try running this:

[code]
<?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

}

?>
[/code]

If that works, your mail setup is fine.

Share this post


Link to post
Share on other sites
Didn't work.

[code]<?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

}

?>[/code]

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.
[code][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 =[/code]

(the above code is verbatim)

Thanks for your help.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I was able to find the IP address for the SMTP server. So i plugged it into my php.ini as so:

[code][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 =[/code]

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

Any ideas?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.