...

View Full Version : PLEASE HELP... with my email script



lozbenson
10-30-2009, 08:33 PM
So far I have what is below, it sends and replies to emails like it is supposed to however I can not get it to show error messages in the area provided...

It seems not to show the error messages of confirmation...

if it is of help give it a go at www.erbimages.com/contact.php

just use demo demo demo etc in the fields...

PLEASE HELP... heres the script...


<?php
if(isset($_POST['send'])){
$to = $_REQUEST['sendto'] ; // change all the following to $_POST
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@erbimages.com";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";
$send=false;
if($from == '') {$error= "You have not entered an email, please go back and try again";}
else {
if($name == '') {$error= "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
if(!isset($error) && !$send)
$error= "We encountered an error sending your mail, please notify service@erbimages.com"; }
}// end of if(isset($_POST['send']))
?>

<?php include("http://www.erbimages.com/php/head.php"); ?>
<?php include("http://www.erbimages.com/php/start.php"); ?>
<?php include("http://www.erbimages.com/php/topline/return.php"); ?>

<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_header_right_contact">CONTACT</span>
</li>
<li>
<span id="section_txt">

<?php
if(isset($error))
echo '<span id="section_error">'.$error.'</span>';
if(isset($send) && $send== true){
echo 'Your message has been send. Thank you.';
}
if(!isset($_POST['send']) || isset($error))
?>

<form method="post" action="contact.php">
<p>Your Details</p>
<p><select name="sendto"><option value="info@erbimages.com">Information</option> <option value="hire@erbimages.com">Hire</option> <option value="rf@erbimages.com">Royalty Free</option> <option value="service@erbimages.com">Technical</option></select></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Name:</font><input size=25 name="Name"></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Email:</font><input size=25 name="Email"></p>
<p><font style="padding-right: 2em;">Company / Event:</font><input size=25 name="Company"></p>
<p>Message</p>
<p><textarea name="Message" rows=5 cols=35></textarea></p>
<p><input type=submit name="send" value="Submit"></p>
</form>
</span>
</li>
</ul>
</div>

<?php include("http://www.erbimages.com/php/quiet_footer.php"); ?>
<?php include("http://www.erbimages.com/php/end.php"); ?>


PLEASE HELP, I REALLY NEED YOU...

tomws
10-30-2009, 10:10 PM
Try some debugging. You can do some quick but ugly debugging with die(). I'd start here:

if(isset($_POST['send'])){
die("I'm here");


That will confirm you're actually entering the area for the assignments and tests. If that shows up, move the die() to another block a little later and test if control is going through there. When it stops dying, you've found the problem area.

_Aerospace_Eng_
10-30-2009, 11:04 PM
Hmm you should probably change this

if(!isset($error) && !$send)

to this

if($error == '' && !$send)

Then at the top of your code add $error = '';

Then change this

if(isset($error))
echo '<span id="section_error">'.$error.'</span>';
to this

if($error != '')
echo '<span id="section_error">'.$error.'</span>';

lozbenson
10-30-2009, 11:55 PM
Have done...

So now it reads


<?php
if(isset($_POST['send'])){
$to = $_REQUEST['sendto'] ; // change all the following to $_POST
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@erbimages.com";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";
$send=false;
if($from == '') {$error= "You have not entered an email, please go back and try again";}
else {
if($name == '') {$error= "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
if($error == '' && !$send)
$error= "We encountered an error sending your mail, please notify service@erbimages.com"; }
}// end of if(isset($_POST['send']))
?>

<?php include("http://www.erbimages.com/php/head.php"); ?>
<?php include("http://www.erbimages.com/php/start.php"); ?>
<?php include("http://www.erbimages.com/php/topline/return.php"); ?>

<div class="section_right">
<ul id="section_contact">
<li>
<span id="section_header_right_contact">CONTACT</span>
</li>
<li>
<span id="section_txt">

<?php
if($error != '')
echo '<span id="section_error">'.$error.'</span>';
if(isset($send) && $send== true){
echo 'Your message has been send. Thank you.';
}
if(!isset($_POST['send']) || isset($error))
?>

<form method="post" action="contact.php">
<p>Your Details</p>
<p><select name="sendto"><option value="info@erbimages.com">Information</option> <option value="hire@erbimages.com">Hire</option> <option value="rf@erbimages.com">Royalty Free</option> <option value="service@erbimages.com">Technical</option></select></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Name:</font><input size=25 name="Name"></p>
<p><font color=red>*</font> <font style="padding-right: 2em;">Email:</font><input size=25 name="Email"></p>
<p><font style="padding-right: 2em;">Company / Event:</font><input size=25 name="Company"></p>
<p>Message</p>
<p><textarea name="Message" rows=5 cols=35></textarea></p>
<p><input type=submit name="send" value="Submit"></p>
</form>
</span>
</li>
</ul>
</div>

<?php include("http://www.erbimages.com/php/quiet_footer.php"); ?>
<?php include("http://www.erbimages.com/php/end.php"); ?>

Unfortunately it still doesn't work...

Any other ideas?

_Aerospace_Eng_
10-31-2009, 08:22 AM
You missed a step read it again. Change this

<?php
if($error != '')
echo '<span id="section_error">'.$error.'</span>';
to this

<?php
echo $error;
if($error != '')
echo '<span id="section_error">'.$error.'</span>';
and mess up on the form on purpose. Do you get any php errors?

lozbenson
10-31-2009, 02:18 PM
Have change...

No I dont get any errors, it was working fine before but it started not to show up the error messages, that is the only reason it doesnt work...

Any clues?

lozbenson
10-31-2009, 03:57 PM
Got it working now, thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum