Jump to content

Sending a simple form?!


wednesdayaddams

Recommended Posts

Ok so I have created a form in DW.

The action is targeted to this PHP script (see below)

However, it doesn't display the message or name?! Just sends a blank email...

 

Any help really appreciated for a frustrated newbie,

 

Thankyou :)

 

<?php

 

$HTTP_POST_VARS. */

$subject = $HTTP_POST_VARS['subject'];

$message = $HTTP_POST_VARS['message'];

$email = 'myemail@thatwebsite.com';

 

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {

  echo "<h4>Invalid email address</h4>";

  echo "<a href='javascript:history.back(1);'>Back</a>";

}

 

elseif (mail($email,$subject,$message)) {

  echo "<h4>Thank you for sending email</h4>";

} else {

  echo "<h4>Can't send email to $email</h4>";

}

?>

 

 

 

 

Link to comment
Share on other sites

Besides the fact that $HTTP_POST_VARS has long been deprticated in favour of a simple $_POST array, the very first line....

 

$HTTP_POST_VARS. */

 

will cause a parse error in your code. Why is it there?

Link to comment
Share on other sites

So I changed the code to below... But still recieving blanks messages (with no content from name or subject input boxes)

 

I really do appreciate your help and hasty responses guys :)

 

<?php

/*$_POST */
$subject = $_POST['subject'];
$message = $_POST['message'];
$email = 'myemail@mywebsite.com';

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

