Page 1 of 2

contact form not emailing specified email address

Posted: Sat Feb 11, 2006 11:20 pm
by C_Calav
hey guys,

pulled this short mailer script out and used it again for a different website and for some reason i cannot get it to email the account specified. no error messages or anything, redirects to the page specified also too.

Code: Select all

ob_start();

   $recipient = '****@gmail.com';
   $subject = $_POST['contact_name'];
   $from = stripslashes($_POST['contact_email']);
   $msg = "Message from: $from\n\n".stripslashes($_POST['contact_message']);
   mail($recipient, $subject, $msg);

   header("Location: http://www.***.com/html/index.html");
can anyone see anything wrong?

thanks heaps

Posted: Sat Feb 11, 2006 11:26 pm
by feyd
missing headers? bad configuration? no mail service available (to php) on the server?

Posted: Sat Feb 11, 2006 11:43 pm
by C_Calav
all i have on the page is that code.
missing headers? bad configuration? no mail service available (to php) on the server?
^^ not sure! can you tell me what i can check?

one more thing not sure who the webhost is i should check that out i guess!

here are my two contact pages if that helps.


ill try a different email address in the mean time.

thanks.

contact.php

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	<title>ALC :: Winter 05</title>
<style type="text/css" media="all">
		@import "/css/alc_1.css";
	</style>

  
<script type="text/javascript">

		//-->

var errormessage = "" 
var passme=false	
	
function validate()
{
if(passme){passme=false;return true}

        errormessage = ""
        
	Name()
	Email()
	Enquiry()
	
	if (errormessage == "")
	{
	   return (true);	
	}
	else
	{
	   alert(errormessage)
       	   return (false);
    }
}

function Name()
{
	var name = window.document.contact.contact_name.value
	if (name == "")
	{
		errormessage = errormessage + "Please enter your Name\n"
	}
}

function Email()
{
	var email = window.document.contact.contact_email.value	
	if (email == "")
	{
		errormessage = errormessage + "Please enter your Email\n"
	}
	else if (email.indexOf("@")==-1)
	{
		errormessage = errormessage + "Your Email is not a valid Email\n"
	}
}

function Enquiry()
{
	var enquiry = window.document.contact.contact_message.value
	if (enquiry == "")
	{
		errormessage = errormessage + "Please enter your Message\n"
	}
}


	</script>
</head>

<div id="container_1">

 <h2>Contact</h2>

 <form name="contact" method="post" action="/html/contact_2.php" onsubmit="return validate()">

    <table width="450">
		<tr>
			<td width ="100">Name</td>
		</tr>
		<tr>
			<td><input name="contact_name" type="text" class="detailspage" /> </td>
		</tr>
		<tr>
			<td>Email</td>
		</tr>
		<tr>
			<td><input name="contact_email" type="text" class="detailspage" /></td>
		</tr>
		<tr>
			<td>Enquiry</td>
		</tr>
		<tr>
			<td><textarea name="contact_message" cols="40" rows="5"></textarea></td>
		</tr>
		<tr>
			<td><input type="submit" value="Send" class="contact btn" /></td>
		</tr>

   </table>



</form>

</div> <!-- end container -->
</body>
</html>
and contact_2.php

Code: Select all

<?php
ob_start();

   $recipient = '**@gmail.com';
   $subject = $_POST['contact_name'];
   $from = stripslashes($_POST['contact_email']);
   $msg = "Message from: $from\n\n".stripslashes($_POST['contact_message']);
   mail($recipient, $subject, $msg);

   header("Location: http://www.**/html/index.html");
?>

Posted: Sun Feb 12, 2006 2:14 am
by matthijs
Have you tested the mail function itself to see if anything is sent? running this script:

Code: Select all

<?php
mail("yourmail@gmail.com","test","hello test","From: mymail@domain.com");
?>

Posted: Sun Feb 12, 2006 3:39 am
by ed209
you have used ob_start(), my undertanding is that the output buffer stores the page until you decide to output it - apart from headers - so try putting ob_end_flush() at the end of your php page.

Posted: Sun Feb 12, 2006 2:39 pm
by C_Calav
hey guys,

thanks for both your replys.

