Connecting Tech Pros Worldwide Help | Site Map

PHP email form not working

  #1  
Old January 6th, 2007, 05:35 AM
alice
Guest
 
Posts: n/a
I found this code for making a php email form for a web site. It works
fine on my ISP, but not on my friends...could it be that my ISP uses
php5, I know that hers does not, so I assume it's php4. Is there anyway
to tell? Here's the code. It sends me email fine, but when it's on her
ISP, it says it sent the mail, but nothing goes through.

<?php
if (isset($submit)) {
switch ($recipient) {
case "whole-family":
$recipient_email = "gregf@kcls.org";
$subject = "Gregs test php mail";
break;
case "Brian":
$recipient_email = "brian@meyer-family.com";
$subject = "Message to Brian";
break;
case "Jessica":
$recipient_email = "jessica@meyer-family.com";
$subject = "Message to Jessica";
break;
case "Eric":
$recipient_email = "eric@meyer-family.com";
$subject = "Message to Eric";
break;
case "Paul":
$recipient_email = "paul@meyer-family.com";
$subject = "Message to Paul";
break;
case "Dudley":
$recipient_email = "dudley@meyer-family.com";
$subject = "Message to Dudley";
break;
}

if (!empty($name) and !empty($email) and !empty($message)) {
if (mail ($recipient_email, $subject, $message, "From: $name
<$email>"))
$status = "<p>Thanks for your message, $name, it has been
successfully
sent!</p>";
else
$status = '<p>Your message couldnt be sent! Please try again or
send
us a conventional e-mail to
<a href="mailto:gregf@kcls.org">gregf@kcls.org</a>.
Thank you!</p>';
}
else
$status = "Please fill the highlighted fields!";
}
?>

<html>
<head>
<title>www.meyer-family.com - Contact</title>
<style type="text/css">
<!--
.error { font-weight: bold; color: red; }
-->
</style>
</head>
<body>
<h1>Contact</h1>
<?php
if(isset($status))
echo ($status);
?>
<form action="contact.php" method="post">
<p>Send message to:
<select name="recipient" size="1">
<option value="whole-family">The whole Meyer family</option>
<option value="Brian">Brian</option>
<option value="Jessica">Jessica</option>
<option value="Eric">Eric</option>
<option value="Paul">Paul</option>
<option value="Dudley">Dudley</option>
</select></p>
<p<?php
if (isset($submit) and empty($name))
echo(' class="error"');
?>>Your name:
<input type="text" name="name" value="<?php if(!empty($name))
echo($name); ?>" size="30"
/></p>
<p<?php
if (isset($submit) and empty($email))
echo(' class="error"');
?>>Your e-mail address:
<input type="text" name="email" value="<?php if(!empty($email))
echo($email); ?>"
size="30" /></p>
<p<?php
if (isset($submit) and empty($message))
echo(' class="error"');
?>>Your message:
<textarea name="message" cols="30" rows="5"><?php
if(!empty($message))
echo($message);
?></textarea></p>
<input type="submit" name="submit" value="Send" />
</form>
</body>
</html>

  #2  
Old January 6th, 2007, 07:55 AM
Rik
Guest
 
Posts: n/a

re: PHP email form not working


alice wrote:
Quote:
I found this code for making a php email form for a web site. It works
fine on my ISP, but not on my friends...could it be that my ISP uses
php5, I know that hers does not, so I assume it's php4. Is there
anyway to tell? Here's the code. It sends me email fine, but when
it's on her ISP, it says it sent the mail, but nothing goes through.
Look for register_globals and the $_POST array.
--
Rik Wasmus


  #3  
Old January 6th, 2007, 04:05 PM
Michael Austin
Guest
 
Posts: n/a

re: PHP email form not working


Rik wrote:
Quote:
alice wrote:
>
Quote:
>>I found this code for making a php email form for a web site. It works
>>fine on my ISP, but not on my friends...could it be that my ISP uses
>>php5, I know that hers does not, so I assume it's php4. Is there
>>anyway to tell? Here's the code. It sends me email fine, but when
>>it's on her ISP, it says it sent the mail, but nothing goes through.
>
>
Look for register_globals and the $_POST array.
Here is a piece of code I found a long time ago that would extract all of the
get/post'ed variables if register_globals is off. Place this at the top of your
code...

if (!empty($_GET))
{
extract($_GET);
}
else if (!empty($HTTP_GET_VARS))
{
extract($HTTP_GET_VARS);
}

if (!empty($_POST))
{
extract($_POST);
}
else if (!empty($HTTP_POST_VARS))
{
extract($HTTP_POST_VARS);
}

--
Michael Austin.
Database Consultant
  #4  
Old January 6th, 2007, 08:15 PM
alice
Guest
 
Posts: n/a

re: PHP email form not working


Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
where this code does not work, is using php 4.4. Should I still try the
code your talking about, would it make any difference? We also
discovered that other php mail/form code that she had on her ISP that
was working the day before, has suddenly stopped working, but we
haven't changed anything ourselves.

Michael Austin wrote:
Quote:
Rik wrote:
>
Quote:
alice wrote:
Quote:
>I found this code for making a php email form for a web site. It works
>fine on my ISP, but not on my friends...could it be that my ISP uses
>php5, I know that hers does not, so I assume it's php4. Is there
>anyway to tell? Here's the code. It sends me email fine, but when
>it's on her ISP, it says it sent the mail, but nothing goes through.

Look for register_globals and the $_POST array.
>
Here is a piece of code I found a long time ago that would extract all of the
get/post'ed variables if register_globals is off. Place this at the top of your
code...
>
if (!empty($_GET))
{
extract($_GET);
}
else if (!empty($HTTP_GET_VARS))
{
extract($HTTP_GET_VARS);
}
>
if (!empty($_POST))
{
extract($_POST);
}
else if (!empty($HTTP_POST_VARS))
{
extract($HTTP_POST_VARS);
}
>
--
Michael Austin.
Database Consultant
  #5  
Old January 6th, 2007, 10:05 PM
Michael Austin
Guest
 
Posts: n/a

re: PHP email form not working


alice wrote:
Quote:
Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
where this code does not work, is using php 4.4. Should I still try the
code your talking about, would it make any difference? We also
discovered that other php mail/form code that she had on her ISP that
was working the day before, has suddenly stopped working, but we
haven't changed anything ourselves.
>
Michael Austin wrote:
>
Quote:
>>Rik wrote:
>>
>>
Quote:
>>>alice wrote:
>>>
>>>
>>>>I found this code for making a php email form for a web site. It works
>>>>fine on my ISP, but not on my friends...could it be that my ISP uses
>>>>php5, I know that hers does not, so I assume it's php4. Is there
>>>>anyway to tell? Here's the code. It sends me email fine, but when
>>>>it's on her ISP, it says it sent the mail, but nothing goes through.
>>>
>>>
>>>Look for register_globals and the $_POST array.
>>
>>Here is a piece of code I found a long time ago that would extract all of the
>>get/post'ed variables if register_globals is off. Place this at the top of your
>>code...
>>
> if (!empty($_GET))
> {
> extract($_GET);
> }
> else if (!empty($HTTP_GET_VARS))
> {
> extract($HTTP_GET_VARS);
> }
>>
> if (!empty($_POST))
> {
> extract($_POST);
> }
> else if (!empty($HTTP_POST_VARS))
> {
> extract($HTTP_POST_VARS);
> }
>>
>>--
>>Michael Austin.
>>Database Consultant
>
>
It has to do with the register_global settings in the php.ini file. If you are
deploying this to multiple servers - I would include it as you really do not
know what the setting is going to be from server to server [for a given ISP].

--
Michael Austin.
Database Consultant
  #6  
Old January 6th, 2007, 10:05 PM
Rik
Guest
 
Posts: n/a

re: PHP email form not working


Michael Austin wrote:
Quote:
alice wrote:
Quote:
>Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
>where this code does not work, is using php 4.4. Should I still try
>the
>code your talking about, would it make any difference? We also
>discovered that other php mail/form code that she had on her ISP that
>was working the day before, has suddenly stopped working, but we
>haven't changed anything ourselves.
>
It has to do with the register_global settings in the php.ini file.
If you are deploying this to multiple servers - I would include it as
you really do not
know what the setting is going to be from server to server [for a
given ISP].
Well, an another script that previously worked suddenly stopped working I
doubt it.

I'd suggest the following:
Make a small script with a hardcoded mail() statement, which sends the mail
to an emailadress without spam filtering. If this doesn't work, yet mail()
returns true, contact your hoster. If it does, then try with
spam-filtering. If that also works, it's the variables in the script that
are the problem. Try to var_dump them instead of mail()ing , to check what
value they hold.
--
Rik Wasmus


  #7  
Old January 7th, 2007, 08:35 PM
alice
Guest
 
Posts: n/a

re: PHP email form not working


Well now the code has started working again, and we did nothing. I
guess it was just a problem with the ISP.

Rik wrote:
Quote:
Michael Austin wrote:
Quote:
alice wrote:
Quote:
Actually, as it turns out, my ISP is using PHP 4.3 and hers, the one
where this code does not work, is using php 4.4. Should I still try
the
code your talking about, would it make any difference? We also
discovered that other php mail/form code that she had on her ISP that
was working the day before, has suddenly stopped working, but we
haven't changed anything ourselves.
It has to do with the register_global settings in the php.ini file.
If you are deploying this to multiple servers - I would include it as
you really do not
know what the setting is going to be from server to server [for a
given ISP].
>
Well, an another script that previously worked suddenly stopped working I
doubt it.
>
I'd suggest the following:
Make a small script with a hardcoded mail() statement, which sends the mail
to an emailadress without spam filtering. If this doesn't work, yet mail()
returns true, contact your hoster. If it does, then try with
spam-filtering. If that also works, it's the variables in the script that
are the problem. Try to var_dump them instead of mail()ing , to check what
value they hold.
--
Rik Wasmus
  #8  
Old January 7th, 2007, 09:15 PM
jiverbean
Guest
 
Posts: n/a

re: PHP email form not working


I have a similar problem with a PHP script not sending email. I get an
error message with a syntax error T_VARIABLE missing in the line where
the mail() function is.

TIA

jiverbean
http://www.aibiver.com/
aside from my PHP woes, I have some JavaScript issues, but that's
another story

  #9  
Old January 8th, 2007, 12:25 AM
jiverbean
Guest
 
Posts: n/a

re: PHP email form not working


jiverbean wrote:
Quote:
I have a similar problem with a PHP script not sending email. I get an
error message with a syntax error T_VARIABLE missing in the line where
the mail() function is.
>
TIA
>
jiverbean
http://www.aibiver.com/
aside from my PHP woes, I have some JavaScript issues, but that's
another story
I looked up the PHP manual, and thought the issue was due to the
whitespace (tabs, and newlines) in the concatenation of the mail
header.

There was a semi-colon missing in the statement before the line with
the error message.

Thanks for your patience,
jiverbean

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
CURL redirect not working even with CURLOPT_FOLLOWLOCATION set totrue Sarah answers 3 July 26th, 2008 09:15 PM
help with email form alice answers 20 August 16th, 2007 03:05 PM
AJAX .responseText not working - Please Help! Snt answers 3 August 28th, 2006 05:55 PM