Jump to content

Recommended Posts

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

right, you should only see the output from var dump after the form has submitted.try this.

<php var_dump($_POST);if (isset($_POST['email'])){  //if "email" is filled out, send email  $to = 'mymail@yahoo.com';  $email = $_POST['email'];  $subject = "Subject: " . $_POST['subject'];  $message = 'Name: ' . $_POST['first'] . '   ' . $_POST['last'];  $message .= $_POST['message'];  $header = 'From: ' . $email;  mail( $to, $subject, $message, $header);  echo "Thank you for using our mail form";}else{  //if "email" is not filled out, display the form  echo "<form method='post' action='index.php'>  First Name: <input name='first' type='text' /><br />    Last Name: <input name='last' type='text' /><br/>  Email: <input name='email' type='text' /><br />  Subject: <input name='subject' type='text' /><br />  Message:<br />  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' />  </form>";}?>

edit: so it appears it's not the form that's issue, it's you getting the email. How are you testing this? mail needs a mail server (SMTP) to work. Are you testing locally? If so you would need to setup your AMP stack accordingly. Let us know your environment and then we can help you out.

Edited by thescientist
Link to post
Share on other sites

I'm getting the same problem with "array". I think the problem is with the "var_dump($_POST);" because when I submit it shows:array(5) { ["first"]=> string(13) "my first name" ["last"]=> string(12) "my last name" ["email"]=> string(17) "myemail@yahoo.com" ["subject"]=> string(12) "just testing" ["message"]=> string(21) "this is a simple test" } Thank you for using our mail formAnd in the form (before submitting it), it shows array(0) { }

Edited by Dark Knight
Link to post
Share on other sites

This revised code works for me..

<html><body><?phpif (isset($_POST['email']))//if "email" is filled out, send email  {  //send email  $to = "mymailaddress@yahoo.com";  $email = $_POST['email'];  $subject = $_POST['subject'];  $message = "<u>From:</u> " . $_POST['first'] . " " . $_POST['last'] . "<br />" . "<u>Message:</u> " . $_POST['message'];  mail( $to, "Subject: $subject", $message, "From: $email");  echo "<br /><br />Thank you for using our mail form";  }else//if "email" is not filled out, display the form  {  echo "<form method='post' action='index.php'>  First Name: <input name='first' type='text' /><br />  Last Name: <input name='last' type='text' /><br/>  Email: <input name='email' type='text' /><br />  Subject: <input name='subject' type='text' /><br />  Message:<br />  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' />  </form>";  }?></body></html>

Link to post
Share on other sites
I'm getting the same problem with "array". I think the problem is with the "var_dump($_POST);" because when I submit it shows:array(5) { ["first"]=> string(13) "my first name" ["last"]=> string(12) "my last name" ["email"]=> string(17) "myemail@yahoo.com" ["subject"]=> string(12) "just testing" ["message"]=> string(21) "this is a simple test" } Thank you for using our mail formAnd in the form (before submitting it), it shows array(0) { }
That is exactly what is supposed to happen. Before submitting the form, $_POST will be an empty array (as you found out) and only after submitting the form will the $_POST array contain information (which it is). So you've confirmed that all the values are indeed being submitted to PHP. You can remove the var_dump line now since it was only used for debugging.The issue now, as I understand it, is that you are not getting the email. But as scientist said, you cannot send any email without an email server.
Link to post
Share on other sites
I'm getting the same problem with "array". I think the problem is with the "var_dump($_POST);" because when I submit it shows:array(5) { ["first"]=> string(13) "my first name" ["last"]=> string(12) "my last name" ["email"]=> string(17) "myemail@yahoo.com" ["subject"]=> string(12) "just testing" ["message"]=> string(21) "this is a simple test" } Thank you for using our mail formAnd in the form (before submitting it), it shows array(0) { }
Didn't you read my last post? I've already explained to you that's what you expect. There's no problem with the array. Until you submit the form, there's nothing in it. That's what $_POST is, an array. and until the page submits, there's nothing in it. That's why it doesn't show until you submit the form.I thought we got to the point where you were getting the success message, but you just weren't receiving the email What about my questions about how you are testing this? Locally? Live?
Link to post
Share on other sites

if you put the line

phpinfo()

at the beginning of your code somewhere, it should output you all information about the current installation of PHP on the machine. You should be able to use CTR+F to search for SMTP and tell us what the value of it is.http://php.net/manual/en/function.phpinfo.php

Edited by thescientist
Link to post
Share on other sites

Just load a page that just has this

<?phpphpinfo();?>

don't you want to know if you even have a mail server or not? This is the nature of all programming: debugging. Get used to it now.

Link to post
Share on other sites

also, a more preferable way of testing PHP is to do it locally, so you don't have to keep uploading your work to a host each time you want to try something. Look up WAMP or MAMP if you are working on windows or mac, respectively.

Link to post
Share on other sites
Just load a page that just has this
<?phpphpinfo();?>

don't you want to know if you even have a mail server or not? This is the nature of all programming: debugging. Get used to it now.

It has because I've tested a long time ago. I can ensure you.Okei, I've add this and on my page I see some tables. What should I check?
Link to post
Share on other sites

well, I guess the last thing we can ask for now is to what the latest version of your code is and start working with that. Include the form, the mail script, and the output of var_dump after you submit the form.

Link to post
Share on other sites
well, I guess the last thing we can ask for now is to what the latest version of your code is and start working with that. Include the form, the mail script, and the output of var_dump after you submit the form.
<html><body><?phpif (isset($_POST['email']))//if "email" is filled out, send email  {  //send email  $to = "mymail@yahoo.com";  $email = $_POST['email'];  $subject = $_POST['subject'];  $message = "<u>From:</u> " . $_POST['first'] . " " . $_POST['last'] . "<br />" . "<u>Message:</u> " . $_POST['message'];  mail( $to, "Subject: $subject", $message, "From: $email");  echo "<br /><br />Thank you for using our mail form";  }else//if "email" is not filled out, display the form  {  echo "<form method='post' action='index.php'>  First Name: <input name='first' type='text' /><br />  Last Name: <input name='last' type='text' /><br/>  Email: <input name='email' type='text' /><br />  Subject: <input name='subject' type='text' /><br />  Message:<br />  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' />  </form>";  }?></body></html>

Like above?

Link to post
Share on other sites
You mean like this?
<?php var_dump

yes...like you've already done....
var_dump($_POST)

Edited by thescientist
Link to post
Share on other sites
stupid question: your using a real email address, and the one you're posting is different, right?
Yes I'm using my own email address.About the var thing, I'm getting a error Parse error: syntax error, unexpected T_IF on line 5
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...