# Email Button HTML



## mariusmeeren (Aug 4, 2016)

*Hello,*
I've been looking around for ages for a page like this that i can ask questions and fix my html problems,
Now my *problem *is that i've made a email button, but it doesn't work at all. http://www.nightlightrp.esy.es/contact Is where the form is located, now i am filling in all of my information, but it doesn't work. 
*HTML Code:
*​

Night Light Contact Form


http://nightlightrp.esy.es
Forums
Servers
Rules
Contact us

*Problem is here:










Expect an answer within 56 hours

Submit <--- BUTTON IS HERE

*
​


----------



## mariusmeeren (Aug 4, 2016)

*Problem is here:










Expect an answer within 56 hours

Submit <--- BUTTON IS HERE

*


----------



## JiminSA (Dec 15, 2011)

Hi Marius - welcome to TSG
The way you are set up would normally invoke your visitor's email handler to send a messy message
unfortunately your Host - Hostinger - interprets the action="mailto .." as a page request and throws a 403 (page forbidden).
It would (IMHO) be better to change your action to a php script which would process a mailto properly.
Take a gander at this tut. Hopefully it will help. If not come back to us


----------



## mariusmeeren (Aug 4, 2016)

That page is really confusing and i don't understand it sorry. Is there an easier tutorial? For me that is just alot of text talking about files i don't have and all that. Could you possible make it? Sorry for begging and stuff but i just need it to work. I only know html


----------



## mariusmeeren (Aug 4, 2016)

Here, imma just send you the file, because i have NO CLUE on php or idk what it even is, and it's just WAY too confusing.


----------



## JiminSA (Dec 15, 2011)

Change your form to look like this

```
[IMG]http://i.imgur.com/64wGS5P.png[/IMG]

Expect an answer within 48 hours

Submit
```
... then save this as contact.php

```
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
    $fname = $_POST['fname'];
    $email = $_POST['email'];
    $phone = $_POST['phonel'];
    $msg = $_POST['msg'];
    $to = "EMAIL ADDRESS OF RECIPIENT";
    $subject = "A SUITABLE SUBJECT TEXT";
    $headers = "From: [email protected] \r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    $body = "<table style=\"background-color: #E7E7E7;\" cellpadding=\"10\">
    [TR][TD]Marius,[/TD][/TR]
    [TR][TD]You've had a visitor. Their email address is $email ...[/TD][/TR]
    [TR][TD]Their phone number is $phone ...[/TD]/tr>
    [TR][TD]Their message is ... $msg[/TD]/tr>
    [TR][TD]Regards,[/TD][/TR]
    [TR][TD]Your Site[/TD][/TR][/TABLE]";

    mail($to, $subject, $body, $headers);
}
    header("Location: index.php"); /* Go back ... */
?>
```
BE WARNED, Marius, this written off the top of my head UNTESTED!


----------



## mariusmeeren (Aug 4, 2016)

The email doesn't come to my gmail idk why? I filled in my email @ 
$to = "[email protected]";
$subject = "Contact Form";


----------



## JiminSA (Dec 15, 2011)

Did you spot my bad? The name="phone" and $phone = $_POST['phonel']; don't match


----------



## mariusmeeren (Aug 4, 2016)

Yeah i saw it now, i filled in my details hit submit, but i ain't getting no mail


----------



## mariusmeeren (Aug 4, 2016)

http://www.nightlightrp.esy.es/contact

Contact.php:
<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
$to = "[email protected]";
$subject = "Contact Form";
$headers = "From: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$body = "<table style=\"background-color: #E7E7E7;\" cellpadding=\"10\">
[TR][TD]Marius,[/TD][/TR]
[TR][TD]You've had a visitor. Their email address is $email ...[/TD][/TR]
[TR][TD]Their phone number is $phone ...[/TD]/tr>
[TR][TD]Their message is ... $msg[/TD]/tr>
[TR][TD]Regards,[/TD][/TR]
[TR][TD]Your Site[/TD][/TR][/TABLE]";

mail($to, $subject, $body, $headers);
}
header("Location: mailsent"); /* Go back ... */
?>

contact.contact:

Night Light Contact Form


http://nightlightrp.esy.es
Forums
Servers
Rules
Contact us










Expect an answer within 48 hours

Submit


----------



## JiminSA (Dec 15, 2011)

The following bit of code will throw a php error ...

```
header("Location: mailsent"); /* Go back ... */
```
... because it expects the text after "Location:" to be either an html or php file. I'm not quite sure how "mailsent" fits in??


----------



## mariusmeeren (Aug 4, 2016)

