# PHP Mail Form

**URL:** https://forum.kirupa.com/t/php-mail-form/23353
**Category:** programming
**Created:** [June 16, 2003, 8:35pm UTC](https://forum.kirupa.com/t/php-mail-form/23353 "2003-06-16T20:35:43Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![wyclef](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@wyclef](https://forum.kirupa.com/u/wyclef)
#### Post date: [June 16, 2003, 8:35pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/1 "2003-06-16T20:35:43Z")

</div>

Hi,

I’m trying to create a form field so the user can submit their email address but it doesn’t seem to return the email address.

I have a file titled “mail.php”

```php

<?php

mail("myEmail@domain.com", "Email Subject", $email);

?>

```

A button with this code attached…  
[AS]  
on (release) {  
loadVariablesNum(“mail.php”, “0”, “POST”);  
email.text = “Thank You!”;  
}  
[/AS]

And a textfield with the instance name “email”

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 16, 2003, 9:29pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/2 "2003-06-16T21:29:27Z")

</div>

Heres a bunch of threads on the subject of PHP E-mail forms both in and out of Flash…

[http://www.kirupaforum.com/forums/search.php?s=&action=showresults&searchid=95094&sortby=lastpost&sortorder=descending](http://www.kirupaforum.com/forums/search.php?s=&action=showresults&searchid=95094&sortby=lastpost&sortorder=descending)

Ive never done a Flash/PHP Form so I won’t be much help, but those threads have your answers.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 16, 2003, 10:50pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/3 "2003-06-16T22:50:32Z")

</div>

try this

```auto
on (release) {
email = "Thank You!";
loadVariablesNum("mail.php", "0", "POST");
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 5:04am UTC](https://forum.kirupa.com/t/php-mail-form/23353/4 "2003-06-17T05:04:14Z")

</div>

yeah, if you are receiving the e-mail, but it doesn’t have any content, then do what **ahmed** said, and also put this line at the top of your PHP script…

```php

$email = $_POST['email'];

```

also, make sure that you are giving the input box a _variable_ name, not an instance name. I had a bit of trouble getting my variables to read from the instance name of an input box…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 3, 2003, 2:45pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/5 "2003-08-03T14:45:38Z")

</div>

This is what I have now,

```php

<?PHP

$to = "myemail@email.com";

$msg = "$email

"; 

mail($to, $msg, "For: Mailing List
Reply-To: $email
");

?> 

```

Everything works except the autoresponder for [myemail@email.com](mailto:myemail@email.com) doesn’t get sent to the email address submitted. Is there a way to fix this with the code?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 8:35pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/6 "2003-08-04T20:35:16Z")

</div>

Any Ideas? :bounce:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 9:24pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/7 "2003-08-04T21:24:12Z")

</div>

your syntax is a little wrong… it should be

```php

mail(E-mail, SUBJECT, MESSAGE, HEADERS);

```

try this… make a file called testMail.php and put this code in it…

```php

<?

$to = "PUT YOUR ADDRESS HERE";
$subject = "Test E-mail";
$message = "This is a test e-mail";

$mail_test = mail($to, $subject, $message);

if($mail_test)
{
     print "Mail sent successfully";
}
else
{
     print "Error sending mail";
}

?>

```

Just put your e-mail address in where it says. If it still doesn’t work then try this link : [http://www.kirupa.com/web/testphp.htm](http://www.kirupa.com/web/testphp.htm)

that will tell you if PHP is set up correctly on your server. If you get the correct screen then scroll down to where it says **STMP** and make sure it says **localhost** if not then your host probably has disabled it to prevent Spamming.

\*\*Oh, yeah and you can’t test this locally, it has to be tested on your server (that causes so much trouble…)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 9:33pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/8 "2003-08-04T21:33:06Z")

</div>

Hi, PHP has to be set up correctly on my server because the email data submitted is being sent, it’s just that the email address submitted is not showing up as the “from” addres so the autoresponder doesn  
t send a response to the submitted email. Here is my most updated code.

```php

<?PHP

$to = "list@test.com";

$msg = "$email

"; 

$subj = "Mailing List";

mail($to, $subj, $msg, "From: $email
Reply-To: $email
");

?> 

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 9:34pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/9 "2003-08-04T21:34:24Z")

</div>

where are you defining the $email variable?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 9:38pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/10 "2003-08-04T21:38:57Z")

</div>

in the flash textfield

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 9:44pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/11 "2003-08-04T21:44:53Z")

</div>

```php

<?PHP

$email = $_POST['email'];  

$to = "list@test.com";

$msg = "$email

"; 

$subj = "Mailing List";

$header = "From: $email <$email>
";

$header .= "Reply-To: $email
";

mail($to, $subj, $msg, $header);

?> 

```

try that… if that doesn’t work then make sure you are using Ahmed’s method of defining the Flash variable…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 11:46pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/12 "2003-08-04T23:46:15Z")

</div>

No go, the email goes through, everything is in check, but no autoresponse is sent. I DON’T GET IT!!! It even has the appropriate mail account. WHAT THE %&_$_$ IS GOING ON!!! ahhhhhhh

🅱

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 11:47pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/13 "2003-08-04T23:47:48Z")

</div>

what do you mean autoresponse?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 11:49pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/14 "2003-08-04T23:49:58Z")

</div>

An autoresponder is an email that is set up to automatically be sent to any address it’s receiving mail from.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2003, 11:54pm UTC](https://forum.kirupa.com/t/php-mail-form/23353/15 "2003-08-04T23:54:18Z")

</div>

ohhh… php doesn’t do that. You have to use the e-mail client for something like that. That is something that you would have to set up in outlook…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 5, 2003, 12:02am UTC](https://forum.kirupa.com/t/php-mail-form/23353/16 "2003-08-05T00:02:49Z")

</div>

and so you know this is incorrect:

“From: $email”

it has to be

“From: $email \<$email\>”;

that is probably causing the problem. YOu need to have the e-mail address in there twice. Once as the name, and then again in the brackets so that the e-mail program will recognize it as an e-mail address…

code should look like this:

```php

<?PHP

$to = "list@test.com";

$msg = "$email

"; 

$subj = "Mailing List";

$header = "From: $email <$email>
";

$header .= "Reply-To: $email
";

mail($to, $subj, $msg, $header);

?> 

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 24, 2003, 4:50am UTC](https://forum.kirupa.com/t/php-mail-form/23353/17 "2003-12-24T04:50:00Z")

</div>

Hi, this is PHP code I am using in conjunction with a flash form and i’m wondering how I can build in a bit of simple email address validation and possibly an autoresponder built into the PHP that gets sent to whatever address is submitted.

```php

<?PHP
$email = $_POST['email'];  
$to = "email@myemail.com";
$msg = "$email

"; 
$subj = "Mailing List";
$header = "From: $email <$email>
";
$header .= "Reply-To: $email
";
mail($to, $subj, $msg, $header);
?> 

```
