PHP mailer form on Windows server

Posted on 2009-04-14
Last Modified: 2013-12-13

I have a website hosted on a Windows server. I need to get the contact form working, but I believe the code is missing the authentication parts, just not sure what I'm missing. Can someone help me out with that?

The current code I have is below:

// list all vars to be expected from the movie

$vars = array("contact_name", "contact_email", "contact_message");

// and import them into the script

foreach($vars as $var)


		$$var = $_POST[$var];


		$$var = '';

// where to send it

// remove or configure one of the two code blocks

// otherwise your mail will be sent to :)

// ***** or one fixed recipient ******

$recip = "";

//****  end fixed recipient *******

$headers  = "MIME-Version: 1.0\n";

$headers .= "Content-type: text/plain; charset=utf-8\n";

$headers .= "X-Priority: 3\n";

$headers .= "X-MSMail-Priority: Normal\n";

$headers .= "X-Mailer: php\n";

$headers .= "From:";

// build up message

// this code for any multiline text fields

$message = str_replace("\r", "\n", $contact_message);

// info vars

$sender = $_SERVER[REMOTE_ADDR];

// you can rearrange this - just do not add or remove quotes

$mailbody = "Contact form send by:

Name: $contact_name

Email: $contact_email




sender's ip: $sender";

mail($recip, "Contact form", $mailbody, $headers);

// and tell visitor

print "&status=sent_ok";


Open in new window

Question by:Trevor Local

Author Comment

by:Trevor Local
Comment Utility
I'm actually switching to Linux server, so we'll see if that works!
LVL 18

Accepted Solution

Matthew Kelly earned 500 total points
Comment Utility
If you do need to do it on windows

The best approach is to use a 3rd party mail program. In the past I have used PHPMailer as it is has all features I have needed. This script is the fix to many SMTP email problems in PHP!

It additionally allows for SMTP authentication where required.

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now