We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

PHP MAIL configuration?

Hi,

I have found a REALLY simple contact form, which i am trying to mail to my own email for testing.

But I havent tried this before so i am not sure how to set it up.

Hope someone can help me out!

I get 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 C:\wamp\www\enkeltwebdesign\send_contact.php on line 21

I havent set up anything, so was kind of expecting it to go crazy when i submitted.

Can someone hint me on how to setup the mail function correct?

My code looks like this, just the core contact stuff, and processing which might be wrong too :-/

//The Form
<form name=\"form1\" method=\"post\" action=\"send_contact.php\">
<p>Emne:</p><input name=\"subject\" class=\"input\" type=\"text\" id=\"subject\" size=\"64\"><br /><br />
<p>Forespørgsel:</p><textarea name=\"detail\" cols=\"50\" rows=\"7\" id=\"detail\"></textarea><br /><br />
<p>Navn:</p><input name=\"name\" class=\"input\" type=\"text\" id=\"name\" size=\"64\"><br /><br />
<p>Email:</p><input name=\"customer_mail\" class=\"input\" type=\"text\" id=\"customer_mail\" size=\"64\"><br /><br />
<input type=\"submit\" name=\"Submit\" value=\"&nbsp;Send&nbsp;\"> <input type=\"reset\" name=\"Submit2\" value=\"&nbsp;Ryd formen&nbsp;\">

The form processing:

<?php
// Contact subject
$subject = $_POST['subject']; 
// Details
$message= $_POST['detail']; 

// Mail of sender
$mail_from= $_POST['customer_mail'];
// From 
$header="from: $name <$mail_from>"; // This is wrong I think? Undefined variable?

// Enter your email address
$to ='mail@mail.com';

$send_contact=mail($to,$subject,$message,$header); // This is wrong I think?

// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo "Tak for din forespørgsel.";
}
else {
echo "ERROR";
}
?>
3
Contributors
3
Replies
1 Hour
Discussion Span
2 Years Ago
Last Updated
4
Views
klemme
Posting Whiz
311 posts since Mar 2011
Reputation Points: 18
Solved Threads: 8
Skill Endorsements: 0

No. The syntax of the mail() statement looks fine. The message you're getting indicates that smtp isn't set up or not working. You should contact your host about this.

tiggsy
Junior Poster
131 posts since Jul 2009
Reputation Points: 16
Solved Threads: 10
Skill Endorsements: 2

Arh I see, thanks.

I am running on a localhost though. The site is not put online yet.

Is it not possible to tjeck locally, if it is working or not?

klemme
Posting Whiz
311 posts since Mar 2011
Reputation Points: 18
Solved Threads: 8
Skill Endorsements: 0

If you put this code in a file and run it, there will be information about smtp included in the output:

<?php
phpinfo();
?>

(I just did a quick "find" on the output on mine). If smtp isn't listed there at all, most likely it isn't enabled.

tiggsy
Junior Poster
131 posts since Jul 2009
Reputation Points: 16
Solved Threads: 10
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0938 seconds using 2.7MB