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
ID: 24143325
I'm actually switching to Linux server, so we'll see if that works!
LVL 18

Accepted Solution

Matthew Kelly earned 500 total points
ID: 24144194
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

22 Experts available now in Live!

Get 1:1 Help Now