will try what both of you suggested and get back if there are still some problems!

:D

Posted: Sun Feb 12, 2006 11:13 pm
by C_Calav
Hi guys,

just tried what you guys suggested.


matthijs - i did not recieve a email. nothing happened.


ed209 - added ob_end_flush(); and i got this error

Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/**/**.com/html/contact_2.php:9) in /hsphere/local/home/**/**.com/html/contact_2.php on line 11
here is the new code.

Code: Select all

ob_start();

   $recipient = 'chris.calav@gmail.com';
   $subject = $_POST['contact_name'];
   $from = stripslashes($_POST['contact_email']);
   $msg = "Message from: $from\n\n".stripslashes($_POST['contact_message']);
   mail($recipient, $subject, $msg);
ob_end_flush();

   header("Location: http://www.alcoholicclothing.com/html/index.html");
i checked the provider. it is 2globalmart

the plan they have is plan 6

you can find the plan features here http://www.2globalmart.com/multiple-dom ... sting.html

anything else i can check or try?

thanks

Posted: Sun Feb 12, 2006 11:30 pm
by Benjamin
You cannot have ANY output sent before the <?php tag preceding the ob_start() function. If you do the header cannot be sent.

Code: Select all

<?php
ob_start();
Will not work.

Code: Select all

<?php
ob_start();
Will not work.

Code: Select all

<?php
ob_start();
Will work.

I had to use the code tag on these as the php tag would not format the line feeds correctly

Posted: Sun Feb 12, 2006 11:46 pm
by C_Calav
thanks for the reply.

2 things - all three examples look the same to me

and i thought that is what i was doing?

oringal code

Code: Select all

<?php 
ob_start(); 

   $recipient = '**@gmail.com'; 
   $subject = $_POST['contact_name']; 
   $from = stripslashes($_POST['contact_email']); 
   $msg = "Message from: $from\n\n".stripslashes($_POST['contact_message']); 
   mail($recipient, $subject, $msg); 

   header("Location: http://www.**/html/index.html"); 
?>
trhanks for the help!

Posted: Sun Feb 12, 2006 11:50 pm
by feyd
viewtopic.php?t=1157 may be of interest..

Posted: Mon Feb 13, 2006 12:06 am
by Benjamin
C_Calav wrote: 2 things - all three examples look the same to me
If you don't see the difference between the 3, please look at them until you do. There is a difference, and this difference is the difference between your script working or not.

Posted: Mon Feb 13, 2006 12:27 am
by Roja
agtlewis wrote:
C_Calav wrote: 2 things - all three examples look the same to me
If you don't see the difference between the 3, please look at them until you do. There is a difference, and this difference is the difference between your script working or not.
The last two are the same. Its misleading, and your tone is condescending. You could have simply stated "The first one has a linefeed before the open php tag".

This is a site for helping and teaching others. Not insulting them.

If you don't understand that, re-read the previous line until you do. ;)

Posted: Mon Feb 13, 2006 1:11 am
by C_Calav
hi guys,


@agtlewis,

i see the difference now :oops:

Code: Select all

<?php
ob_start();
$recipient = 'chris.calav@gmail.com';
$subject = $_POST['contact_name'];
$from = stripslashes($_POST['contact_email']);
$msg = "Message from: $from\n\n".stripslashes($_POST['contact_message']);
mail($recipient, $subject, $msg);
header("Location: http://www.alcoholicclothing.com/html/index.html");
?>

this is exactly what it looks like in notepad. no spaces anywhere. there were no spaces before but i put everything really tight togther just to make sure.

still not getting anything in my mail box.

anything else i can try?

might not reply till tomorow but anyhelp what so ever will be gratefull

@feyd - will have a read tomorow morn :idea:

Posted: Mon Feb 13, 2006 5:41 am
by Roja
You ob_start, but you never finish - so no output is being sent to the browser. Remove that line.

You do output, but then do a header() line - you can't do that. Remove the header line.

Try that, and see if things work, and we can work on fixing those issues.

Posted: Mon Feb 13, 2006 2:01 pm
by C_Calav
Thanks for the reply and your help Roja,

will try the things you mentioned after work and will get back to you!