1,105,578 Community Members

PHP MAIL configuration?

Member Avatar
klemme
Posting Whiz
376 posts since Mar 2011
Reputation Points: 3 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

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";
}
?>
Member Avatar
tiggsy
Junior Poster
132 posts since Jul 2009
Reputation Points: 4 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
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.

Member Avatar
klemme
Posting Whiz
376 posts since Mar 2011
Reputation Points: 3 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
tiggsy
Junior Poster
132 posts since Jul 2009
Reputation Points: 4 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: