Mail problem

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

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

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?

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

[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…

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

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

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

[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…?

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:

<?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.

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

Thanks for redirecting :slight_smile: I’ll look into it. Lots of info there, I hope it will work out :wink:

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:

$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.

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?

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…

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:

$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.

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


$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.

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