Oh no no, Thats not a problem. What that does, is when you hit submit, it takes you to http://www.nightlightrp.esy.es/*mailsent *page

The reason why i ain't calling it .html or .htm is because it will look ugly in the browser tab. lol. I want to to look clean. And yes, it does work, i sends you to that page.


----------



## JiminSA (Dec 15, 2011)

I have learned something from this at least - .html/.php etc., is not necessary - hadn't realised that before
As to why it's not mailing, perhaps you should talk to your hosts - maybe we are not conforming to their requirements?
Another thing - look at your Spam Filters on your email handler - perhaps it's getting blocked?


----------



## mariusmeeren (Aug 4, 2016)

I will take contact with hostinger as soon as possible  

And no, it's not in my spam filter.


----------



## mariusmeeren (Aug 4, 2016)

Hello! It has worked, but i ****ed it up again trying to make it alot better and i am coming back to you if you CAN PLEASE IN THE WORLD HELP ME!

What i want to recieve in my email is this thing right here: https://gyazo.com/24955f07ed51ff955efe765fa7d42861

With all the details. I want it to send that html form with the details in it, that would look so much better and easier to read. Can you help me or no?


----------



## JiminSA (Dec 15, 2011)

I shall try But first, could you explain how you got the email sent?


----------



## JiminSA (Dec 15, 2011)

One can indeed send a web page in an email, simply by including the script as the $body variable in this particular example I constructed for you.
You do that in php by assigning the web page content to the $body variable. A simple statement

```
$body = '<!DOCTYPE html>Gyazo - 24955f07ed51ff955efe765fa7d42861.png ...'
```
 etcetera, to the document's end (copy/paste).
Simple hey?
Not so Especial care has to be taken when dealing with (in this case) single quotes (because I started the variable assignment with one).
Every single quote in the webpage script has to be preceded by an escape character \ (backslash) to stop php from closing the assignment and enable continuation to the end of the script ... I hope you have the patience to do this - AFAIK it's the only way to do it!
But maybe someone has an easier method??


----------



## mariusmeeren (Aug 4, 2016)

I just contacted hostinger and they created a testmail.php in my public_html folder, and that worked, here is the file i am currently using and that sends like a "Kinda Working" form, But it doesn't give any of the details in the boxes, i've tried putting in $fnam $email $phone & $msg but nothing of that appears. Here is the .php file


----------



## mariusmeeren (Aug 4, 2016)

Sorry the file didn't upload in the last comment. here it is


----------



## JiminSA (Dec 15, 2011)

Rather use the code icon- 4th in from the right, than a zipped file - it makes reading the thread easier ...


----------



## JiminSA (Dec 15, 2011)

mariusmeeren said:


> i've tried putting in $fnam $email $phone & $msg but nothing of that appears.


You need to put each variable in to the input elements like so ...

```
>
```


----------



## colinsp (Sep 5, 2007)

Also don't forget some people have HTML turned off in their email programmes so you need to ensure they can read your email properly too.


----------



## mariusmeeren (Aug 4, 2016)

JiminSA said:


> You need to put each variable in to the input elements like so ...
> 
> ```
> >
> ```


Now it doesn't even send the email to me
CODE:










Expect an answer within 48 hours

>

>

>

>


----------



## JiminSA (Dec 15, 2011)

This was the content of your zip file ...

```
<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
    $fname = $_POST['fname'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $msg = $_POST['msg'];
    $to = "[email protected]";
    $subject = "Contact Form";
    $headers = "From: [email protected] \r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $to  = '[email protected]';
    $subject = 'Contact Form';

    // 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";

    // Put your HTML here
    $message = '

    [IMG]http://i.imgur.com/64wGS5P.png[/IMG]

Expect an answer within 48 hours

    ';

    // Mail it
    mail($to, $subject, $message, $headers);
}
header("Location: mailsent"); /* Go back ... */
?>
```
 and it's here that you must put the value="<?=$fname?>" goodies. You appear to have placed them in the form you are submitting Submission fails because the variables don't exist at that stage.


----------



## mariusmeeren (Aug 4, 2016)

Where???? You just said It's here you place them? I ain't php expert. Where here? or have you placed them?


----------



## JiminSA (Dec 15, 2011)

Hey, I'm not blaming you or laughing at you, I'm trying to help you. My bad I didn't explain that you should put the "echo statements" (that's what they are) into the message body and not the form. But there's nothing achieved by getting all sensitive and defensive ...


----------



## mariusmeeren (Aug 4, 2016)

What??? I ain't getting defensive or sensetive. I was just asking


----------



## mariusmeeren (Aug 4, 2016)

