Jump to content


Photo

Problems with mail


  • Please log in to reply
26 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 05:06 PM

Ok the url is [a href=\"http://www.funnyemailforwards.com/contactus.php\" target=\"_blank\"]page[/a]
The problem is the everything is working great, but the bottom section where I am sending the mail, the message that is suppose to appear if it is sent, is displaying first thing, and emailing it as soon as the page opens, don't I have the control structure set up right, I didn't want to test each and every field individually, I wanted to test them all like this, and have it display all error messages it runs across, but this didn't work, I also tried with if, the else if, then else at the end but it only displayed one error at a time, and I am not ready to start learning how to create an array with them and do it that way, I am learning very fast, getting better and better, and forcing myself into difficult situations to learn, but I am learning, and I don't want to rush that, until I have 100% understanding over control structures this is where my problem currently lies.

<?php
if (isset($_POST['submit'])){
    if (empty($_POST['name'])){
    print('The name field has been left blank<br />');
    }if (empty($_POST['emailaddress'])){
    print('The Email Address field was left blank<br />');
    }if (empty($_POST['verifyemail'])){
    print('The Verify Email Field was left blank<br />');
    }if ($_POST['emailaddress'] != $_POST['verifyemail']){
    print('The Email Addresses do not match, please fix this<br />');
    }if (empty($_POST['description'])){
    print('The Description Field was left blank<br />');
    }}else {
    $to = "businessman332211@hotmail.com";
    $subject = "FunnyEmailForwards.com contact";
    $name = $_POST['name'];
    $emailaddress = $_POST['emailaddress'];
    $verifyemail = $_POST['verifyemail'];
    $description = $_POST['description'];
    $from = "$emailaddress";
    $message = "
    Name: {$name}
    Email Address: {$emailaddress}
    Verify Email: {$verifyemail}
    What the person had to say:
    {$description}
    ";
        if (mail($to, $subject, $message, $From)){
        print('Thank you for contacting us!<br />');
        print('We will try and get back to you within 24 hours.<br />');
        }else{
        print('There was an error sending the message, please try again!<br />');
        print('If it does not work the second time, please send an email directly to<br />');
        print('<a href="mailto:businessman332211@hotmail.com">Here</a>');
        }};
    
    
    
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 05:18 PM

Somehow your $_POST contains a variable called "submit". That's the only way I can figure this doesn't work. Try changing the name of the submit button to something else and then modifying your first if statement.

Also, this should be above the form, not below it.

One more thing, when you submit, it doesn't refill the form with the info you already submitted. You might want to fix that. And it wouldn't hurt to say what was required and what wasn't. If it's all required, say so.

Info: PHP Manual


#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 05:23 PM

ok I will change those, the one question that is puzzling me though, before when I tried putting it above, after it finished validating the form below it dissapeared, and didn't work anymore

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 05:27 PM

Can you show us the code for the entire page, with the changes? And also do this:

print_r($_POST);

Info: PHP Manual


#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 05:39 PM

I made the changes, It didn't make the form disappear this time for some reason, but it still has the same thing, and I changed that with the form, I changed it to send instead of submit, and changed the variable too, where should I put printr should I replace all my current print statements with it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Us</title>
</head>
<body>
<h3>Contact Us</h3>
<p><a href="index.php" title="Return Home">Return Home</a></p>
<p>If you need to contact us for any reason you can do so below.  We will try and respond within 24 hours.</p>
<br />
<?php
if (isset($_POST['send'])){
    if (empty($_POST['name'])){
    print('The name field has been left blank<br />');
    }if (empty($_POST['emailaddress'])){
    print('The Email Address field was left blank<br />');
    }if (empty($_POST['verifyemail'])){
    print('The Verify Email Field was left blank<br />');
    }if ($_POST['emailaddress'] != $_POST['verifyemail']){
    print('The Email Addresses do not match, please fix this<br />');
    }if (empty($_POST['description'])){
    print('The Description Field was left blank<br />');
    }}else {
    $to = "businessman332211@hotmail.com";
    $subject = "FunnyEmailForwards.com contact";
    $name = $_POST['name'];
    $emailaddress = $_POST['emailaddress'];
    $verifyemail = $_POST['verifyemail'];
    $description = $_POST['description'];
    $from = "$emailaddress";
    $message = "
    Name: {$name}
    Email Address: {$emailaddress}
    Verify Email: {$verifyemail}
    What the person had to say:
    {$description}
    ";
        if (mail($to, $subject, $message, $From)){
        print('Thank you for contacting us!<br />');
        print('We will try and get back to you within 24 hours.<br />');
        }else{
        print('There was an error sending the message, please try again!<br />');
        print('If it does not work the second time, please send an email directly to<br />');
        print('<a href="mailto:businessman332211@hotmail.com">Here</a>');
        }};
    
    
    
?>
<form name="contact" id="contact" action="contactus.php" method="post">
<label for="name">Name:</label><br />
<input name="name" id="name" type="text" maxlength="80" /><br />
<label for="emailaddress">Email Address:</label><br />
<input name="emailaddress" id="emailaddress" type="text" maxlength="80" /><br />
<label for="verifyemail">Verify Email Address:</label><br />
<input name="verifyemail" id="verifyemail" type="text" maxlength="80" /><br />
<label for="description">Message:</label><br />
<textarea name="description" id="description" cols="20" rows="7" />
</textarea><br />
<input name="send" id="send" type="submit" value="Contact Us!" />
<input name="reset" id="reset" type="reset" value="Clear Form" />
</form>
</body>
</html>

See I did decide a few things, on forms where I am doing databasing, or handling more than one submit button or more than one form, I always want to do it on another page. But when I have some basic contact form, or something simple, I like the idea of having it on the same page, I know all of this is subject to opinion, so I thought through all of this, the thing I don't get also is when it's on another page repopulating the form fields isn't an issue, so why does it clear it when it's on the same page, when it's a different page they hit back and they are still there, they fix the errors and boom, here what happens is it removes itself, how do I repopulate the form fields, and why does it work like that.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 05:49 PM

print_r($array_name) prints out the contents of an array. I wanted you to throw that in at the top so you can see what variables are actually in the $_POST array.

When you submit a form, all the current values will be in the $_POST array, so in your form you do something like this:

<input name="emailaddress" id="emailaddress" type="text" maxlength="80" value="<?=isset($_POST['emailaddress']) ? $_POST['emailaddress'] : ''?>" />

By the way, you have a double closing bracket before your else. If you move one of those to the end of the PHP block, I think that will fix your issues with having it send on the loading of the page.

Info: PHP Manual


#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 05:52 PM

Ok, I got in the repopulation, it repopulates now, what I need to figure out is why that message is still displaying and for some reason it's emailing it to me automatically at the open of the page. I am going to see if I can break down and understand the repopulation so I can do it later from memory, any advice on the other would be appreciated too, thanks so far, I need to learn the repopulation too.

I have to do that, or I get a parse error, it's because I have it wrapped in a bigger construct. The if at the top get's closed there, along with the end of the last if statement used in that segment.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 05:54 PM

Using 2 closing brackets there is going to end your main if which will send the script through the mailing process... HENCE WHAT IS HAPPENING.

You have to fix that. Tell us where you're getting the parse error.

Info: PHP Manual


#9 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 05:58 PM

Oh ok, that makes sense, I will redo it and tell you the parse area.
When I change it and take that out I get
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected $ in /home/all/funnyemailforwards/public_html/contactus.php on line 66
[/quote]
and that is on the line with nothing, for some reason that is way out all the way at the end of the document, pass the html, why is my php trying to read there?

Actually I got it working, What I did was added that at the end instead of where it was.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#10 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 05:59 PM

Which is what I told you to do. So is this solved?

Info: PHP Manual


#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 06:02 PM

A few other things happened.
That aren't working, for one I repopulated my text area field like you said but it's not repopulating, another thing is, how do I get it to remove the form when it submits all the way, or is it suppose to do that.

Just the bottom text area, teh one with description, and the form stays there for some reason, and let's you submit really rapidly.

I was also wondering, I figured out how to set the from address, but he wants the from field itself to say FunnyEmailForwards.com instead of an email address is this possible, to set a header as text instead of email, I tried but it doesn't register it, it still puts some wierd damon, at the website, whatever.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#12 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 06:08 PM

You need to use headers to set the from address. Look up the mail() function... it lays it out nicely.

And if you want to hide the form after the submit, all you have to do is build up an "error code" of some sort so that if it fails validation, it'll show the form, otherwise it won't.

Info: PHP Manual


#13 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 06:23 PM

How do I build up the error code, and the other question was, why is description not repopulating upon submit when it fails, it clears that one.
I do understand headers, I just tried it though and it ignored my work.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#14 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 06:27 PM

To build the error code, you're going to do something like this:
    
    $error_code = false;
    if (empty($_POST['name'])){
    $error_code = true;
    print('The name field has been left blank<br />');
    }if (empty($_POST['emailaddress'])){
    $error_code = true;
    print('The Email Address field was left blank<br />');
    }if (empty($_POST['verifyemail'])){
    $error_code = true;
    print('The Verify Email Field was left blank<br />');
    }if ($_POST['emailaddress'] != $_POST['verifyemail']){
    $error_code = true;
    print('The Email Addresses do not match, please fix this<br />');
    //etc
So then you just check that variable to see if it ran into an error or not.

I'm going to guess that your description block is a text area and you're trying to set a value. The text area doesn't have a value... you just have to echo the value between the open and closing tags (but that's just a guess... ).

As far as the from header... maybe you should show us your latest code (after you add the above parts).

Info: PHP Manual


#15 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 06:49 PM

Ok I have done 2 things.

First, is there a way to make the form disappear after submission other than that, I want to avoid getting into something so deep I don't understand it yet, I don't understand at all the functionality of the error code, I need to get this down I think before I dig into that, I tried doing adjustments to the from field, to set the header, and I tried a weak attempt at getting the text area to repopulate but they both failed, the email is still giving me this wierd email address of the domain manager, but I needed it to say FunnyEmailForwards.com, I have to get this to work because I talked him into using forms instead of mailto links. Also I need to get the field to populate itself but that didn't work.
The other thing is giving me an error here
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/all/funnyemailforwards/public_html/contactus.php on line 63
[/quote]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Us</title>
</head>
<body>
<h3>Contact Us</h3>
<p><a href="index.php" title="Return Home">Return Home</a></p>
<p>If you need to contact us for any reason you can do so below.  We will try and respond within 24 hours.</p>
<br />
<?php
if (isset($_POST['send'])){
    if (empty($_POST['name'])){
    print('The name field has been left blank<br />');
    }if (empty($_POST['emailaddress'])){
    print('The Email Address field was left blank<br />');
    }if (empty($_POST['verifyemail'])){
    print('The Verify Email Field was left blank<br />');
    }if ($_POST['emailaddress'] != $_POST['verifyemail']){
    print('The Email Addresses do not match, please fix this<br />');
    }if (empty($_POST['description'])){
    print('The Description Field was left blank<br />');
    }else {
    $to = "businessman332211@hotmail.com";
    $subject = "FunnyEmailForwards.com contact";
    $name = $_POST['name'];
    $emailaddress = $_POST['emailaddress'];
    $verifyemail = $_POST['verifyemail'];
    $description = $_POST['description'];
    $from = "FunnyEmailForwards.com Contact";
    $message = "
    Name: {$name}
    Email Address: {$emailaddress}
    Verify Email: {$verifyemail}
    What the person had to say:
    {$description}
    ";
        if (mail($to, $subject, $message, $From)){
        print('Thank you for contacting us!<br />');
        print('We will try and get back to you within 24 hours.<br />');
        }else{
        print('There was an error sending the message, please try again!<br />');
        print('If it does not work the second time, please send an email directly to<br />');
        print('<a href="mailto:businessman332211@hotmail.com">Here</a>');
        }}
        };
    
    
    
?>
<form name="contact" id="contact" action="contactus.php" method="post">
<label for="name">Name:</label><br />
<input name="name" id="name" type="text" maxlength="80" value="<?=isset($_POST['name']) ? $_POST['name'] : ''?>"/><br />
<label for="emailaddress">Email Address:</label><br />
<input name="emailaddress" id="emailaddress" type="text" maxlength="80" value="<?=isset($_POST['emailaddress']) ? $_POST['emailaddress'] : ''?>"/><br />
<label for="verifyemail">Verify Email Address:</label><br />
<input name="verifyemail" id="verifyemail" type="text" maxlength="80" value="<?=isset($_POST['verifyemail']) ? $_POST['verifyemail'] : ''?>"/><br />
<label for="description">Message:</label><br />
<textarea name="description" id="description" cols="20" rows="7" />
<?php 
if (isset($_POST['description'])){
echo("$_POST['description']");
}; ?>
</textarea><br />
<input name="send" id="send" type="submit" value="Contact Us!" />
<input name="reset" id="reset" type="reset" value="Clear Form" />
</form>
</body>
</html>


------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#16 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 06:56 PM

*sigh*... so much you have to learn about giving us enough info.

1) WHAT LINE IS 63?????
2) You can't hide the form without some kind of error code validation.
3) Is the text area filled in now?
4) You're still not using any headers. Did you read the manual entry for mail()???

