contact form not emailing specified email address

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

contact form not emailing specified email address

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

missing headers? bad configuration? no mail service available (to php) on the server?
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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");
?>
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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");
?>
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

Post 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.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=1157 may be of interest..
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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. ;)
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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:
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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!
Post Reply