# Php mail not working

**URL:** <https://forum.kirupa.com/t/php-mail-not-working/260316>\
**Category:** Uncategorized\
**Created:** [May 14, 2008, 12:26pm UTC](https://forum.kirupa.com/t/php-mail-not-working/260316 "2008-05-14T12:26:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravibhatdon](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@ravibhatdon](https://forum.kirupa.com/u/ravibhatdon)\
**Post date:** [May 14, 2008, 12:26pm UTC](https://forum.kirupa.com/t/php-mail-not-working/260316/1 "2008-05-14T12:26:08Z")

</div>

Hi,  
i have a form in which there are 4 fields,

- Name
- email\_id
- comments
- file

and below is the code to send the mail with an attachment

```auto

<?php
// Read POST request params into global vars
$to = "recpt[EMAIL="recpt@gmail.com"]@gmail.com[/EMAIL]";
$from = $_POST['email_id'];
$username = trim($_POST['Name']);
$subject = $username."'s comments";
$message = $_POST['comments'];
 
$fileatt = $_FILES['file']['tmp_name'];
$fileatt_type = $_FILES['file']['type'];
$fileatt_name = $_FILES['file']['name'];
 
$headers = "From: " . $username . "<webmaster@domain.com>

";
$headers .= "Reply-To: " . $from. "

";
$headers .= "Return-Path: <[COLOR=#0000ff]webmaster@domain.com[/COLOR]> 

";
 
if (is_uploaded_file($fileatt)) {
  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
 
  $headers .= "
MIME-Version: 1.0
" .
              "Content-Type: multipart/mixed;
" .
              " boundary=\"{$mime_boundary}\"";
 
  $message = "This is a multi-part message in MIME format.

" .
             "--{$mime_boundary}
" .
             "Content-Type: text/plain; charset=\"iso-8859-1\"
" .
             "Content-Transfer-Encoding: 7bit

" .
             $message . "

";
 
  $data = chunk_split(base64_encode($data));
 
  $message .= "--{$mime_boundary}
" .
              "Content-Type: {$fileatt_type};
" .
              " name=\"{$fileatt_name}\"
" .
              //"Content-Disposition: attachment;
" .
              //" filename=\"{$fileatt_name}\"
" .
              "Content-Transfer-Encoding: base64

" .
              $data . "

" .
              "--{$mime_boundary}--
";
}
 
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
  echo "<p>Mail sent!</p>";
  echo $ok;
} else {
  echo "<p>Mail could not be sent. Sorry!</p>";
}
?>

```

this will not work if u give [someid@gmail.com](mailto:someid@gmail.com) or [someid@yahoo.com](mailto:someid@yahoo.com) in email\_id field of the form… It will work only if i give [test@test.com](mailto:test@test.com) in the email\_id field of that form.

What is wrong in the code ?? 😑

---

<div class="post-metadata">

**Author:** ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)\
**Post date:** [May 14, 2008, 8:36pm UTC](https://forum.kirupa.com/t/php-mail-not-working/260316/2 "2008-05-14T20:36:02Z")

</div>

The headers seem messed up…

---

<div class="post-metadata">

**Author:** ![ravibhatdon](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@ravibhatdon](https://forum.kirupa.com/u/ravibhatdon)\
**Post date:** [May 15, 2008, 4:22am UTC](https://forum.kirupa.com/t/php-mail-not-working/260316/3 "2008-05-15T04:22:09Z")

</div>

> [@kdd;2326302](#):
>
> The headers seem messed up…

whats wrong with the headers ?? can u please suggest me …

---

<div class="post-metadata">

**Author:** ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)\
**Post date:** [May 15, 2008, 4:49am UTC](https://forum.kirupa.com/t/php-mail-not-working/260316/4 "2008-05-15T04:49:12Z")

</div>

Well, I don’t really know, but are you sure you’re supposed to do something like “Reply-To:” ? Here’s the mail function: [http://us3.php.net/manual/en/function.mail.php](http://us3.php.net/manual/en/function.mail.php).

Sorry I can’t be of much help right now…

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [May 16, 2008, 3:55am UTC](https://forum.kirupa.com/t/php-mail-not-working/260316/5 "2008-05-16T03:55:24Z")

</div>

When you try to set the From header as an domain that does not exist on the machine, the server on the recieving end knows it’s a fake and will block it in many cases.

---

<div class="post-metadata">

**Author:** ![vwxy679](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@vwxy679](https://forum.kirupa.com/u/vwxy679)\
**Post date:** [May 19, 2008, 6:32pm UTC](https://forum.kirupa.com/t/php-mail-not-working/260316/6 "2008-05-19T18:32:40Z")

</div>

You write very well, support you ![neoprene computer bags [url=http://www.cnprince.com/en/oem.html]neoprene Laptop computer bags [url=http://www.cnprince.com/en/oem.html]memory foam computer bags [url=http://www.cnprince.com/en/oem.html]memory foam Laptop computer bags](http://www.cnprince.com/en/oem.html)
