View Full Version : SMTP server for emailing through PHP (And more)?

03-16-2011, 11:28 PM
Hello again! I have (again) ran into a problem during the creation of my dad's new website. On the contact page I have created, I created a simple script that will email the file. That part works correctly, but it says the following 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 C:\xampp\htdocs\mcneilcustomknives\scripts\emailse nd.php on line 20

Here's the script I made for emailing the message:

//Set's the email info
$emailSubject = "Message from MCK";
$donsEmail = "myemail@gmail.com";
//Gather's the data from our form
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Put's together the info from above and puts it into an HTML form
$body = <<<EOD
$name ($email) sent you a message: <br>
//Send the email

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n<br>";
$success = mail($donsEmail, $emailSubject, $body, $headers);
//Results for when the email is sent
$results = <<<EOD
(HTML goes here).

//Display the results
echo "$results"


What do I have to do for it to work?

Also, how could I make it echo the name given from the form inside of a <p> tag afterwards? Meaning if someone told me there name was Johnny, then the $results would load something saying "Thanks for contacting me Johnny!...."?

03-17-2011, 01:29 AM
your pc does not have a mail server set up, it will work when you are on a web server. although you could set one up locally it would be subject to spam filters as you would not have correct mx configuration.
re adding more to message the mail will echo $message so you can add more
$message = $_POST['name'];