<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
$to = "[email protected]";
$subject = "Contact Form";
$headers = "From: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to = '[email protected]';
$subject = 'Contact Form';

// 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";

// Put your HTML here
$message = '










Expect an answer within 48 hours

[TR][TD]$fname[/TD][/TR]

[TR][TD]$email[/TD][/TR]

[TR][TD]$phone[/TD][/TR]

[TR][TD]$msg[/TD][/TR]

';

// Mail it
mail($to, $subject, $message, $headers);
}
header("Location: mailsent"); /* Go back ... */
?>

I have put in the $fname $email $phone $msg but in the email it just displays $fname $email $phone $msg


----------



## JiminSA (Dec 15, 2011)

mariusmeeren said:


> it just displays $fname $email $phone $msg


That's because you didn't 'echo' the variables -


JiminSA said:


> and it's here that you must put the value="<?=$fname?>" goodies.


HTML doesn't recognise PHP variables (it just treats them as text), so you have to inject them using PHP code

```
[TR][TD]<?=$fname?>[/TD][/TR]

[TR][TD]<?=$email?>[/TD][/TR]

[TR][TD]<?=$phone?>[/TD][/TR]

[TR][TD]<?=$msg?>[/TD][/TR]
```
Did you change your mind about using the form in your email message?


----------



## mariusmeeren (Aug 4, 2016)

No i really want the entire form with the cool design in the email itself. Maybe not the background (Might be too much) But the nice looking form would be amazing. Much easier to read


----------



## mariusmeeren (Aug 4, 2016)

JiminSA said:


> That's because you didn't 'echo' the variables -
> HTML doesn't recognise PHP variables (it just treats them as text), so you have to inject them using PHP code
> 
> ```
> ...


Also it didn't work. It sends it to my email, but it's just empty: Like so: https://gyazo.com/90697f99f3f8c43fa6ade9a76f884757


----------



## JiminSA (Dec 15, 2011)

Could you post the current code? You can use the code insert option (4th on the right) in the 'Post Reply' procedure. I'd just like to see how the form and the email send code looks ...


----------



## mariusmeeren (Aug 4, 2016)

```
<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
$to = "[email protected]";
$subject = "Contact Form";
$headers = "From: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to  = '[email protected]';
$subject = 'Contact Form';

// 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";

// Put your HTML here
$message = '

[IMG]http://i.imgur.com/64wGS5P.png[/IMG]

Expect an answer within 48 hours

[TR][TD]<?=$fname?>[/TD][/TR]

[TR][TD]<?=$email?>[/TD][/TR]

[TR][TD]<?=$phone?>[/TD][/TR]

[TR][TD]<?=$msg?>[/TD][/TR]

';

// Mail it
mail($to, $subject, $message, $headers);
}
header("Location: mailsent"); /* Go back ... */
?>
```


----------



## JiminSA (Dec 15, 2011)

Could you change some code for me please? Change:

```
// Mail it
mail($to, $subject, $message, $headers);
```
to

```
// Mail it
//mail($to, $subject, $message, $headers);
    echo $to."
";
    echo $subject."
";
    echo $message."
";
    echo $headers."
";
```


----------



## mariusmeeren (Aug 4, 2016)

I ain't recieving anything in my mail Dafuq is this ****? IDK what to say, just why is it so hard? Dammit.


----------



## JiminSA (Dec 15, 2011)

Could you change the code as I asked and maybe I can see the problem ...


----------



## mariusmeeren (Aug 4, 2016)

I did change it, but i ain't getting the email
Current Code:

```
<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
$to = "[email protected]";
$subject = "Contact Form";
$headers = "From: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to  = '[email protected]';
$subject = 'Contact Form';

// 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";

// Put your HTML here
$message = '

[IMG]http://i.imgur.com/64wGS5P.png[/IMG]

Expect an answer within 48 hours

[B][SIZE=15]<?=$fname?>[/SIZE][/B]

[B][SIZE=14]<?=$email?>[/SIZE][/B]

[B][SIZE=14]<?=$phone?>[/SIZE][/B]

<?=$msg?>

';

// Mail it
//mail($to, $subject, $message, $headers);
    echo $to."
";
    echo $subject."
";
    echo $message."
";
    echo $headers."
";
}
header("Location: mailsent"); /* Go back ... */
?>
```


----------



## mariusmeeren (Aug 4, 2016)

Sorry Here is the code.

```
<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
$to = "[email protected]";
$subject = "Contact Form";
$headers = "From: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to  = '[email protected]';
$subject = 'Contact Form';

// 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";

// Put your HTML here
$message = '

[IMG]http://i.imgur.com/64wGS5P.png[/IMG]

Expect an answer within 48 hours

[B][SIZE=15]<?=$fname?>[/SIZE][/B]

[B][SIZE=14]<?=$email?>[/SIZE][/B]

[B][SIZE=14]<?=$phone?>[/SIZE][/B]

<?=$msg?>

';

// Mail it
mail($to, $subject, $message, $headers);
    echo $to."
";
    echo $subject."
";
    echo $message."
";
    echo $headers."
";
}
header("Location: mailsent"); /* Go back ... */
?>
```


----------



## JiminSA (Dec 15, 2011)

If you could upload it to your site I could do some debugging ... Woops! Could you add the exit line after this line

```
echo $headers."
";
```


```
exit;
```


----------



## JiminSA (Dec 15, 2011)

Lost interest, Marius?


----------



## mariusmeeren (Aug 4, 2016)

What the **** happend? I posted two Comments with the files. tf?


----------



## JiminSA (Dec 15, 2011)

Not quite with you - are you saying that the email(s) are coming through now?


----------



## mariusmeeren (Aug 4, 2016)

No, they are not coming through, here is the current php code, I removed the echo $fname; things to see if it worked but it didn't.

Current Code:

```
<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
$to = "[email protected]";
$subject = "Contact Form";
$headers = "From: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to  = '[email protected]';
$subject = 'Contact Form';

// 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";

// Put your HTML here
$message = '

[IMG]http://i.imgur.com/64wGS5P.png[/IMG]

Expect an answer within 48 hours

<?=$fname?></input>

<?=$email?></input>

<?=$phone?></input>

<?=$msg?></input>

';

// Mail it
//mail($to, $subject, $message, $headers);
}
header("Location: mailsent"); /* Go back ... */
?>
```


----------



## JiminSA (Dec 15, 2011)

OK, at the moment we are blocking the send because of this line ...

```
//mail($to, $subject, $message, $headers);
```
which has been commented out (//)
What I would like you to do is put in some debugging code for me ...

```
echo $to."
";
    echo $subject."
";
    echo $message."
";
    echo $headers."
";
    exit;
```
straight after the commented out line please.
Then I'll test it and get a better idea of what's going on ...


----------



## mariusmeeren (Aug 4, 2016)

Hm idk. Picture of what happens:
https://gyazo.com/7546692c60f3696228dd41ae40cd75c9


----------



## mariusmeeren (Aug 4, 2016)

You can try to go on the website now, It still doesn't work


----------



## mariusmeeren (Aug 4, 2016)

It justs displays the and the logo, with some displaced text. Nothing in the box


----------



## colinsp (Sep 5, 2007)

I don't think this is going to work as it is.

I don't think the coding around your fieldset is correct. See http://www.w3schools.com/tags/tag_fieldset.asp

Can you actually send emails from your server? Try something much simpler first to ensure that it works and then add functionality once you are certain.


----------



## mariusmeeren (Aug 4, 2016)

I used the code you gave me and this happened https://gyazo.com/0289e85434ad03c460de26054107c15f


----------



## mariusmeeren (Aug 4, 2016)

And you asked if it does send, yes it does, I managed to send it like this:

Name: (Their Name)
Email: (Their Email)
Phone: (Their Phonenumber)
Message: (Their Message)

But it wanted the entire form with the exact style to be sent with the details in the fields. And i managed to make the email come to my email, but the fields was empty, so we tried even further and it didn't work :/


----------



## colinsp (Sep 5, 2007)

As I said the code for your fieldset does not look right and that bears out what you have said with no input data being displayed in your email.


----------



## colinsp (Sep 5, 2007)

Try removing this code and see where we get to


```
[B][SIZE=15]<?=$fname?>[/SIZE][/B]

[B][SIZE=14]<?=$email?>[/SIZE][/B]

[B][SIZE=14]<?=$phone?>[/SIZE][/B]

<?=$msg?>
```
This should then just display the image in the email. Then you can see about adding the other data.


----------



## mariusmeeren (Aug 4, 2016)

Yeah no, i removed that part and i ain't recieving the mail at all.

Current code:

```
<?php
if(isset($_REQUEST['fname']) && !empty($_REQUEST['fname']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
$to = "[email protected]";
$subject = "Contact Form";
$headers = "From: [email protected] \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to = '[email protected]';
$subject = 'Contact Form';

// 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";

// Put your HTML here
$message ='

[IMG]http://i.imgur.com/64wGS5P.png[/IMG]

Expect an answer within 48 hours

';

// Mail it
mail($to, $subject, $message, $headers);
}
header("Location: mailsent"); /* Go back ... */
?>
```


----------