elseif (mail($email,$subject,$message)) {
  echo "<h4>Thank you for sending email</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>

 

ps- Please excuse my stupidity!!!

Link to comment
Share on other sites

try put in these 2 lines after /* $_POST */

 

print_r($_POST);

exit();

 

this will let you see what is being posted and see if your message/subject is being posted....

 

can you post the response you get from this? and your FORM HTML.

 

 

Link to comment
Share on other sites

Ok, now when I click submit I get this...

 

Array ( [name] => myname [comment] => comment => venus200013@yahoo.com [submit] => Submit )

 

The code for the table is as follows (its probably wrong!)- I made it inserting fields in DW (which was the easy bit!)...

 

<form action="send.php" method="post" enctype="application/x-www-form-urlencoded" name="contact form" id="contact form">
                <p align="left" class="form">Your name                  </p>
                <p align="left">
                  <input name="subject" type="text" class="formtext" id="subject" size="40" maxlength="50" />
                </p>
                <p align="left" class="form">Your comments or query</p>
                <p align="left">
                  <textarea name="message" cols="40" rows="10" class="formtext" id="message"></textarea>
</p>
                <p align="left" class="form">Your email address </p>
                <p align="left" class="form">
                  <input name="email" type="text" class="formtext" id="email" size="40" maxlength="50" />
                </p>
                <p align="left" class="form">
                  <input name="Submit" type="submit" class="form" id="Submit" value="Submit" />
                </p>
                <p class="form"> </p>
                </form>  

 

 

Link to comment
Share on other sites

Array ( [name] => myname [comment] => comment => venus200013@yahoo.com [submit] => Submit )

 

you wrote myname in the name field nad comment in the comment field, yes?

did you type anything in the subject field?

 

*** just noticed after i typed all the stuff below this... ***

an input with the name "comment" is being posted... and the comment field in your form is named "message"....

is the HTML FORM you wrote the right one?

is send.php in the same directory as the form HTML file?

and the contents of send.php is that of the PHP code you've been posting, yeah?

 

also, you have no "name" field in the html form... it says name but its being sent as "subject"...

i fixed up the php/html for you...

 

<form action="send.php" method="post" enctype="application/x-www-form-urlencoded" name="contactForm" id="contactForm">
                <p align="left" class="form">Your name</p>
                <p align="left">
                  <input name="userName" type="text" class="formtext" id="userName" size="40" maxlength="50" />
                </p>
                <p align="left" class="form">Your email address </p>
                <p align="left" class="form">
                  <input name="email" type="text" class="formtext" id="email" size="40" maxlength="50" />
                </p>
                <p align="left" class="form">Subject</p>
                <p align="left">
                  <input name="subject" type="text" class="formtext" id="subject" size="40" maxlength="50" />
                </p>
                <p align="left" class="form">Your comments or query</p>
                <p align="left">
                  <textarea name="message" cols="40" rows="10" class="formtext" id="message"></textarea>
</p>
                <p align="left" class="form">
                  <input name="Submit" type="submit" class="form" id="Submit" value="Submit" />
                </p>
                <p class="form"> </p>
                </form> 

 

 

 

<?php

/*$_POST */
$subject = $_POST['subject'];
$userMessage = $_POST['message'];
$userName = $_POST['userName'];
$userEmail = $_POST['email'];
$email = 'myemail@mywebsite.com';

$message = "Email sent from $userName \n
Reply: $userEmail \n
Subject: $subject \n
Message: $userMessage";

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

elseif (mail($email,$subject,$message)) {
  echo "<h4>Thank you for sending email</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>

 

 

Link to comment
Share on other sites

Ok, I named the comment box 'message' as I didnt think this would make a difference- as long as the php pointed to 'message'?

 

The HTML form is the right one, the only form I have made.

Yes, the php file is in the same directory as the html form file.

And yes the contents of send.php is the code I have been posting.

 

I don't actually need the subject box, I only need the users name, email and comments and when they click 'submit' it comes to my email.

 

I think the name field was named subject as I was trying to follow the tutorial as closely as possible and thats what they used.

 

Still not working!

 

Now I am not recieving any email at all (and yes I changed the 'myemail@mywebsite' address in the php code to mine)

 

Thankyou for your help, Im sure you are going to become as frustrated as I am soon!!!

 

Thanks again :)

Link to comment
Share on other sites

... might be a silly question, but did you remember to change the

$email = 'myemail@mywebsite.com';

line to your email in the code i posted?

 

if you didn't, change it and try it again..

otherwise try this code and tell me what gets displayed...

 

I've made the subject always "New message from site"... you can change this to whatever you want.

 

<?php

/*$_POST */
$subject = 'New message from site';
$userMessage = $_POST['message'];
$userName = $_POST['userName'];
$userEmail = $_POST['email'];
$email = 'myemail@mywebsite.com';

$message = "Email sent from $userName \n
Reply: $userEmail \n
Message: $userMessage";

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

echo "Subject: $subject<br/>
User Name: $userName<br/>
Posted Message: $userMessage<br/>
Email Message: $message<br/><br/>
To email: $email";
exit();

elseif (mail($email,$subject,$message)) {
  echo "<h4>Thank you for sending email</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>

 

HTML

 

<form action="send.php" method="post" enctype="application/x-www-form-urlencoded" name="contactForm" id="contactForm">
                <p align="left" class="form">Your name</p>
                <p align="left">
                  <input name="userName" type="text" class="formtext" id="userName" size="40" maxlength="50" />
                </p>
                <p align="left" class="form">Your email address </p>
                <p align="left" class="form">
                  <input name="email" type="text" class="formtext" id="email" size="40" maxlength="50" />
                </p>
                <p align="left" class="form">Your comments or query</p>
                <p align="left">
                  <textarea name="message" cols="40" rows="10" class="formtext" id="message"></textarea>
</p>
                <p align="left" class="form">
                  <input name="Submit" type="submit" class="form" id="Submit" value="Submit" />
                </p>
                <p class="form"> </p>
                </form> 

Link to comment
Share on other sites

>:(

 

Yes I changed the email to my email address, that was the first thing I checked.

 

Tried that code above, same thing, uploaded the html and php files, tested it and when you click 'submit' it just takes you to a blank page and Im not recieving any email!

 

Thankyou so much for helping me, Im not expecting you to solve this, its getting silly now!

Link to comment
Share on other sites

the if logic is wrong

 

try this

 

<?php
error_reporting(E_ALL);
/*$_POST */
$subject = 'New message from site';
$userMessage = $_POST['message'];
$userName = $_POST['userName'];
$userEmail = $_POST['email'];
$email = 'myemail@mywebsite.com';

$message = "Email sent from $userName \n
Reply: $userEmail \n
Message: $userMessage";

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}elseif(mail($email,$subject,$message)) {
echo "Subject: $subject<br/>
User Name: $userName<br/>
Posted Message: $userMessage<br/>
Email Message: $message<br/><br/>
To email: $email";
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>

Link to comment
Share on other sites

okay,

i just uploaded it on my site and it worked?

 

i got rid of my debugging lines (i put them in the wrong spot anyway, didn't notice you had an elseif there):

echo "Subject: $subject<br/>

User Name: $userName<br/>

Posted Message: $userMessage<br/>

Email Message: $message<br/><br/>

To email: $email";

exit();

 

this is the code as is on my server, minus the yourEmail@yourdomain.com thingo...

 

<?php

/*$_POST */
$subject = 'New message from site';
$userMessage = $_POST['message'];
$userName = $_POST['userName'];
$userEmail = $_POST['email'];
$email = 'yourEmail@yourdomain.com';

$message = "Email sent from $userName \n
Reply: $userEmail \n
Message: $userMessage";

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

elseif (mail($email,$subject,$message)) {
  echo "<h4>Thank you for sending email</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>

Link to comment
Share on other sites

if that doesn't work, put in the following lines

 

ini_set ("display_errors", "1");

error_reporting(E_ALL);

 

at the very top of the code.. the line after <?php

 

and try and run the program and tell me exactly what happens? does it say Thank you for sending email etc?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.