Sinisterly
[HELP] Website Functions! - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Design (https://sinister.ly/Forum-Design)
+--- Forum: Web Design (https://sinister.ly/Forum-Web-Design)
+--- Thread: [HELP] Website Functions! (/Thread-HELP-Website-Functions)

Pages: 1 2 3 4


RE: [HELP] Website Functions! - Eclipse - 12-15-2013

[Image: 635111b0ff02f69fd9f5a56a1ae8aa4a.png]

It doesn't seem to work.


RE: [HELP] Website Functions! - Anizeb - 12-15-2013

There are a number of things wrong here.

Code:
<td><input type="text" name="email"></td>
and
Code:
<td><textarea type="text" name="message">

are the two things you need to snatch from the orm you've got. You should also include a subject field, or a name one as CamIce seems to have implied. (I've done so below)

So what you want (combining both you and CamIce's code) would be
Code:
<form method="post" name="contact" id="contact"> <table> <tr> <td>Your Email Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Subject</td> <td><textarea type="text" name="subject"></textarea></td> </tr> <tr> <td>Your Message</td> <td><textarea type="text" name="message"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form>


Code:
<?php $mail = $_POST['email']; $to = 'cbc-chat@hotmail.com'; $subject = 'Contact Form:' . $_POST['subject']; $message = $_POST['message']; $headers = 'From: ' . $mail . "\r\n" . 'Reply-To: ' . $mail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?>

Untested, and it's been ages since I've used PHP, so I may have fucked up. Sorry in advance, if that's the case.


RE: [HELP] Website Functions! - Eclipse - 12-15-2013

(12-15-2013, 07:02 PM)Anizeb Wrote: There are a number of things wrong here.

Code:
<td><input type="text" name="email"></td>
and
Code:
<td><textarea type="text" name="message">

are the two things you need to snatch from the orm you've got. You should also include a subject field, or a name one as CamIce seems to have implied. (I've done so below)

So what you want (combining both you and CamIce's code) would be
Code:
<form method="post" name="contact" id="contact"> <table> <tr> <td>Your Email Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Subject</td> <td><textarea type="text" name="subject"></textarea></td> </tr> <tr> <td>Your Message</td> <td><textarea type="text" name="message"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form>


Code:
<?php $mail = $_POST['email']; $to = 'cbc-chat@hotmail.com'; $subject = 'Contact Form:' . $_POST['subject']; $message = $_POST['message']; $headers = 'From: ' . $mail . "\r\n" . 'Reply-To: ' . $mail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?>

Untested, and it's been ages since I've used PHP, so I may have fucked up. Sorry in advance, if that's the case.

Thanks! I'll try it now and post results.

EDIT:

Hmm, it seems some of the fields don't link.


RE: [HELP] Website Functions! - Anizeb - 12-15-2013

Have you moved the PHP to another page?
Makes things easier.

Code:
<form method="post" name="contact" id="contact" action="send.php"> <table> <tr> <td>Your Email Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Subject</td> <td><textarea type="text" name="subject"></textarea></td> </tr> <tr> <td>Your Message</td> <td><textarea type="text" name="message"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form>

and you now add the PHP to a file called "send.php"


Only mentioning this because your form originally submitted to itself, and I didn't know if you set up the page right.


RE: [HELP] Website Functions! - Eclipse - 12-15-2013

(12-15-2013, 07:26 PM)Anizeb Wrote: Have you moved the PHP to another page?
Makes things easier.

Code:
<form method="post" name="contact" id="contact" action="send.php"> <table> <tr> <td>Your Email Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Subject</td> <td><textarea type="text" name="subject"></textarea></td> </tr> <tr> <td>Your Message</td> <td><textarea type="text" name="message"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form>

and you now add the PHP to a file called "send.php"


Only mentioning this because your form originally submitted to itself, and I didn't know if you set up the page right.

Yeah the php is already in another file. What I mean was that for example, the form name, in the php is says 'email' but in the html, it's 'contact'. Shall I change this?

html:
Code:
<form action="email.php" method="post" name="contact" id="contact"> <table> <tr> <td>Your Email Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Subject</td> <td><textarea type="text" name="subject"></textarea></td> </tr> <tr> <td>Your Message</td> <td><textarea type="text" name="message"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form>

PHP
Code:
<?php $mail = $_POST['email']; $to = 'cbc-chat@hotmail.com'; $subject = 'Contact Form:' . $_POST['subject']; $message = $_POST['message']; $headers = 'From: ' . $mail . "\r\n" . 'Reply-To: ' . $mail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?>



RE: [HELP] Website Functions! - Anizeb - 12-15-2013

OH, I see. Also, I've tested it, and it works as intended.

"contact" is the name of the form, and that's irrelevant.
You need the field names, not the form name,

What exactly is the behavior you're looking for, if that code isn't what you need?
Because it does grab from POST just fine.


RE: [HELP] Website Functions! - Eclipse - 12-15-2013

(12-15-2013, 07:35 PM)Anizeb Wrote: OH, I see. Also, I've tested it, and it works as intended.

"contact" is the name of the form, and that's irrelevant.
You need the field names, not the form name,

What exactly is the behavior you're looking for, if that code isn't what you need?
Because it does grab from POST just fine.


(12-15-2013, 07:35 PM)Anizeb Wrote: OH, I see. Also, I've tested it, and it works as intended.

"contact" is the name of the form, and that's irrelevant.
You need the field names, not the form name,

What exactly is the behavior you're looking for, if that code isn't what you need?
Because it does grab from POST just fine.

The thing is, I don't get an email. [Image: c43b97f754cd80aebb266143ed368183.png]

I'm using this code:

Code:
<?php $field_name = $_POST['cf_name']; $field_email = $_POST['cf_email']; $field_message = $_POST['cf_message']; $mail_to = 'cbc-chat@hotmail.com'; $subject = 'Message from a site visitor '.$field_name; $body_message = 'From: '.$field_name."\n"; $body_message .= 'E-mail: '.$field_email."\n"; $body_message .= 'Message: '.$field_message; $headers = 'From: '.$field_email."\r\n"; $headers .= 'Reply-To: '.$field_email."\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for the message. We will contact you shortly.'); window.location = 'contact.html'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Message failed. Please, send an email to cbc-chat@hotmail.com'); window.location = 'contact.html'; </script> <?php } ?>

I always get the error message on my site.

For the subscribe function, how do I construct the form to make sure that the php works?


RE: [HELP] Website Functions! - Anizeb - 12-15-2013

This is the (near) exact code I've used:

mail.htm
Code:
<form method="post" name="contact" id="contact" action="send.php"> <table> <tr> <td>Your Email Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Subject</td> <td><textarea type="text" name="subject"></textarea></td> </tr> <tr> <td>Your Message</td> <td><textarea type="text" name="message"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form>

send.php
Code:
<?php $mail = $_POST['email']; $to = '[CENSORED]'; $subject = 'Contact Form:' . $_POST['subject']; $message = $_POST['message']; $headers = 'From: ' . $mail . "\r\n" . 'Reply-To: ' . $mail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); echo $to . " " . $subject . " " . $message . " " . $headers; ?>

and that is functional, and sending me emails. Obviously, I've removed mine, but it's a LIVE.com email, so if it works there, it should work for you.

For you, I imagine your if-else might be an issue. Either that, or you forgot to rename the fields in your form to match the PHP.
Stick with something simple like mine, and work SLOWLY towards what you want.

Also, this WILL end up in your spam folder, so make sure you check out that it's not an issue with that.

Edit;
Your code works fine, as long as the field names match.
It's also possible that your server has disallowed mailing for some reason, but I'm leaning towards the field thing, considering you seem to have a little trouble understanding how to properly use POST.


RE: [HELP] Website Functions! - Eclipse - 12-15-2013

(12-15-2013, 08:05 PM)Anizeb Wrote: This is the (near) exact code I've used:

mail.htm
Code:
<form method="post" name="contact" id="contact" action="send.php"> <table> <tr> <td>Your Email Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Subject</td> <td><textarea type="text" name="subject"></textarea></td> </tr> <tr> <td>Your Message</td> <td><textarea type="text" name="message"></textarea></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form>

send.php
Code:
<?php $mail = $_POST['email']; $to = '[CENSORED]'; $subject = 'Contact Form:' . $_POST['subject']; $message = $_POST['message']; $headers = 'From: ' . $mail . "\r\n" . 'Reply-To: ' . $mail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); echo $to . " " . $subject . " " . $message . " " . $headers; ?>

and that is functional, and sending me emails. Obviously, I've removed mine, but it's a LIVE.com email, so if it works there, it should work for you.

For you, I imagine your if-else might be an issue. Either that, or you forgot to rename the fields in your form to match the PHP.
Stick with something simple like mine, and work SLOWLY towards what you want.

Also, this WILL end up in your spam folder, so make sure you check out that it's not an issue with that.

Edit;
Your code works fine, as long as the field names match.
It's also possible that your server has disallowed mailing for some reason, but I'm leaning towards the field thing, considering you seem to have a little trouble understanding how to properly use POST.

My fields are fine. It's most likely the host. Fuck it. I'll think of another solution. The good news is, CamIce's code for the subscribe feature works fine. The only thing I need now is javascript validation to check if it's a legitimate email. I'm not sure how to check if that email is already in the file though.

(I had a small misunderstanding with Post but I assure you, I understand.)


RE: [HELP] Website Functions! - Anizeb - 12-15-2013

Sorry if I offended you, was just offering ideas since the code is working fine for me.

As for checking if an email was used, you can use regex to see if there's a match in the file.
Not so sure about validation, though.