Info: PHP Manual


#17 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 07:09 PM

Sorry about that, line 63 is
echo("$_POST['description']");

No it's still not displaying, and I had another suggestion about putting the form into an if-else statement, somehow and doing it that way is that possible, I will play around with and try to learn this error code thing, I am starting to think it's a better idea to do it on another page, is it easier that way.

The headers I was using was setting the header variable to what I needed and then putting it into the mail like this

Setting header
$from = "FunnyEmailForwards.com Contact";
Putting it into the mail function
if (mail($to, $subject, $message, $From)){
        print('Thank you for contacting us!<br />');
        print('We will try and get back to you within 24 hours.<br />');
        }else{
        print('There was an error sending the message, please try again!<br />');
        print('If it does not work the second time, please send an email directly to<br />');
        print('<a href="mailto:businessman332211@hotmail.com">Here</a>');
        }}
        };
and for some reason it's not changing it.

also I noticed lately when I go to the page, type something in the description area, it sends the email and validates it, as soon as something enters into the description it sends the email, everytime I do it in another page, it always worked first thing, but now it's giving me issues, but I guess I am learning from it.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#18 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 07:12 PM

[a href=\"http://us3.php.net/manual/en/function.mail.php\" target=\"_blank\"]http://us3.php.net/manual/en/function.mail.php[/a]

Look at the "how to send HTML emails part:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);[/quote]

Change:
if (isset($_POST['description'])){
echo("$_POST['description']");
}; ?>
To:
if (isset($_POST['description'])){
echo $_POST['description'];
} ?>
You don't need the parenthesis or the quotes when you're just echoing a variable (I never use the parenthesis otherwise either).

I also don't understand why you had a ";" after the if closing bracket. That's completely unnecessary.

This:
<?=isset($_POST['emailaddress']) ? $_POST['emailaddress'] : ''?>
may not work as intended. It's short-code and I always screw it up. You may want to break that out.
if(isset($_POST['emailaddress']))
echo $_POST['emailaddress'];
else
echo "";


Info: PHP Manual


#19 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 06 June 2006 - 07:21 PM

Ok, now I got the form field working, thanks the text-area works, and now I know how to do it, from now on should I ALWAYS leave off the parenthesis on echo, or echo and print, or what. I just need clarification for learning purposes.
It's also doing something funny, when you go to the site, if you type something in description and click submit it submits it automatically.
You can fill out the others, and click it it gives you error messages, but no matter what when you fill out description and click submit, it displays the message it is suppose to for confirmation, sends an email, and still validates and shows up the error messages, I am confused as to why this is happening, I didn't notice it until now.
and at the part where you showed me to change those over to the longer forms, I tried that but it didn't work, can you show me an example in a form field.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#20 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 07:30 PM

Try it like this:
<?php
$email = "";
if(isset($_POST['emailaddress']))
    $email =  $_POST['emailaddress'];
?>
<input name="emailaddress" id="emailaddress" type="text" maxlength="80" value="<?=$email?>"/><br />

The reason it's doing that is because you have no way of checking to see if any of the other validations have failed. That's where the error code comes into play.

Right now your code says this:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]if email is blank show error
if name is blank show error
if description is blank show error but if it's not go ahead and send the email.[/quote]

As it is, your "else" statement is only tied to the description.

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users