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
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sat Feb 11, 2006 11:20 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Feb 11, 2006 11:26 pm
missing headers? bad configuration? no mail service available (to php) on the server?
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sat Feb 11, 2006 11:43 pm
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 » Sun Feb 12, 2006 2:14 am
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");
?>
ed209
Forum Contributor
Posts: 153 Joined: Thu May 12, 2005 5:06 am
Location: UK
Post
by ed209 » Sun Feb 12, 2006 3:39 am
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.
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sun Feb 12, 2006 2:39 pm
hey guys,
thanks for both your replys.
will try what both of you suggested and get back if there are still some problems!
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sun Feb 12, 2006 11:13 pm
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
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sun Feb 12, 2006 11:30 pm
You cannot have
ANY output sent before the <?php tag preceding the ob_start() function. If you do the header cannot be sent.
Will not work.
Will not work.
Will work.
I had to use the code tag on these as the php tag would not format the line feeds correctly
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sun Feb 12, 2006 11:46 pm
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!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Feb 12, 2006 11:50 pm
viewtopic.php?t=1157 may be of interest..
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Mon Feb 13, 2006 12:06 am
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 » Mon Feb 13, 2006 12:27 am
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.
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Feb 13, 2006 1:11 am
hi guys,
@agtlewis,
i see the difference now
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
Roja
Tutorials Group
Posts: 2692 Joined: Sun Jan 04, 2004 10:30 pm
Post
by Roja » Mon Feb 13, 2006 5:41 am
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.
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Feb 13, 2006 2:01 pm
Thanks for the reply and your help Roja,
will try the things you mentioned after work and will get back to you!