# PHP email error

**URL:** https://forum.kirupa.com/t/php-email-error/27430
**Category:** flash
**Created:** [August 2, 2003, 9:21am UTC](https://forum.kirupa.com/t/php-email-error/27430 "2003-08-02T09:21:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rawguru](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@rawguru](https://forum.kirupa.com/u/rawguru)
#### Post date: [August 2, 2003, 9:21am UTC](https://forum.kirupa.com/t/php-email-error/27430/1 "2003-08-02T09:21:29Z")

</div>

Ok, I did this php email tutorial exactly like this dude said.  
The email thing looks good and says “Your message has been sent” but it doesnt work.  
Here is the tutorial

[http://www.sephiroth.it/tutorials/flashPHP/email/page001.php](http://www.sephiroth.it/tutorials/flashPHP/email/page001.php)

and here is my email form.  
[http://www.rawguru.com/feedback.html](http://www.rawguru.com/feedback.html)

my php file  
[http://www.rawguru.com/sendmail.php](http://www.rawguru.com/sendmail.php)

which shows an error

Please help. I gotta have one of these email forms.  
Thanks in advance!  
Alex

---

<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 2, 2003, 9:23am UTC](https://forum.kirupa.com/t/php-email-error/27430/2 "2003-08-02T09:23:50Z")

</div>

Can you post the PHP code and the AS you used ?

---

<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 2, 2003, 9:24am UTC](https://forum.kirupa.com/t/php-email-error/27430/3 "2003-08-02T09:24:48Z")

</div>

\<?  
if(!empty($\_POST[‘sender\_mail’])  
|| !empty($\_POST[‘sender\_message’])  
|| !empty($\_POST[‘sender\_subject’])  
|| !empty($\_POST[‘sender\_name’]))  
{  
$to = "alienboy24@hotmail.com"; // replace with your mail address  
$s\_name = $\_POST[‘sender\_name’];  
$s\_mail = $\_POST[‘sender\_mail’];  
$subject = stripslashes($\_POST[‘sender\_subject’]);  
$body = stripslashes($\_POST[‘sender\_message’]);  
$body .= "

* * *

";  
$body .= "Mail sent by: $s\_name \<$s\_mail\>  
";  
$header = "From: $s\_name \<$s\_mail\>  
";  
$header .= "Reply-To: $s\_name \<$s\_mail\>  
";  
$header .= “X-Mailer: PHP/” . phpversion() . "  
";  
$header .= “X-Priority: 1”;  
if(@mail($to, $subject, $body, $header))  
{  
echo “output=sent”;  
} else {  
echo “output=error”;  
}  
} else {  
echo “output=error”;  
}  
?\>

---

<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 2, 2003, 9:36am UTC](https://forum.kirupa.com/t/php-email-error/27430/4 "2003-08-02T09:36:50Z")

</div>

Now that I think about it, your PHP file may show an error because when you enter the PHP file, you’re not defining any vars, which makes PHP unable to send a mail. I can’t see any errors in the PHP file, but try replacing it with this:

```php
<?
//flash should check for empty fields, not PHP
$to = "alienboy24@hotmail.com"; // replace with your mail address
$s_name = $_POST['sender_name'];
$s_mail = $_POST['sender_mail'];
$subject = stripslashes($_POST['sender_subject']);
$body = stripslashes($_POST['sender_message']);
$body .= "

---------------------------
";
$body .= "Mail sent by: ".$s_name." <".$s_mail.">
";
$header = "From: ".$s_name." <".$s_mail.">
";
$header .= "Reply-To: ".$s_name." <".$s_mail.">
";
$header .= "X-Mailer: PHP ".phpversion()."
";
$header .= "X-Priority: 1";
if(@mail($to, $subject, $body, $header))
{
echo "output=sent";
} else {
echo "output=error";
}
?>

```

What AS did you use ?

---

<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 2, 2003, 9:57am UTC](https://forum.kirupa.com/t/php-email-error/27430/5 "2003-08-02T09:57:50Z")

</div>

Nope, didnt work either.  
Man, this sucks. Maybe i need to do this.

Since all the mail arguments (except for the $to variable) are passed by another page (Flash in this case) we need to add the if statement at the beginning in order to check if they are all defined.  
So, if one of those HTTP\_POST\_VARS variales is empty, don’t run the mail code and return an error message: output=error

Otherwise, if all those variables exist and they’re not empty, we define our mail paramenters paying atention to these lines:

$subject = stripslashes($\_POST[‘sender\_subject’]);  
$body = stripslashes($\_POST[‘sender\_message’]);

We do that because if user input this text: “I’m the one” (example) and we dont’ use the stripslashes function, we will receive an email with this text: “I’m the one”. In fact stripslashes returns a string with backslashes stripped off.  
Then we add this headers to our email:

$header = "From: $s\_name \<$s\_mail\>  
";  
$header .= "Reply-To: $s\_name \<$s\_mail\>  
";  
$header .= “X-Mailer: PHP/” . phpversion() . "  
";  
$header .= “X-Priority: 1”;

From defines the mail sender, Reply-To (not necessary here) is necessary when the reply recipient is different from the sender email. (When you press the ‘reply’ button on your mail reader, the email is sent, if defined, to the Reply-To address).  
Header finishes with the X-Mail (The php page itself and the php running version) and the X-Priority of the mail (1 is urgent, 3 is normal)

---

<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 2, 2003, 10:01am UTC](https://forum.kirupa.com/t/php-email-error/27430/6 "2003-08-02T10:01:42Z")

</div>

Well, then I’d suggest you find another tutorial.
