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?
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.
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?
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");
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.