# Mail problem

**URL:** https://forum.kirupa.com/t/mail-problem/263699
**Category:** programming
**Created:** [June 18, 2008, 1:30pm UTC](https://forum.kirupa.com/t/mail-problem/263699 "2008-06-18T13:30:14Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 18, 2008, 1:30pm UTC](https://forum.kirupa.com/t/mail-problem/263699/1 "2008-06-18T13:30:14Z")

</div>

I built a small mail example, to test how the PHP mail() function works.

It didn’t work though, I got this error:

```auto
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\xampp\htdocs\Mark\PHP\PHPMAIL\mail.php on line 7

```

I’ve looked it up but I can’t seem to find what’s wrong. I think it’s running on an Apache server. How can I fix this?

---

<div class="post-metadata">

### Author: ![actionAction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/actionaction/32/3987_2.png) [@actionAction](https://forum.kirupa.com/u/actionAction)
#### Post date: [June 18, 2008, 5:10pm UTC](https://forum.kirupa.com/t/mail-problem/263699/2 "2008-06-18T17:10:52Z")

</div>

Find you httpd.conf file and change the following lines to suit:

```auto
[mail function]
;For Win32 only.

SMTP = smtp.your_service_provider.com

smtp_port = 25

;For Win32 only

sendmail_from = [EMAIL="webmaster@your_domain.com"]webmaster@your_domain.com[/EMAIL] 

```

[LEFT]  
[/LEFT]  
Restart Apache…

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 18, 2008, 6:25pm UTC](https://forum.kirupa.com/t/mail-problem/263699/3 "2008-06-18T18:25:04Z")

</div>

Thanks 🙂 I’ll see if I can do that… :o

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 19, 2008, 11:14am UTC](https://forum.kirupa.com/t/mail-problem/263699/4 "2008-06-19T11:14:22Z")

</div>

I’ve found the file httpd.conf, but those lines are not in there. Am I doing it wrong?

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 19, 2008, 11:46am UTC](https://forum.kirupa.com/t/mail-problem/263699/5 "2008-06-19T11:46:38Z")

</div>

I found the lines you copied there in the php.ini file. For me it says:

```auto
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

```

Should I change SMTP = localhost then?  
And how about the ‘;’ before sendmail\_from, remove it?  
I haven’t got a domainname, is that a problem…?

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 19, 2008, 2:36pm UTC](https://forum.kirupa.com/t/mail-problem/263699/6 "2008-06-19T14:36:56Z")

</div>

**UPDATE**

It’s now working, I sent an e-mail to myself from the site. My hotmail said it was unsafe though, how come? This is the code I’m using:

```auto
<?php
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subj'];
$message = $_POST['message'];

mail($to,$subject,$message,"From: " . $from);

?>

```

Should I add more in the mail function?  
Note, I’m not going to let anyone fill in the form, this was a test. I’m going to use the mail function with a standard sender, no one can change that.

---

<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: [June 19, 2008, 5:41pm UTC](https://forum.kirupa.com/t/mail-problem/263699/7 "2008-06-19T17:41:45Z")

</div>

You should read the comments on the [PHP.net](http://PHP.net) mail() page. You need to add additional mail headers to make your email look more “legitimate”.

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 19, 2008, 6:01pm UTC](https://forum.kirupa.com/t/mail-problem/263699/8 "2008-06-19T18:01:37Z")

</div>

Thanks for redirecting 🙂 I’ll look into it. Lots of info there, I hope it will work out 😉

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 19, 2008, 7:44pm UTC](https://forum.kirupa.com/t/mail-problem/263699/9 "2008-06-19T19:44:00Z")

</div>

Ok I’m stuck at this point. I’m trying to make it look better. I want to send it to my e-mail, with my name infront of it, how is that done, is that possible?

This is my code:

```auto
$to = $_POST['toname'];
$to .= " <";
$to .= $_POST['toemail'];
$to .= ">";
$from = $_POST['from'];
$subject = $_POST['subj'];
$message = $_POST['message'];

echo $to;

mail($to,$subject,$message,"From: " . $from);

```

However, when I’m echoing $to, it only echoes the first bit, not the entire line.

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 20, 2008, 11:00am UTC](https://forum.kirupa.com/t/mail-problem/263699/10 "2008-06-20T11:00:26Z")

</div>

I found out Windows pc’s don’t handle that very well. Well no troubles.  
Actually… I do have a trouble. The e-mail I send to myself is being flagged as spam/innapropriate or whatever. I’m using hotmail. I’m sending the mail from @live.nl to @hotmail.com. However, the server is hosted at xs4all.nl. Is this why it’s going wrong?

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 23, 2008, 7:37am UTC](https://forum.kirupa.com/t/mail-problem/263699/11 "2008-06-23T07:37:53Z")

</div>

How can I send mail from a site, without having trouble with it? How does a phpBB forum handle this for example?  
Through php’s mail() function I can send mail as if it were from anyone. I don’t think that is right, how do I associate a certain e-mail with it? It’s all pretty confusing, but I want to get this right…

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 23, 2008, 11:03am UTC](https://forum.kirupa.com/t/mail-problem/263699/12 "2008-06-23T11:03:50Z")

</div>

I’ve now integrated my mail into my main site, to see if it works.

It works, it sends the e-mail. This is what my Hotmail says when I open the mail:

> ```
> This message has been blocked for your safety.
> 
> ```

And

> This message may be dangerous.

I tell Hotmail to open it anyway, because I know it is safe. Users on my site however might now know that!

Also, this is what I get when I open the mail:

> Hello Maqrkk,

This e-mail has been sent to you to reset your password. If you do not want to reset your password, ignore this e-mail.

I thought the  
would make a new line, but it doesn’t!

Here is my code for this part of the site:

```php
$subject = 'Email Recovery';
$message = 'Hello '.$user.',

This e-mail has been sent to you to reset your password. If you do not want to reset your password, ignore this e-mail.

';
$headers = 'From: markpeerdeman@live.nl' . "
" . 'Reply-To: markpeerdeman@live.nl' . "
" . 'X-Mailer: PHP/' . phpversion();
mail($email,$subject,$message,$headers);
header("location:index.php?mode=successrec");

```

Can anyone help me to:

1. Get new lines to appear correctly.
2. Make this e-mail not appear as dangerous?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![actionAction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/actionaction/32/3987_2.png) [@actionAction](https://forum.kirupa.com/u/actionAction)
#### Post date: [June 23, 2008, 4:55pm UTC](https://forum.kirupa.com/t/mail-problem/263699/13 "2008-06-23T16:55:55Z")

</div>

Try reversing your single and double quotes. By saying that I mean:

```php

$message = "Hello ".$user.",

This e-mail has been sent to you to reset your password. If you do not want to reset your password, ignore this e-mail.

";
$headers = "From: markpeerdeman@live.nl" . '
' . "Reply-To: markpeerdeman@live.nl" . '
' . "X-Mailer: PHP/" . phpversion(); 

```

For a reason unknown to me, line breaks (  
) only seem to work within double quotes.

---

<div class="post-metadata">

### Author: ![Maqrkk](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Maqrkk](https://forum.kirupa.com/u/Maqrkk)
#### Post date: [June 23, 2008, 5:04pm UTC](https://forum.kirupa.com/t/mail-problem/263699/14 "2008-06-23T17:04:44Z")

</div>

Thanks I’ll try it out. Any idea what I can do to prevent Hotmail from tagging it as spam?
